Digital
and Interactive Games, 2015, Term 3, Session 4
Today: - coloring block (wool, glass, pane)
– bit specific block manipulation (door, bed)
• Create a structure (building, statue, etc)
• Create a new project for a plugin based on the cube1 project
“BuildIt”
– implement three commands
1. make door (permission makedoor.use)
2. make bed (permission makebed.use)
3. BuildIt (permission buildit.use)
.setType(...)
.setTypeId(...)
.setData( ) ← byte
• DyeColor.RED.getData()
TUT – Doors: A better understanding: https://bukkit.org/threads/tut-doors-a-better-understanding.15630/
…
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class MakeDoorCommand implements CommandExecutor {
@SuppressWarnings("deprecation")
@Override
public boolean onCommand(CommandSender sender, Command arg1, String arg2,
String[] arg3) {
// TODO Auto-generated method stub
if(!(sender instanceof Player)) return true;
Player player = (Player) sender;
Location loc = player.getLocation();
BlockFace bf = TomUtililties.yawToFace(loc.getYaw(), false);
BlockFace bf1 = null;
BlockFace bf2 = null;
byte doorface = 0x0;
byte righthinge = 0x1;
byte lefthinge = 0x0;
if (bf == BlockFace.SOUTH) {
bf1 = BlockFace.NORTH;
bf2 = BlockFace.EAST;
doorface = 0x3;
} else if (bf == BlockFace.WEST) {
bf1 = BlockFace.EAST;
bf2 = BlockFace.SOUTH;
doorface = 0x0;
} else if (bf == BlockFace.NORTH) {
bf1 = BlockFace.SOUTH;
bf2 = BlockFace.WEST;
doorface = 0x1;
} else if (bf == BlockFace.EAST) {
bf1 = BlockFace.WEST;
bf2 = BlockFace.NORTH;
doorface = 0x2;
}
Block block = loc.getBlock();
// right hand side
block.getRelative(bf1, 1).setTypeIdAndData(64, (byte) (0x0 | doorface), true); // bottom half
block.getRelative(bf1, 1).setTypeIdAndData(64, (byte) (0x8 | righthinge), true); // top half
// left hand side
block.getRelative(bf1, 1).getRelative(bf2, 1).setTypeIdAndData(64, (byte) (0x0 | doorface), true); // bottom half
block.getRelative(bf1, 1).getRelative(bf2, 1).getRelative(BlockFace.UP, 1).setTypeIdAndData(64, (byte) (0x8 | lefthinge), true); // top half
/*
Player player = (Player) sender;
createABlock(player);
player.sendMessage("Successfully execute makedoor");
player.sendMessage(arg2);
*/
return true;
}
/*
@SuppressWarnings("deprecation")
private void createABlock(Player p) {
World w = p.getWorld();
p.getLocation().getBlock().getRelative(1,0,4).setType(Material.ICE);
w.getBlockAt(270,64,202).setTypeId(62);
}*/
}
…
Structure
x 7 – 15
z around 5
1 – 3 types of material
One of wool, glass or pane must be used.
(Dye it)
Submit it as name
.setTypeId and Data
#gamedesign #gameprogramming #java #minecraft #plugins #programming
Today: - coloring block (wool, glass, pane)
– bit specific block manipulation (door, bed)
• Create a structure (building, statue, etc)
• Create a new project for a plugin based on the cube1 project
“BuildIt”
– implement three commands
1. make door (permission makedoor.use)
2. make bed (permission makebed.use)
3. BuildIt (permission buildit.use)
.setType(...)
.setTypeId(...)
.setData( ) ← byte
• DyeColor.RED.getData()
TUT – Doors: A better understanding: https://bukkit.org/threads/tut-doors-a-better-understanding.15630/
…
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class MakeDoorCommand implements CommandExecutor {
@SuppressWarnings("deprecation")
@Override
public boolean onCommand(CommandSender sender, Command arg1, String arg2,
String[] arg3) {
// TODO Auto-generated method stub
if(!(sender instanceof Player)) return true;
Player player = (Player) sender;
Location loc = player.getLocation();
BlockFace bf = TomUtililties.yawToFace(loc.getYaw(), false);
BlockFace bf1 = null;
BlockFace bf2 = null;
byte doorface = 0x0;
byte righthinge = 0x1;
byte lefthinge = 0x0;
if (bf == BlockFace.SOUTH) {
bf1 = BlockFace.NORTH;
bf2 = BlockFace.EAST;
doorface = 0x3;
} else if (bf == BlockFace.WEST) {
bf1 = BlockFace.EAST;
bf2 = BlockFace.SOUTH;
doorface = 0x0;
} else if (bf == BlockFace.NORTH) {
bf1 = BlockFace.SOUTH;
bf2 = BlockFace.WEST;
doorface = 0x1;
} else if (bf == BlockFace.EAST) {
bf1 = BlockFace.WEST;
bf2 = BlockFace.NORTH;
doorface = 0x2;
}
Block block = loc.getBlock();
// right hand side
block.getRelative(bf1, 1).setTypeIdAndData(64, (byte) (0x0 | doorface), true); // bottom half
block.getRelative(bf1, 1).setTypeIdAndData(64, (byte) (0x8 | righthinge), true); // top half
// left hand side
block.getRelative(bf1, 1).getRelative(bf2, 1).setTypeIdAndData(64, (byte) (0x0 | doorface), true); // bottom half
block.getRelative(bf1, 1).getRelative(bf2, 1).getRelative(BlockFace.UP, 1).setTypeIdAndData(64, (byte) (0x8 | lefthinge), true); // top half
/*
Player player = (Player) sender;
createABlock(player);
player.sendMessage("Successfully execute makedoor");
player.sendMessage(arg2);
*/
return true;
}
/*
@SuppressWarnings("deprecation")
private void createABlock(Player p) {
World w = p.getWorld();
p.getLocation().getBlock().getRelative(1,0,4).setType(Material.ICE);
w.getBlockAt(270,64,202).setTypeId(62);
}*/
}
…
Structure
x 7 – 15
z around 5
1 – 3 types of material
One of wool, glass or pane must be used.
(Dye it)
Submit it as name
.setTypeId and Data
#gamedesign #gameprogramming #java #minecraft #plugins #programming
No comments:
Post a Comment