diff --git a/.gitignore b/.gitignore index 9c0573a55d..9c628f5f76 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,9 @@ # netbeans /nbproject +# we use maven! +/build.xml + # maven /target diff --git a/README.md b/README.md new file mode 100644 index 0000000000..d5719e2ff9 --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +CraftBukkit +=========== + +A Bukkit (Minecraft Server API) implementation + +Compilation +----------- + +We use maven to handle our dependencies. + +* Install [Maven 3](http://maven.apache.org/download.html) +* Check out and install [Bukkit](http://github.com/Bukkit/Bukkit) +* Check out this repo and: `mvn clean package` diff --git a/src/main/java/net/minecraft/server/BlockButton.java b/src/main/java/net/minecraft/server/BlockButton.java new file mode 100644 index 0000000000..cc4462d620 --- /dev/null +++ b/src/main/java/net/minecraft/server/BlockButton.java @@ -0,0 +1,258 @@ +package net.minecraft.server; + + +import java.util.Random; + +import org.bukkit.craftbukkit.CraftBlock; +import org.bukkit.craftbukkit.CraftPlayer; +import org.bukkit.event.Event.Type; +import org.bukkit.event.block.BlockInteractEvent; + + +public class BlockButton extends Block { + + protected BlockButton(int i, int j) { + super(i, j, Material.n); + a(true); + } + + public AxisAlignedBB d(World world, int i, int j, int k) { + return null; + } + + public int b() { + return 20; + } + + public boolean a() { + return false; + } + + public boolean a(World world, int i, int j, int k) { + if (world.d(i - 1, j, k)) { + return true; + } + if (world.d(i + 1, j, k)) { + return true; + } + if (world.d(i, j, k - 1)) { + return true; + } + return world.d(i, j, k + 1); + } + + public void c(World world, int i, int j, int k, int l) { + int i1 = world.b(i, j, k); + int j1 = i1 & 8; + + i1 &= 7; + if (l == 2 && world.d(i, j, k + 1)) { + i1 = 4; + } + if (l == 3 && world.d(i, j, k - 1)) { + i1 = 3; + } + if (l == 4 && world.d(i + 1, j, k)) { + i1 = 2; + } + if (l == 5 && world.d(i - 1, j, k)) { + i1 = 1; + } + world.b(i, j, k, i1 + j1); + } + + public void e(World world, int i, int j, int k) { + if (world.d(i - 1, j, k)) { + world.b(i, j, k, 1); + } else if (world.d(i + 1, j, k)) { + world.b(i, j, k, 2); + } else if (world.d(i, j, k - 1)) { + world.b(i, j, k, 3); + } else if (world.d(i, j, k + 1)) { + world.b(i, j, k, 4); + } + g(world, i, j, k); + } + + public void b(World world, int i, int j, int k, int l) { + if (g(world, i, j, k)) { + int i1 = world.b(i, j, k) & 7; + boolean flag = false; + + if (!world.d(i - 1, j, k) && i1 == 1) { + flag = true; + } + if (!world.d(i + 1, j, k) && i1 == 2) { + flag = true; + } + if (!world.d(i, j, k - 1) && i1 == 3) { + flag = true; + } + if (!world.d(i, j, k + 1) && i1 == 4) { + flag = true; + } + if (flag) { + a_(world, i, j, k, world.b(i, j, k)); + world.d(i, j, k, 0); + } + } + } + + private boolean g(World world, int i, int j, int k) { + if (!a(world, i, j, k)) { + a_(world, i, j, k, world.b(i, j, k)); + world.d(i, j, k, 0); + return false; + } else { + return true; + } + } + + public void a(IBlockAccess iblockaccess, int i, int j, int k) { + int l = iblockaccess.b(i, j, k); + int i1 = l & 7; + boolean flag = (l & 8) > 0; + float f = 0.375F; + float f1 = 0.625F; + float f2 = 0.1875F; + float f3 = 0.125F; + + if (flag) { + f3 = 0.0625F; + } + if (i1 == 1) { + a(0.0F, f, 0.5F - f2, f3, f1, 0.5F + f2); + } else if (i1 == 2) { + a(1.0F - f3, f, 0.5F - f2, 1.0F, f1, 0.5F + f2); + } else if (i1 == 3) { + a(0.5F - f2, f, 0.0F, 0.5F + f2, f1, f3); + } else if (i1 == 4) { + a(0.5F - f2, f, 1.0F - f3, 0.5F + f2, f1, 1.0F); + } + } + + public void b(World world, int i, int j, int k, EntityPlayer entityplayer) { + a(world, i, j, k, entityplayer); + } + + public boolean a(World world, int i, int j, int k, EntityPlayer entityplayer) { + // Craftbukkit start - Interact Button + CraftBlock block = (CraftBlock) ((WorldServer) world).getWorld().getBlockAt(i, j, k); + CraftPlayer player = new CraftPlayer(((WorldServer) world).getServer(), (EntityPlayerMP) entityplayer); + BlockInteractEvent bie = new BlockInteractEvent(Type.BLOCK_INTERACT, block, player); + + ((WorldServer) world).getServer().getPluginManager().callEvent(bie); + + if (bie.isCancelled()) return true; + + if (world.z) { + return true; + } + int l = world.b(i, j, k); + int i1 = l & 7; + int j1 = 8 - (l & 8); + + if (j1 == 0) { + return true; + } + world.b(i, j, k, i1 + j1); + world.b(i, j, k, i, j, k); + world.a((double) i + 0.5D, (double) j + 0.5D, (double) k + 0.5D, "random.click", 0.3F, 0.6F); + world.g(i, j, k, bh); + if (i1 == 1) { + world.g(i - 1, j, k, bh); + } else if (i1 == 2) { + world.g(i + 1, j, k, bh); + } else if (i1 == 3) { + world.g(i, j, k - 1, bh); + } else if (i1 == 4) { + world.g(i, j, k + 1, bh); + } else { + world.g(i, j - 1, k, bh); + } + world.h(i, j, k, bh); + return true; + } + + public void b(World world, int i, int j, int k) { + int l = world.b(i, j, k); + + if ((l & 8) > 0) { + world.g(i, j, k, bh); + int i1 = l & 7; + + if (i1 == 1) { + world.g(i - 1, j, k, bh); + } else if (i1 == 2) { + world.g(i + 1, j, k, bh); + } else if (i1 == 3) { + world.g(i, j, k - 1, bh); + } else if (i1 == 4) { + world.g(i, j, k + 1, bh); + } else { + world.g(i, j - 1, k, bh); + } + } + super.b(world, i, j, k); + } + + public boolean b(IBlockAccess iblockaccess, int i, int j, int k, int l) { + return (iblockaccess.b(i, j, k) & 8) > 0; + } + + public boolean d(World world, int i, int j, int k, int l) { + int i1 = world.b(i, j, k); + + if ((i1 & 8) == 0) { + return false; + } + int j1 = i1 & 7; + + if (j1 == 5 && l == 1) { + return true; + } + if (j1 == 4 && l == 2) { + return true; + } + if (j1 == 3 && l == 3) { + return true; + } + if (j1 == 2 && l == 4) { + return true; + } + return j1 == 1 && l == 5; + } + + public boolean c() { + return true; + } + + public void a(World world, int i, int j, int k, Random random) { + if (world.z) { + return; + } + int l = world.b(i, j, k); + + if ((l & 8) == 0) { + return; + } + world.b(i, j, k, l & 7); + world.g(i, j, k, bh); + int i1 = l & 7; + + if (i1 == 1) { + world.g(i - 1, j, k, bh); + } else if (i1 == 2) { + world.g(i + 1, j, k, bh); + } else if (i1 == 3) { + world.g(i, j, k - 1, bh); + } else if (i1 == 4) { + world.g(i, j, k + 1, bh); + } else { + world.g(i, j - 1, k, bh); + } + world.a((double) i + 0.5D, (double) j + 0.5D, (double) k + 0.5D, "random.click", 0.3F, 0.5F); + world.b(i, j, k, i, j, k); + } +} + diff --git a/src/main/java/net/minecraft/server/BlockChest.java b/src/main/java/net/minecraft/server/BlockChest.java new file mode 100644 index 0000000000..90e41e332d --- /dev/null +++ b/src/main/java/net/minecraft/server/BlockChest.java @@ -0,0 +1,169 @@ +package net.minecraft.server; + + +import java.util.Random; + +import org.bukkit.craftbukkit.CraftBlock; +import org.bukkit.craftbukkit.CraftPlayer; +import org.bukkit.event.Event.Type; +import org.bukkit.event.block.BlockInteractEvent; + + +public class BlockChest extends BlockContainer { + + private Random a; + + protected BlockChest(int i) { + super(i, Material.c); + a = new Random(); + bg = 26; + } + + public int a(int i) { + if (i == 1) { + return bg - 1; + } + if (i == 0) { + return bg - 1; + } + if (i == 3) { + return bg + 1; + } else { + return bg; + } + } + + public boolean a(World world, int i, int j, int k) { + int l = 0; + + if (world.a(i - 1, j, k) == bh) { + l++; + } + if (world.a(i + 1, j, k) == bh) { + l++; + } + if (world.a(i, j, k - 1) == bh) { + l++; + } + if (world.a(i, j, k + 1) == bh) { + l++; + } + if (l > 1) { + return false; + } + if (g(world, i - 1, j, k)) { + return false; + } + if (g(world, i + 1, j, k)) { + return false; + } + if (g(world, i, j, k - 1)) { + return false; + } + return !g(world, i, j, k + 1); + } + + private boolean g(World world, int i, int j, int k) { + if (world.a(i, j, k) != bh) { + return false; + } + if (world.a(i - 1, j, k) == bh) { + return true; + } + if (world.a(i + 1, j, k) == bh) { + return true; + } + if (world.a(i, j, k - 1) == bh) { + return true; + } + return world.a(i, j, k + 1) == bh; + } + + public void b(World world, int i, int j, int k) { + TileEntityChest tileentitychest = (TileEntityChest) world.l(i, j, k); + + label0: + for (int l = 0; l < tileentitychest.a(); l++) { + ItemStack itemstack = tileentitychest.a(l); + + if (itemstack == null) { + continue; + } + float f = a.nextFloat() * 0.8F + 0.1F; + float f1 = a.nextFloat() * 0.8F + 0.1F; + float f2 = a.nextFloat() * 0.8F + 0.1F; + + do { + if (itemstack.a <= 0) { + continue label0; + } + int i1 = a.nextInt(21) + 10; + + if (i1 > itemstack.a) { + i1 = itemstack.a; + } + itemstack.a -= i1; + EntityItem entityitem = new EntityItem(world, (float) i + f, (float) j + f1, (float) k + f2, new ItemStack(itemstack.c, i1, itemstack.d)); + float f3 = 0.05F; + + entityitem.s = (float) a.nextGaussian() * f3; + entityitem.t = (float) a.nextGaussian() * f3 + 0.2F; + entityitem.u = (float) a.nextGaussian() * f3; + world.a(entityitem); + } while (true); + } + + super.b(world, i, j, k); + } + + public boolean a(World world, int i, int j, int k, EntityPlayer entityplayer) { + Object obj = (TileEntityChest) world.l(i, j, k); + + if (world.d(i, j + 1, k)) { + return true; + } + if (world.a(i - 1, j, k) == bh && world.d(i - 1, j + 1, k)) { + return true; + } + if (world.a(i + 1, j, k) == bh && world.d(i + 1, j + 1, k)) { + return true; + } + if (world.a(i, j, k - 1) == bh && world.d(i, j + 1, k - 1)) { + return true; + } + if (world.a(i, j, k + 1) == bh && world.d(i, j + 1, k + 1)) { + return true; + } + if (world.a(i - 1, j, k) == bh) { + obj = new InventoryLargeChest("Large chest", (TileEntityChest) world.l(i - 1, j, k), ((IInventory) (obj))); + } + if (world.a(i + 1, j, k) == bh) { + obj = new InventoryLargeChest("Large chest", ((IInventory) (obj)), (TileEntityChest) world.l(i + 1, j, k)); + } + if (world.a(i, j, k - 1) == bh) { + obj = new InventoryLargeChest("Large chest", (TileEntityChest) world.l(i, j, k - 1), ((IInventory) (obj))); + } + if (world.a(i, j, k + 1) == bh) { + obj = new InventoryLargeChest("Large chest", ((IInventory) (obj)), (TileEntityChest) world.l(i, j, k + 1)); + } + if (world.z) { + return true; + } else { + // Craftbukkit start - Interact Chest + CraftBlock block = (CraftBlock) ((WorldServer) world).getWorld().getBlockAt(i, j, k); + CraftPlayer player = new CraftPlayer(((WorldServer) world).getServer(), (EntityPlayerMP) entityplayer); + BlockInteractEvent bie = new BlockInteractEvent(Type.BLOCK_INTERACT, block, player); + + ((WorldServer) world).getServer().getPluginManager().callEvent(bie); + + if (!bie.isCancelled()) entityplayer.a(((IInventory) (obj))); + + return true; + } + } + + protected TileEntity a_() { + return new TileEntityChest(); + } +} + diff --git a/src/main/java/net/minecraft/server/BlockDoor.java b/src/main/java/net/minecraft/server/BlockDoor.java new file mode 100644 index 0000000000..f051febaa5 --- /dev/null +++ b/src/main/java/net/minecraft/server/BlockDoor.java @@ -0,0 +1,195 @@ +package net.minecraft.server; + + +import java.util.Random; + +import org.bukkit.craftbukkit.CraftBlock; +import org.bukkit.craftbukkit.CraftPlayer; +import org.bukkit.event.Event.Type; +import org.bukkit.event.block.BlockInteractEvent; + + +public class BlockDoor extends Block { + + protected BlockDoor(int i, Material material) { + super(i, material); + bg = 97; + if (material == Material.e) { + bg++; + } + float f = 0.5F; + float f1 = 1.0F; + + a(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f1, 0.5F + f); + } + + public boolean a() { + return false; + } + + public AxisAlignedBB d(World world, int i, int j, int k) { + // Craftbukkit - Downcast necessary for doors to work + a((IBlockAccess) world, i, j, k); + return super.d(world, i, j, k); + } + + public void a(IBlockAccess iblockaccess, int i, int j, int k) { + b(d(iblockaccess.b(i, j, k))); + } + + public void b(int i) { + float f = 0.1875F; + + a(0.0F, 0.0F, 0.0F, 1.0F, 2.0F, 1.0F); + if (i == 0) { + a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f); + } + if (i == 1) { + a(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); + } + if (i == 2) { + a(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F); + } + if (i == 3) { + a(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F); + } + } + + public void b(World world, int i, int j, int k, EntityPlayer entityplayer) { + a(world, i, j, k, entityplayer); + } + + public boolean a(World world, int i, int j, int k, EntityPlayer entityplayer) { + if (bs == Material.e) { + return true; + } + int l = world.b(i, j, k); + + if ((l & 8) != 0) { + if (world.a(i, j - 1, k) == bh) { + a(world, i, j - 1, k, entityplayer); + } + return true; + } + + // Craftbukkit start - Interact Door + CraftBlock block = (CraftBlock) ((WorldServer) world).getWorld().getBlockAt(i, j, k); + CraftPlayer player = new CraftPlayer(((WorldServer) world).getServer(), (EntityPlayerMP) entityplayer); + BlockInteractEvent bie = new BlockInteractEvent(Type.BLOCK_INTERACT, block, player); + + ((WorldServer) world).getServer().getPluginManager().callEvent(bie); + + // Craftbukkit the client updates the doors before the server does it's thing. + // Forcibly send correct data. + if (bie.isCancelled()) { + ((EntityPlayerMP) entityplayer).a.b(new Packet53BlockChange(i, j, k, (WorldServer) world)); + ((EntityPlayerMP) entityplayer).a.b(new Packet53BlockChange(i, j + 1, k, (WorldServer) world)); + return true; + } + + if (world.a(i, j + 1, k) == bh) { + world.b(i, j + 1, k, (l ^ 4) + 8); + } + world.b(i, j, k, l ^ 4); + world.b(i, j - 1, k, i, j, k); + if (Math.random() < 0.5D) { + world.a((double) i + 0.5D, (double) j + 0.5D, (double) k + 0.5D, "random.door_open", 1.0F, world.l.nextFloat() * 0.1F + 0.9F); + } else { + world.a((double) i + 0.5D, (double) j + 0.5D, (double) k + 0.5D, "random.door_close", 1.0F, world.l.nextFloat() * 0.1F + 0.9F); + } + return true; + } + + public void a(World world, int i, int j, int k, boolean flag) { + int l = world.b(i, j, k); + + if ((l & 8) != 0) { + if (world.a(i, j - 1, k) == bh) { + a(world, i, j - 1, k, flag); + } + return; + } + boolean flag1 = (world.b(i, j, k) & 4) > 0; + + if (flag1 == flag) { + return; + } + if (world.a(i, j + 1, k) == bh) { + world.b(i, j + 1, k, (l ^ 4) + 8); + } + world.b(i, j, k, l ^ 4); + world.b(i, j - 1, k, i, j, k); + if (Math.random() < 0.5D) { + world.a((double) i + 0.5D, (double) j + 0.5D, (double) k + 0.5D, "random.door_open", 1.0F, world.l.nextFloat() * 0.1F + 0.9F); + } else { + world.a((double) i + 0.5D, (double) j + 0.5D, (double) k + 0.5D, "random.door_close", 1.0F, world.l.nextFloat() * 0.1F + 0.9F); + } + } + + public void b(World world, int i, int j, int k, int l) { + int i1 = world.b(i, j, k); + + if ((i1 & 8) != 0) { + if (world.a(i, j - 1, k) != bh) { + world.d(i, j, k, 0); + } + if (l > 0 && Block.m[l].c()) { + b(world, i, j - 1, k, l); + } + } else { + boolean flag = false; + + if (world.a(i, j + 1, k) != bh) { + world.d(i, j, k, 0); + flag = true; + } + if (!world.d(i, j - 1, k)) { + world.d(i, j, k, 0); + flag = true; + if (world.a(i, j + 1, k) == bh) { + world.d(i, j + 1, k, 0); + } + } + if (flag) { + a_(world, i, j, k, i1); + } else if (l > 0 && Block.m[l].c()) { + boolean flag1 = world.o(i, j, k) || world.o(i, j + 1, k); + + a(world, i, j, k, flag1); + } + } + } + + public int a(int i, Random random) { + if ((i & 8) != 0) { + return 0; + } + if (bs == Material.e) { + return Item.az.aW; + } else { + return Item.at.aW; + } + } + + public MovingObjectPosition a(World world, int i, int j, int k, Vec3D vec3d, Vec3D vec3d1) { + a(((IBlockAccess) (world)), i, j, k); + return super.a(world, i, j, k, vec3d, vec3d1); + } + + public int d(int i) { + if ((i & 4) == 0) { + return i - 1 & 3; + } else { + return i & 3; + } + } + + public boolean a(World world, int i, int j, int k) { + if (j >= 127) { + return false; + } else { + return world.d(i, j - 1, k) && super.a(world, i, j, k) && super.a(world, i, j + 1, k); + } + } +} + diff --git a/src/main/java/net/minecraft/server/BlockFurnace.java b/src/main/java/net/minecraft/server/BlockFurnace.java new file mode 100644 index 0000000000..64df942c63 --- /dev/null +++ b/src/main/java/net/minecraft/server/BlockFurnace.java @@ -0,0 +1,121 @@ +package net.minecraft.server; + + +import java.util.Random; + +import org.bukkit.craftbukkit.CraftBlock; +import org.bukkit.craftbukkit.CraftPlayer; +import org.bukkit.event.Event.Type; +import org.bukkit.event.block.BlockInteractEvent; + + +public class BlockFurnace extends BlockContainer { + + private final boolean a; + + protected BlockFurnace(int i, boolean flag) { + super(i, Material.d); + a = flag; + bg = 45; + } + + public int a(int i, Random random) { + return Block.aB.bh; + } + + public void e(World world, int i, int j, int k) { + super.e(world, i, j, k); + g(world, i, j, k); + } + + private void g(World world, int i, int j, int k) { + int l = world.a(i, j, k - 1); + int i1 = world.a(i, j, k + 1); + int j1 = world.a(i - 1, j, k); + int k1 = world.a(i + 1, j, k); + byte byte0 = 3; + + if (Block.o[l] && !Block.o[i1]) { + byte0 = 3; + } + if (Block.o[i1] && !Block.o[l]) { + byte0 = 2; + } + if (Block.o[j1] && !Block.o[k1]) { + byte0 = 5; + } + if (Block.o[k1] && !Block.o[j1]) { + byte0 = 4; + } + world.b(i, j, k, byte0); + } + + public int a(int i) { + if (i == 1) { + return Block.t.bh; + } + if (i == 0) { + return Block.t.bh; + } + if (i == 3) { + return bg - 1; + } else { + return bg; + } + } + + public boolean a(World world, int i, int j, int k, EntityPlayer entityplayer) { + if (world.z) { + return true; + } else { + // Craftbukkit start - Interact Furnace + CraftBlock block = (CraftBlock) ((WorldServer) world).getWorld().getBlockAt(i, j, k); + CraftPlayer player = new CraftPlayer(((WorldServer) world).getServer(), (EntityPlayerMP) entityplayer); + BlockInteractEvent bie = new BlockInteractEvent(Type.BLOCK_INTERACT, block, player); + + ((WorldServer) world).getServer().getPluginManager().callEvent(bie); + + if (bie.isCancelled()) return true; + + TileEntityFurnace tileentityfurnace = (TileEntityFurnace) world.l(i, j, k); + + entityplayer.a(tileentityfurnace); + return true; + } + } + + public static void a(boolean flag, World world, int i, int j, int k) { + int l = world.b(i, j, k); + TileEntity tileentity = world.l(i, j, k); + + if (flag) { + world.d(i, j, k, Block.aC.bh); + } else { + world.d(i, j, k, Block.aB.bh); + } + world.b(i, j, k, l); + world.a(i, j, k, tileentity); + } + + protected TileEntity a_() { + return new TileEntityFurnace(); + } + + public void a(World world, int i, int j, int k, EntityLiving entityliving) { + int l = MathHelper.b((double) ((entityliving.v * 4F) / 360F) + 0.5D) & 3; + + if (l == 0) { + world.b(i, j, k, 2); + } + if (l == 1) { + world.b(i, j, k, 5); + } + if (l == 2) { + world.b(i, j, k, 3); + } + if (l == 3) { + world.b(i, j, k, 4); + } + } +} + diff --git a/src/main/java/net/minecraft/server/BlockJukeBox.java b/src/main/java/net/minecraft/server/BlockJukeBox.java new file mode 100644 index 0000000000..8c7e61adf6 --- /dev/null +++ b/src/main/java/net/minecraft/server/BlockJukeBox.java @@ -0,0 +1,64 @@ +package net.minecraft.server; + + +import org.bukkit.craftbukkit.CraftBlock; +import org.bukkit.craftbukkit.CraftPlayer; +import org.bukkit.event.Event.Type; +import org.bukkit.event.block.BlockInteractEvent; + + +public class BlockJukeBox extends Block { + + protected BlockJukeBox(int i, int j) { + super(i, j, Material.c); + } + + public int a(int i) { + return bg + (i != 1 ? 0 : 1); + } + + public boolean a(World world, int i, int j, int k, EntityPlayer entityplayer) { + int l = world.b(i, j, k); + + if (l > 0) { + // Craftbukkit start - Interact Jukebox + CraftBlock block = (CraftBlock) ((WorldServer) world).getWorld().getBlockAt(i, j, k); + CraftPlayer player = new CraftPlayer(((WorldServer) world).getServer(), (EntityPlayerMP) entityplayer); + BlockInteractEvent bie = new BlockInteractEvent(Type.BLOCK_INTERACT, block, player); + + ((WorldServer) world).getServer().getPluginManager().callEvent(bie); + + if (bie.isCancelled()) return true; + + f(world, i, j, k, l); + return true; + } else { + return false; + } + } + + public void f(World world, int i, int j, int k, int l) { + world.a((String) null, i, j, k); + world.b(i, j, k, 0); + int i1 = (Item.aU.aW + l) - 1; + float f1 = 0.7F; + double d = (double) (world.l.nextFloat() * f1) + (double) (1.0F - f1) * 0.5D; + double d1 = (double) (world.l.nextFloat() * f1) + (double) (1.0F - f1) * 0.20000000000000001D + 0.59999999999999998D; + double d2 = (double) (world.l.nextFloat() * f1) + (double) (1.0F - f1) * 0.5D; + EntityItem entityitem = new EntityItem(world, (double) i + d, (double) j + d1, (double) k + d2, new ItemStack(i1)); + + entityitem.c = 10; + world.a(entityitem); + } + + public void a(World world, int i, int j, int k, int l, float f1) { + if (world.z) { + return; + } + if (l > 0) { + f(world, i, j, k, l); + } + super.a(world, i, j, k, l, f1); + } +} + diff --git a/src/main/java/net/minecraft/server/BlockLever.java b/src/main/java/net/minecraft/server/BlockLever.java new file mode 100644 index 0000000000..b8204e1634 --- /dev/null +++ b/src/main/java/net/minecraft/server/BlockLever.java @@ -0,0 +1,231 @@ +package net.minecraft.server; + +import org.bukkit.craftbukkit.CraftBlock; +import org.bukkit.craftbukkit.CraftPlayer; +import org.bukkit.event.Event.Type; +import org.bukkit.event.block.BlockInteractEvent; + + +public class BlockLever extends Block { + + protected BlockLever(int i, int j) { + super(i, j, Material.n); + } + + public AxisAlignedBB d(World world, int i, int j, int k) { + return null; + } + + public boolean a() { + return false; + } + + public boolean a(World world, int i, int j, int k) { + if (world.d(i - 1, j, k)) { + return true; + } + if (world.d(i + 1, j, k)) { + return true; + } + if (world.d(i, j, k - 1)) { + return true; + } + if (world.d(i, j, k + 1)) { + return true; + } + return world.d(i, j - 1, k); + } + + public void c(World world, int i, int j, int k, int l) { + int i1 = world.b(i, j, k); + int j1 = i1 & 8; + + i1 &= 7; + if (l == 1 && world.d(i, j - 1, k)) { + i1 = 5 + world.l.nextInt(2); + } + if (l == 2 && world.d(i, j, k + 1)) { + i1 = 4; + } + if (l == 3 && world.d(i, j, k - 1)) { + i1 = 3; + } + if (l == 4 && world.d(i + 1, j, k)) { + i1 = 2; + } + if (l == 5 && world.d(i - 1, j, k)) { + i1 = 1; + } + world.b(i, j, k, i1 + j1); + } + + public void e(World world, int i, int j, int k) { + if (world.d(i - 1, j, k)) { + world.b(i, j, k, 1); + } else if (world.d(i + 1, j, k)) { + world.b(i, j, k, 2); + } else if (world.d(i, j, k - 1)) { + world.b(i, j, k, 3); + } else if (world.d(i, j, k + 1)) { + world.b(i, j, k, 4); + } else if (world.d(i, j - 1, k)) { + world.b(i, j, k, 5 + world.l.nextInt(2)); + } + g(world, i, j, k); + } + + public void b(World world, int i, int j, int k, int l) { + if (g(world, i, j, k)) { + int i1 = world.b(i, j, k) & 7; + boolean flag = false; + + if (!world.d(i - 1, j, k) && i1 == 1) { + flag = true; + } + if (!world.d(i + 1, j, k) && i1 == 2) { + flag = true; + } + if (!world.d(i, j, k - 1) && i1 == 3) { + flag = true; + } + if (!world.d(i, j, k + 1) && i1 == 4) { + flag = true; + } + if (!world.d(i, j - 1, k) && i1 == 5) { + flag = true; + } + if (flag) { + a_(world, i, j, k, world.b(i, j, k)); + world.d(i, j, k, 0); + } + } + } + + private boolean g(World world, int i, int j, int k) { + if (!a(world, i, j, k)) { + a_(world, i, j, k, world.b(i, j, k)); + world.d(i, j, k, 0); + return false; + } else { + return true; + } + } + + public void a(IBlockAccess iblockaccess, int i, int j, int k) { + int l = iblockaccess.b(i, j, k) & 7; + float f = 0.1875F; + + if (l == 1) { + a(0.0F, 0.2F, 0.5F - f, f * 2.0F, 0.8F, 0.5F + f); + } else if (l == 2) { + a(1.0F - f * 2.0F, 0.2F, 0.5F - f, 1.0F, 0.8F, 0.5F + f); + } else if (l == 3) { + a(0.5F - f, 0.2F, 0.0F, 0.5F + f, 0.8F, f * 2.0F); + } else if (l == 4) { + a(0.5F - f, 0.2F, 1.0F - f * 2.0F, 0.5F + f, 0.8F, 1.0F); + } else { + float f1 = 0.25F; + + a(0.5F - f1, 0.0F, 0.5F - f1, 0.5F + f1, 0.6F, 0.5F + f1); + } + } + + public void b(World world, int i, int j, int k, EntityPlayer entityplayer) { + a(world, i, j, k, entityplayer); + } + + public boolean a(World world, int i, int j, int k, EntityPlayer entityplayer) { + if (world.z) { + return true; + } + + // Craftbukkit start - Interact Lever + CraftBlock block = (CraftBlock) ((WorldServer) world).getWorld().getBlockAt(i, j, k); + CraftPlayer player = new CraftPlayer(((WorldServer) world).getServer(), (EntityPlayerMP) entityplayer); + BlockInteractEvent bie = new BlockInteractEvent(Type.BLOCK_INTERACT, block, player); + + ((WorldServer) world).getServer().getPluginManager().callEvent(bie); + + // Craftbukkit the client updates the doors before the server does it's thing. + // Forcibly send correct data. + if (bie.isCancelled()) { + ((EntityPlayerMP) entityplayer).a.b(new Packet53BlockChange(i, j, k, (WorldServer) world)); + return true; + } + + int l = world.b(i, j, k); + int i1 = l & 7; + int j1 = 8 - (l & 8); + + world.b(i, j, k, i1 + j1); + world.b(i, j, k, i, j, k); + world.a((double) i + 0.5D, (double) j + 0.5D, (double) k + 0.5D, "random.click", 0.3F, j1 <= 0 ? 0.5F : 0.6F); + world.g(i, j, k, bh); + if (i1 == 1) { + world.g(i - 1, j, k, bh); + } else if (i1 == 2) { + world.g(i + 1, j, k, bh); + } else if (i1 == 3) { + world.g(i, j, k - 1, bh); + } else if (i1 == 4) { + world.g(i, j, k + 1, bh); + } else { + world.g(i, j - 1, k, bh); + } + return true; + } + + public void b(World world, int i, int j, int k) { + int l = world.b(i, j, k); + + if ((l & 8) > 0) { + world.g(i, j, k, bh); + int i1 = l & 7; + + if (i1 == 1) { + world.g(i - 1, j, k, bh); + } else if (i1 == 2) { + world.g(i + 1, j, k, bh); + } else if (i1 == 3) { + world.g(i, j, k - 1, bh); + } else if (i1 == 4) { + world.g(i, j, k + 1, bh); + } else { + world.g(i, j - 1, k, bh); + } + } + super.b(world, i, j, k); + } + + public boolean b(IBlockAccess iblockaccess, int i, int j, int k, int l) { + return (iblockaccess.b(i, j, k) & 8) > 0; + } + + public boolean d(World world, int i, int j, int k, int l) { + int i1 = world.b(i, j, k); + + if ((i1 & 8) == 0) { + return false; + } + int j1 = i1 & 7; + + if (j1 == 5 && l == 1) { + return true; + } + if (j1 == 4 && l == 2) { + return true; + } + if (j1 == 3 && l == 3) { + return true; + } + if (j1 == 2 && l == 4) { + return true; + } + return j1 == 1 && l == 5; + } + + public boolean c() { + return true; + } +} + diff --git a/src/main/java/net/minecraft/server/BlockPressurePlate.java b/src/main/java/net/minecraft/server/BlockPressurePlate.java new file mode 100644 index 0000000000..4745f67897 --- /dev/null +++ b/src/main/java/net/minecraft/server/BlockPressurePlate.java @@ -0,0 +1,171 @@ +package net.minecraft.server; + + +import java.util.List; +import java.util.Random; + +import org.bukkit.craftbukkit.CraftBlock; +import org.bukkit.craftbukkit.CraftLivingEntity; +import org.bukkit.craftbukkit.CraftPlayer; +import org.bukkit.event.Event.Type; +import org.bukkit.event.block.BlockInteractEvent; + + +public class BlockPressurePlate extends Block { + + private EnumMobType a; + + protected BlockPressurePlate(int i, int j, EnumMobType enummobtype) { + super(i, j, Material.d); + a = enummobtype; + a(true); + float f = 0.0625F; + + a(f, 0.0F, f, 1.0F - f, 0.03125F, 1.0F - f); + } + + public int b() { + return 20; + } + + public AxisAlignedBB d(World world, int i, int j, int k) { + return null; + } + + public boolean a() { + return false; + } + + public boolean a(World world, int i, int j, int k) { + return world.d(i, j - 1, k); + } + + public void e(World world, int i, int j, int k) {} + + public void b(World world, int i, int j, int k, int l) { + boolean flag = false; + + if (!world.d(i, j - 1, k)) { + flag = true; + } + if (flag) { + a_(world, i, j, k, world.b(i, j, k)); + world.d(i, j, k, 0); + } + } + + public void a(World world, int i, int j, int k, Random random) { + if (world.z) { + return; + } + if (world.b(i, j, k) == 0) { + return; + } else { + g(world, i, j, k); + return; + } + } + + public void a(World world, int i, int j, int k, Entity entity) { + if (world.z) { + return; + } + if (world.b(i, j, k) == 1) { + return; + } else { + if (entity instanceof EntityLiving) { + // Craftbukkit start - Interact Pressure Plate + CraftBlock block = (CraftBlock) ((WorldServer) world).getWorld().getBlockAt(i, j, k); + CraftLivingEntity craftEntity = null; + if (entity instanceof EntityPlayerMP) { + craftEntity = new CraftPlayer(((WorldServer) world).getServer(), (EntityPlayerMP) entity); + } else { + craftEntity = new CraftLivingEntity(((WorldServer) world).getServer(), (EntityLiving) entity); + } + BlockInteractEvent bie = new BlockInteractEvent(Type.BLOCK_INTERACT, block, craftEntity); + + ((WorldServer) world).getServer().getPluginManager().callEvent(bie); + + if (bie.isCancelled()) return; + } + + g(world, i, j, k); + return; + } + } + + private void g(World world, int i, int j, int k) { + boolean flag = world.b(i, j, k) == 1; + boolean flag1 = false; + float f = 0.125F; + List list = null; + + if (a == EnumMobType.a) { + list = world.b(null, AxisAlignedBB.b((float) i + f, j, (float) k + f, (float) (i + 1) - f, (double) j + 0.25D, (float) (k + 1) - f)); + } + if (a == EnumMobType.b) { + list = world.a(net.minecraft.server.EntityLiving.class, AxisAlignedBB.b((float) i + f, j, (float) k + f, (float) (i + 1) - f, (double) j + 0.25D, (float) (k + 1) - f)); + } + if (a == EnumMobType.c) { + list = world.a(net.minecraft.server.EntityPlayer.class, AxisAlignedBB.b((float) i + f, j, (float) k + f, (float) (i + 1) - f, (double) j + 0.25D, (float) (k + 1) - f)); + } + if (list.size() > 0) { + flag1 = true; + } + if (flag1 && !flag) { + world.b(i, j, k, 1); + world.g(i, j, k, bh); + world.g(i, j - 1, k, bh); + world.b(i, j, k, i, j, k); + world.a((double) i + 0.5D, (double) j + 0.10000000000000001D, (double) k + 0.5D, "random.click", 0.3F, 0.6F); + } + if (!flag1 && flag) { + world.b(i, j, k, 0); + world.g(i, j, k, bh); + world.g(i, j - 1, k, bh); + world.b(i, j, k, i, j, k); + world.a((double) i + 0.5D, (double) j + 0.10000000000000001D, (double) k + 0.5D, "random.click", 0.3F, 0.5F); + } + if (flag1) { + world.h(i, j, k, bh); + } + } + + public void b(World world, int i, int j, int k) { + int l = world.b(i, j, k); + + if (l > 0) { + world.g(i, j, k, bh); + world.g(i, j - 1, k, bh); + } + super.b(world, i, j, k); + } + + public void a(IBlockAccess iblockaccess, int i, int j, int k) { + boolean flag = iblockaccess.b(i, j, k) == 1; + float f = 0.0625F; + + if (flag) { + a(f, 0.0F, f, 1.0F - f, 0.03125F, 1.0F - f); + } else { + a(f, 0.0F, f, 1.0F - f, 0.0625F, 1.0F - f); + } + } + + public boolean b(IBlockAccess iblockaccess, int i, int j, int k, int l) { + return iblockaccess.b(i, j, k) > 0; + } + + public boolean d(World world, int i, int j, int k, int l) { + if (world.b(i, j, k) == 0) { + return false; + } else { + return l == 1; + } + } + + public boolean c() { + return true; + } +} + diff --git a/src/main/java/net/minecraft/server/BlockWorkbench.java b/src/main/java/net/minecraft/server/BlockWorkbench.java new file mode 100644 index 0000000000..08977d50cd --- /dev/null +++ b/src/main/java/net/minecraft/server/BlockWorkbench.java @@ -0,0 +1,48 @@ +package net.minecraft.server; + +import org.bukkit.craftbukkit.CraftBlock; +import org.bukkit.craftbukkit.CraftPlayer; +import org.bukkit.event.Event.Type; +import org.bukkit.event.block.BlockInteractEvent; + + +public class BlockWorkbench extends Block { + + protected BlockWorkbench(int i) { + super(i, Material.c); + bg = 59; + } + + public int a(int i) { + if (i == 1) { + return bg - 16; + } + if (i == 0) { + return Block.x.a(0); + } + if (i == 2 || i == 4) { + return bg + 1; + } else { + return bg; + } + } + + public boolean a(World world, int i, int j, int k, EntityPlayer entityplayer) { + if (world.z) { + return true; + } else { + // Craftbukkit start - Interact Workbench + CraftBlock block = (CraftBlock) ((WorldServer) world).getWorld().getBlockAt(i, j, k); + CraftPlayer player = new CraftPlayer(((WorldServer) world).getServer(), (EntityPlayerMP) entityplayer); + BlockInteractEvent bie = new BlockInteractEvent(Type.BLOCK_INTERACT, block, player); + + ((WorldServer) world).getServer().getPluginManager().callEvent(bie); + + if (bie.isCancelled()) return true; + + entityplayer.a(i, j, k); + return true; + } + } +} + diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java index 69d854f401..759651c7d2 100644 --- a/src/main/java/net/minecraft/server/Entity.java +++ b/src/main/java/net/minecraft/server/Entity.java @@ -829,7 +829,10 @@ public abstract class Entity { return (double) J * 0.75D; } - public void e(Entity entity) { + public void setPassengerOf(Entity entity) { + // e(null) doesn't really fly for overloaded methods, + // so this method is needed + d = 0.0D; e = 0.0D; if (entity == null) { @@ -855,6 +858,10 @@ public abstract class Entity { k = entity; entity.j = this; } + + public void e(Entity entity) { + setPassengerOf(entity); + } public Vec3D C() { return null; diff --git a/src/main/java/net/minecraft/server/EntityBoat.java b/src/main/java/net/minecraft/server/EntityBoat.java new file mode 100644 index 0000000000..92412d9515 --- /dev/null +++ b/src/main/java/net/minecraft/server/EntityBoat.java @@ -0,0 +1,368 @@ +package net.minecraft.server; + +import java.util.List; + +import org.bukkit.Location; +import org.bukkit.craftbukkit.CraftBoat; +import org.bukkit.craftbukkit.CraftEntity; +import org.bukkit.craftbukkit.CraftMappable; +import org.bukkit.craftbukkit.CraftMinecart; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.event.Event.Type; +import org.bukkit.event.vehicle.VehicleCreateEvent; +import org.bukkit.event.vehicle.VehicleDamageEvent; +import org.bukkit.event.vehicle.VehicleEnterEvent; +import org.bukkit.event.vehicle.VehicleEntityCollisionEvent; +import org.bukkit.event.vehicle.VehicleMoveEvent; + +public class EntityBoat extends Entity implements CraftMappable { + + private CraftBoat boat; + + public int a; + public int b; + public int c; + private int d; + private double e; + private double f; + private double aj; + private double ak; + private double al; + + public CraftEntity getCraftEntity() { + return boat; + } + + public EntityBoat(World world) { + super(world); + a = 0; + b = 0; + c = 1; + i = true; + a(1.5F, 0.6F); + H = J / 2.0F; + M = false; + + // CraftBukkit start + handleCreation(world); + // CraftBukkit end + } + + public AxisAlignedBB d(Entity entity) { + return entity.z; + } + + public AxisAlignedBB q() { + return z; + } + + public boolean v() { + return true; + } + + public EntityBoat(World world, double d1, double d2, double d3) { + this(world); + a(d1, d2 + (double) H, d3); + s = 0.0D; + t = 0.0D; + u = 0.0D; + m = d1; + n = d2; + o = d3; + + // CraftBukkit start + handleCreation(world); + // CraftBukkit end + } + + // CraftBukkit start + private void handleCreation(World world) { + CraftServer server = ((WorldServer) world).getServer(); + boat = new CraftBoat(server, this); + VehicleCreateEvent event = new VehicleCreateEvent( + Type.VEHICLE_CREATE, boat); + server.getPluginManager().callEvent(event); + } + // CraftBukkit end + + public double j() { + return (double) J * 0.0D - 0.30000001192092896D; + } + + public boolean a(Entity entity, int i) { + // CraftBukkit start + VehicleDamageEvent event = new VehicleDamageEvent( + Type.VEHICLE_DAMAGE, boat, + ((WorldServer)l).getWorld().toCraftEntity(entity), i); + ((WorldServer)l).getServer().getPluginManager().callEvent(event); + + if (event.isCancelled()) { + return true; + } + // CraftBukkit end + + if (this.l.z || G) { + return true; + } + c = -c; + b = 10; + a += i * 10; + u(); + if (a > 40) { + for (int k = 0; k < 3; k++) { + a(Block.x.bh, 1, 0.0F); + } + + for (int l = 0; l < 2; l++) { + a(Item.B.aW, 1, 0.0F); + } + + l(); + } + return true; + } + + public boolean c_() { + return !G; + } + + public void b_() { + double prevX = p; + double prevY = q; + double prevZ = r; + float prevYaw = v; + float prevPitch = w; + + super.b_(); + if (b > 0) { + b--; + } + if (a > 0) { + a--; + } + m = p; + n = q; + o = r; + int i = 5; + double d1 = 0.0D; + + for (int k = 0; k < i; k++) { + double d2 = (z.b + ((z.e - z.b) * (double) (k + 0)) / (double) i) - 0.125D; + double d3 = (z.b + ((z.e - z.b) * (double) (k + 1)) / (double) i) - 0.125D; + AxisAlignedBB axisalignedbb = AxisAlignedBB.b(z.a, d2, z.c, z.d, d3, z.f); + + if (this.l.b(axisalignedbb, Material.f)) { + d1 += 1.0D / (double) i; + } + } + + if (this.l.z) { + if (d > 0) { + double d4 = p + (e - p) / (double) d; + double d7 = q + (f - q) / (double) d; + double d10 = r + (aj - r) / (double) d; + double d13; + + for (d13 = ak - (double) v; d13 < -180D; d13 += 360D) { + ; + } + for (; d13 >= 180D; d13 -= 360D) { + ; + } + v += d13 / (double) d; + w += (al - (double) w) / (double) d; + d--; + a(d4, d7, d10); + b(v, w); + } else { + double d5 = p + s; + double d8 = q + t; + double d11 = r + u; + + a(d5, d8, d11); + if (A) { + s *= 0.5D; + t *= 0.5D; + u *= 0.5D; + } + s *= 0.99000000953674316D; + t *= 0.94999998807907104D; + u *= 0.99000000953674316D; + } + return; + } + double d6 = d1 * 2D - 1.0D; + + t += 0.039999999105930328D * d6; + if (j != null) { + s += j.s * 0.20000000000000001D; + u += j.u * 0.20000000000000001D; + } + double d9 = 0.40000000000000002D; + + if (s < -d9) { + s = -d9; + } + if (s > d9) { + s = d9; + } + if (u < -d9) { + u = -d9; + } + if (u > d9) { + u = d9; + } + if (A) { + s *= 0.5D; + t *= 0.5D; + u *= 0.5D; + } + c(s, t, u); + double d12 = Math.sqrt(s * s + u * u); + + if (d12 > 0.14999999999999999D) { + double d14 = Math.cos(((double) v * 3.1415926535897931D) / 180D); + double d16 = Math.sin(((double) v * 3.1415926535897931D) / 180D); + + for (int l = 0; (double) l < 1.0D + d12 * 60D; l++) { + double d18 = W.nextFloat() * 2.0F - 1.0F; + double d19 = (double) (W.nextInt(2) * 2 - 1) * 0.69999999999999996D; + + if (W.nextBoolean()) { + double d20 = (p - d14 * d18 * 0.80000000000000004D) + d16 * d19; + double d22 = r - d16 * d18 * 0.80000000000000004D - d14 * d19; + + this.l.a("splash", d20, q - 0.125D, d22, s, t, u); + } else { + double d21 = p + d14 + d16 * d18 * 0.69999999999999996D; + double d23 = (r + d16) - d14 * d18 * 0.69999999999999996D; + + this.l.a("splash", d21, q - 0.125D, d23, s, t, u); + } + } + + } + if (B && d12 > 0.14999999999999999D) { + if (!this.l.z) { + l(); + for (int i1 = 0; i1 < 3; i1++) { + a(Block.x.bh, 1, 0.0F); + } + + for (int j1 = 0; j1 < 2; j1++) { + a(Item.B.aW, 1, 0.0F); + } + + } + } else { + s *= 0.99000000953674316D; + t *= 0.94999998807907104D; + u *= 0.99000000953674316D; + } + w = 0.0F; + double d15 = v; + double d17 = m - p; + double d24 = o - r; + + if (d17 * d17 + d24 * d24 > 0.001D) { + d15 = (float) ((Math.atan2(d24, d17) * 180D) / 3.1415926535897931D); + } + double d25; + + for (d25 = d15 - (double) v; d25 >= 180D; d25 -= 360D) { + ; + } + for (; d25 < -180D; d25 += 360D) { + ; + } + if (d25 > 20D) { + d25 = 20D; + } + if (d25 < -20D) { + d25 = -20D; + } + v += d25; + b(v, w); + + // CraftBukkit start + CraftServer server = ((WorldServer)l).getServer(); + VehicleMoveEvent event = new VehicleMoveEvent( + Type.VEHICLE_MOVE, boat, + new Location(((WorldServer)l).getWorld(), prevX, prevY, prevZ, prevYaw, prevPitch), + new Location(((WorldServer)l).getWorld(), p, q, r, v, w)); + server.getPluginManager().callEvent(event); + // CraftBukkit end + + List list = this.l.b(this, z.b(0.20000000298023224D, 0.0D, 0.20000000298023224D)); + + if (list != null && list.size() > 0) { + for (int k1 = 0; k1 < list.size(); k1++) { + Entity entity = (Entity) list.get(k1); + + if (entity != j && entity.v() && (entity instanceof EntityBoat)) { + entity.c(this); + } + } + + } + if (j != null && j.G) { + j = null; + } + } + + public void A() { + if (j == null) { + return; + } else { + double d1 = Math.cos(((double) v * 3.1415926535897931D) / 180D) * 0.40000000000000002D; + double d2 = Math.sin(((double) v * 3.1415926535897931D) / 180D) * 0.40000000000000002D; + + j.a(p + d1, q + j() + j.B(), r + d2); + return; + } + } + + public void c(Entity entity) { + // CraftBukkit start + CraftServer server = ((WorldServer)l).getServer(); + VehicleEntityCollisionEvent collsionEvent = new VehicleEntityCollisionEvent( + Type.VEHICLE_COLLISION_ENTITY, boat, + ((WorldServer)l).getWorld().toCraftEntity(entity)); + server.getPluginManager().callEvent(collsionEvent); + + if (collsionEvent.isCancelled()) { + return; + } + // CraftBukkit end + + super.c(entity); + } + + protected void a(NBTTagCompound nbttagcompound) {} + + protected void b(NBTTagCompound nbttagcompound) {} + + public boolean a(EntityPlayer entityplayer) { + if (j != null && (j instanceof EntityPlayer) && j != entityplayer) { + return true; + } + if (!l.z) { + // CraftBukkit start + CraftServer server = ((WorldServer)l).getServer(); + VehicleEnterEvent event = new VehicleEnterEvent( + Type.VEHICLE_ENTER, + boat, + ((WorldServer)l).getWorld().toCraftEntity(entityplayer)); + server.getPluginManager().callEvent(event); + + if (event.isCancelled()) { + return true; + } + // CraftBukkit end + + entityplayer.e(this); + } + return true; + } +} + diff --git a/src/main/java/net/minecraft/server/EntityMinecart.java b/src/main/java/net/minecraft/server/EntityMinecart.java index d7fc002c91..cb54f5fe03 100644 --- a/src/main/java/net/minecraft/server/EntityMinecart.java +++ b/src/main/java/net/minecraft/server/EntityMinecart.java @@ -2,15 +2,18 @@ package net.minecraft.server; import java.util.List; +import org.bukkit.Location; +import org.bukkit.Vector; +import org.bukkit.craftbukkit.CraftEntity; +import org.bukkit.craftbukkit.CraftMappable; import org.bukkit.craftbukkit.CraftMinecart; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.event.Event.Type; import org.bukkit.event.vehicle.*; public class EntityMinecart extends Entity - implements IInventory { + implements IInventory, CraftMappable { - private CraftServer server; private CraftMinecart minecart; private ItemStack ak[]; @@ -91,6 +94,18 @@ public class EntityMinecart extends Entity private double aq; private double ar; private double as; + + private boolean slowWhenEmpty = true; + private double derailedX = 0.5; + private double derailedY = 0.5; + private double derailedZ = 0.5; + private double flyingX = 0.94999998807907104; + private double flyingY = 0.94999998807907104; + private double flyingZ = 0.94999998807907104; + + public CraftEntity getCraftEntity() { + return minecart; + } public EntityMinecart(World world) { super(world); @@ -105,11 +120,7 @@ public class EntityMinecart extends Entity M = false; // CraftBukkit start - server = ((WorldServer) world).getServer(); - minecart = CraftMinecart.getCraftMinecart(server, this); - VehicleCreateEvent event = new VehicleCreateEvent(Type.VEHICLE_CREATE, - minecart); - server.getPluginManager().callEvent(event); + handleCreation(world); // CraftBukkit end } @@ -144,14 +155,20 @@ public class EntityMinecart extends Entity d = i; // CraftBukkit start - server = ((WorldServer) world).getServer(); - minecart = CraftMinecart.getCraftMinecart(server, this); - VehicleCreateEvent event = new VehicleCreateEvent(Type.VEHICLE_CREATE, - minecart); - server.getPluginManager().callEvent(event); + handleCreation(world); // CraftBukkit end } + // CraftBukkit start + private void handleCreation(World world) { + CraftServer server = ((WorldServer) world).getServer(); + minecart = CraftMinecart.getCraftMinecart(server, this); + VehicleCreateEvent event = new VehicleCreateEvent( + Type.VEHICLE_CREATE, minecart); + server.getPluginManager().callEvent(event); + } + // CraftBukkit end + public double j() { return (double) J * 0.0D - 0.30000001192092896D; } @@ -159,16 +176,14 @@ public class EntityMinecart extends Entity public boolean a(Entity entity, int i) { // CraftBukkit start VehicleDamageEvent event = new VehicleDamageEvent( - Type.VEHICLE_DAMAGE, - minecart, - null, // @TODO: Needs to be written - i); - server.getPluginManager().callEvent(event); - // CraftBukkit end + Type.VEHICLE_DAMAGE, minecart, + ((WorldServer)l).getWorld().toCraftEntity(entity), i); + ((WorldServer)l).getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { return true; } + // CraftBukkit end i = event.getDamage(); @@ -231,6 +246,12 @@ public class EntityMinecart extends Entity } public void b_() { + double prevX = p; + double prevY = q; + double prevZ = r; + float prevYaw = v; + float prevPitch = w; + if (b > 0) { b--; } @@ -359,7 +380,7 @@ public class EntityMinecart extends Entity } else if (ai[1][1] != 0 && MathHelper.b(p) - i == ai[1][0] && MathHelper.b(r) - i1 == ai[1][2]) { a(p, q + (double) ai[1][1], r); } - if (j != null) { + if (j != null || !slowWhenEmpty) { s *= 0.99699997901916504D; t *= 0.0D; u *= 0.99699997901916504D; @@ -438,17 +459,18 @@ public class EntityMinecart extends Entity u = d6; } if (A) { - s *= 0.5D; - t *= 0.5D; - u *= 0.5D; + s *= derailedX; + t *= derailedY; + u *= derailedZ; } c(s, t, u); if (!A) { - s *= 0.94999998807907104D; - t *= 0.94999998807907104D; - u *= 0.94999998807907104D; + s *= flyingX; + t *= flyingY; + u *= flyingZ; } } + w = 0.0F; double d28 = m - p; double d29 = o - r; @@ -472,6 +494,16 @@ public class EntityMinecart extends Entity al = !al; } b(v, w); + + // CraftBukkit start + CraftServer server = ((WorldServer)l).getServer(); + VehicleMoveEvent event = new VehicleMoveEvent( + Type.VEHICLE_MOVE, minecart, + new Location(((WorldServer)l).getWorld(), prevX, prevY, prevZ, prevYaw, prevPitch), + new Location(((WorldServer)l).getWorld(), p, q, r, v, w)); + server.getPluginManager().callEvent(event); + // CraftBukkit end + List list = l.b(this, z.b(0.20000000298023224D, 0.0D, 0.20000000298023224D)); if (list != null && list.size() > 0) { @@ -605,21 +637,36 @@ public class EntityMinecart extends Entity } // CraftBukkit start - VehicleEntityCollisionEvent event = new VehicleEntityCollisionEvent( - Type.VEHICLE_COLLISION_ENTITY, - minecart, - null); // @TODO: Needs to be written - server.getPluginManager().callEvent(event); - // CraftBukkit end + CraftServer server = ((WorldServer)l).getServer(); + VehicleEntityCollisionEvent collsionEvent = new VehicleEntityCollisionEvent( + Type.VEHICLE_COLLISION_ENTITY, minecart, + ((WorldServer)l).getWorld().toCraftEntity(entity)); + server.getPluginManager().callEvent(collsionEvent); - if ((entity instanceof EntityLiving) && !(entity instanceof EntityPlayer) && d == 0 && s * s + u * u > 0.01D && j == null && entity.k == null) { - entity.e(this); + if (collsionEvent.isCancelled()) { + return; + } + // CraftBukkit end + + if (!collsionEvent.isPickupCancelled() + && (entity instanceof EntityLiving) && !(entity instanceof EntityPlayer) + && d == 0 && s * s + u * u > 0.01D && j == null && entity.k == null) { + // CraftBukkit start + VehicleEnterEvent enterEvent = new VehicleEnterEvent( + Type.VEHICLE_ENTER, minecart, + ((WorldServer)l).getWorld().toCraftEntity(entity)); + server.getPluginManager().callEvent(enterEvent); + // CraftBukkit end + + if (!enterEvent.isCancelled()) { + entity.e(this); + } } double d1 = entity.p - p; double d2 = entity.r - r; double d3 = d1 * d1 + d2 * d2; - if (d3 >= 9.9999997473787516E-005D) { + if (!collsionEvent.isCollisionCancelled() && d3 >= 9.9999997473787516E-005D) { d3 = MathHelper.a(d3); d1 /= d3; d2 /= d3; @@ -713,12 +760,25 @@ public class EntityMinecart extends Entity public void d() {} - public boolean a(EntityPlayer entityplayer) { + public boolean a(EntityPlayer entityplayer) { if (d == 0) { if (j != null && (j instanceof EntityPlayer) && j != entityplayer) { return true; } if (!l.z) { + // CraftBukkit start + CraftServer server = ((WorldServer)l).getServer(); + VehicleEnterEvent event = new VehicleEnterEvent( + Type.VEHICLE_ENTER, + minecart, + ((WorldServer)l).getWorld().toCraftEntity(entityplayer)); + server.getPluginManager().callEvent(event); + + if (event.isCancelled()) { + return true; + } + // CraftBukkit end + entityplayer.e(this); } } else if (d == 1) { diff --git a/src/main/java/net/minecraft/server/EntityPlayerMP.java b/src/main/java/net/minecraft/server/EntityPlayerMP.java new file mode 100644 index 0000000000..751081c23a --- /dev/null +++ b/src/main/java/net/minecraft/server/EntityPlayerMP.java @@ -0,0 +1,291 @@ +package net.minecraft.server; + + +import java.util.*; + + +public class EntityPlayerMP extends EntityPlayer + implements ICrafting { + + public NetServerHandler a; + public MinecraftServer b; + public ItemInWorldManager c; + public double d; + public double e; + public List f; + public Set aj; + public double ak; + public boolean al; + private int bE; + private int bF; + private int bG[] = { + -1, -1, -1, -1, -1 + }; + private int bH; + public boolean am; + + public EntityPlayerMP(MinecraftServer minecraftserver, World world, String s1, ItemInWorldManager iteminworldmanager) { + super(world); + f = new LinkedList(); + aj = new HashSet(); + al = false; + bE = 0xfa0a1f01; + bF = 60; + bH = 0; + int i = world.m; + int j = world.o; + int l = world.n; + + if (!world.q.e) { + i += W.nextInt(20) - 10; + l = world.e(i, j); + j += W.nextInt(20) - 10; + } + c((double) i + 0.5D, l, (double) j + 0.5D, 0.0F, 0.0F); + b = minecraftserver; + S = 0.0F; + iteminworldmanager.a = this; + aw = s1; + c = iteminworldmanager; + H = 0.0F; + } + + public void k() { + // CraftBukkit: Downcast to make it work. + ap.a((ICrafting)this); + } + + public int[] E() { + return bG; + } + + public void b_() { + bF--; + ap.a(); + for (int i = 0; i < 5; i++) { + int j = a(i); + + if (j != bG[i]) { + b.k.a(this, new Packet5PlayerInventory(g, i, j)); + bG[i] = j; + } + } + + } + + public int a(int i) { + if (i == 0) { + return c(an.e()); + } else { + return c(an.b[i - 1]); + } + } + + private int c(ItemStack itemstack) { + if (itemstack == null) { + return -1; + } else { + return itemstack.c; + } + } + + public void f(Entity entity) { + an.h(); + } + + public boolean a(Entity entity, int i) { + if (bF > 0) { + return false; + } + if (!b.n) { + if (entity instanceof EntityPlayer) { + return false; + } + if (entity instanceof EntityArrow) { + EntityArrow entityarrow = (EntityArrow) entity; + + if (entityarrow.b instanceof EntityPlayer) { + return false; + } + } + } + return super.a(entity, i); + } + + public void c(int i) { + super.c(i); + } + + public void F() { + super.b_(); + ChunkCoordIntPair chunkcoordintpair = null; + double d1 = 0.0D; + + for (int i = 0; i < f.size(); i++) { + ChunkCoordIntPair chunkcoordintpair1 = (ChunkCoordIntPair) f.get(i); + double d2 = chunkcoordintpair1.a(this); + + if (i == 0 || d2 < d1) { + chunkcoordintpair = chunkcoordintpair1; + d1 = chunkcoordintpair1.a(this); + } + } + + if (chunkcoordintpair != null) { + boolean flag = false; + + if (d1 < 1024D) { + flag = true; + } + if (a.b() < 2) { + flag = true; + } + if (flag) { + f.remove(chunkcoordintpair); + a.b(new Packet51MapChunk(chunkcoordintpair.a * 16, 0, chunkcoordintpair.b * 16, 16, 128, 16, b.e)); + List list = b.e.d(chunkcoordintpair.a * 16, 0, chunkcoordintpair.b * 16, chunkcoordintpair.a * 16 + 16, 128, chunkcoordintpair.b * 16 + 16); + + for (int j = 0; j < list.size(); j++) { + a((TileEntity) list.get(j)); + } + + } + } + if (ba != bE) { + a.b(new Packet8(ba)); + bE = ba; + } + } + + private void a(TileEntity tileentity) { + if (tileentity != null) { + Packet packet = tileentity.f(); + + if (packet != null) { + a.b(packet); + } + } + } + + public void G() { + s = t = u = 0.0D; + bB = false; + super.G(); + } + + public void c(Entity entity, int i) { + if (!entity.G) { + if (entity instanceof EntityItem) { + b.k.a(entity, new Packet22Collect(entity.g, g)); + } + if (entity instanceof EntityArrow) { + b.k.a(entity, new Packet22Collect(entity.g, g)); + } + } + super.c(entity, i); + ap.a(); + } + + public void H() { + if (!au) { + av = -1; + au = true; + b.k.a(this, new Packet18ArmAnimation(this, 1)); + } + } + + public float s() { + return 1.62F; + } + + public void e(Entity entity) { + super.e(entity); + a.b(new Packet39(this, k)); + a.a(p, q, r, v, w); + } + + protected void a(double d1, boolean flag) {} + + public void b(double d1, boolean flag) { + super.a(d1, flag); + } + + public boolean p() { + return al; + } + + private void R() { + bH = bH % 100 + 1; + } + + public void a(int i, int j, int l) { + R(); + a.b(new Packet100(bH, 1, "Crafting", 9)); + ap = new CraftingInventoryWorkbenchCB(an, this.l, i, j, l); + ap.f = bH; + // CraftBukkit: Downcast to make it work. + ap.a((ICrafting)this); + } + + public void a(IInventory iinventory) { + R(); + a.b(new Packet100(bH, 0, iinventory.b(), iinventory.a())); + ap = new CraftingInventoryChestCB(an, iinventory); + ap.f = bH; + // CraftBukkit: Downcast to make it work. + ap.a((ICrafting)this); + } + + public void a(TileEntityFurnace tileentityfurnace) { + R(); + a.b(new Packet100(bH, 2, tileentityfurnace.b(), tileentityfurnace.a())); + ap = new CraftingInventoryFurnaceCB(an, tileentityfurnace); + ap.f = bH; + // CraftBukkit: Downcast to make it work. + ap.a((ICrafting)this); + } + + public void a(CraftingInventoryCB craftinginventorycb, int i, ItemStack itemstack) { + if (craftinginventorycb.a(i) instanceof SlotCrafting) { + return; + } + if (am) { + return; + } else { + a.b(new Packet103(craftinginventorycb.f, i, itemstack)); + return; + } + } + + public void a(CraftingInventoryCB craftinginventorycb, List list) { + a.b(new Packet104(craftinginventorycb.f, list)); + a.b(new Packet103(-1, -1, an.i())); + } + + public void a(CraftingInventoryCB craftinginventorycb, int i, int j) { + a.b(new Packet105(craftinginventorycb.f, i, j)); + } + + public void a(ItemStack itemstack) {} + + public void I() { + a.b(new Packet101(ap.f)); + K(); + } + + public void J() { + if (am) { + return; + } else { + a.b(new Packet103(-1, -1, an.i())); + return; + } + } + + public void K() { + // CraftBukkit: Downcast to make it work. + ap.a((ICrafting)this); + ap = ao; + } +} + diff --git a/src/main/java/net/minecraft/server/IInventory.java b/src/main/java/net/minecraft/server/IInventory.java new file mode 100644 index 0000000000..c573e81924 --- /dev/null +++ b/src/main/java/net/minecraft/server/IInventory.java @@ -0,0 +1,24 @@ +package net.minecraft.server; + + +public interface IInventory { + + public abstract int a(); + + public abstract ItemStack a(int i); + + public abstract ItemStack a(int i, int j); + + public abstract void a(int i, ItemStack itemstack); + + public abstract String b(); + + public abstract int c(); + + public abstract void d(); + + public abstract boolean a_(EntityPlayer entityplayer); + + public abstract ItemStack[] getContents(); // CraftBukkit +} + diff --git a/src/main/java/net/minecraft/server/InventoryCraftResult.java b/src/main/java/net/minecraft/server/InventoryCraftResult.java new file mode 100644 index 0000000000..8d7f8d6dbd --- /dev/null +++ b/src/main/java/net/minecraft/server/InventoryCraftResult.java @@ -0,0 +1,54 @@ +package net.minecraft.server; + + +public class InventoryCraftResult + implements IInventory { + + private ItemStack a[]; + + // CraftBukkit + public ItemStack[] getContents() { + return a; + } + + public InventoryCraftResult() { + a = new ItemStack[1]; + } + + public int a() { + return 1; + } + + public ItemStack a(int i) { + return a[i]; + } + + public String b() { + return "Result"; + } + + public ItemStack a(int i, int j) { + if (a[i] != null) { + ItemStack itemstack = a[i]; + + a[i] = null; + return itemstack; + } else { + return null; + } + } + + public void a(int i, ItemStack itemstack) { + a[i] = itemstack; + } + + public int c() { + return 64; + } + + public void d() {} + + public boolean a_(EntityPlayer entityplayer) { + return true; + } +} diff --git a/src/main/java/net/minecraft/server/InventoryCrafting.java b/src/main/java/net/minecraft/server/InventoryCrafting.java new file mode 100644 index 0000000000..90502d4704 --- /dev/null +++ b/src/main/java/net/minecraft/server/InventoryCrafting.java @@ -0,0 +1,69 @@ +package net.minecraft.server; + + +public class InventoryCrafting + implements IInventory { + + private ItemStack a[]; + private int b; + private CraftingInventoryCB c; + + //CraftBukkit + public ItemStack[] getContents() { + return a; + } + + public InventoryCrafting(CraftingInventoryCB craftinginventorycb, int i, int j) { + b = i * j; + a = new ItemStack[b]; + c = craftinginventorycb; + } + + public int a() { + return b; + } + + public ItemStack a(int i) { + return a[i]; + } + + public String b() { + return "Crafting"; + } + + public ItemStack a(int i, int j) { + if (a[i] != null) { + if (a[i].a <= j) { + ItemStack itemstack = a[i]; + + a[i] = null; + c.a(this); + return itemstack; + } + ItemStack itemstack1 = a[i].a(j); + + if (a[i].a == 0) { + a[i] = null; + } + c.a(this); + return itemstack1; + } else { + return null; + } + } + + public void a(int i, ItemStack itemstack) { + a[i] = itemstack; + c.a(this); + } + + public int c() { + return 64; + } + + public void d() {} + + public boolean a_(EntityPlayer entityplayer) { + return true; + } +} diff --git a/src/main/java/net/minecraft/server/InventoryLargeChest.java b/src/main/java/net/minecraft/server/InventoryLargeChest.java new file mode 100644 index 0000000000..e79d74b58f --- /dev/null +++ b/src/main/java/net/minecraft/server/InventoryLargeChest.java @@ -0,0 +1,71 @@ +package net.minecraft.server; + + +public class InventoryLargeChest + implements IInventory { + + private String a; + private IInventory b; + private IInventory c; + + // CraftBukkit start + public ItemStack[] getContents() { + ItemStack[] result = new ItemStack[a()]; + for (int i = 0; i < result.length; i++) { + result[i] = a(i); + } + return result; + } + // CraftBukkit end + + public InventoryLargeChest(String s, IInventory iinventory, IInventory iinventory1) { + a = s; + b = iinventory; + c = iinventory1; + } + + public int a() { + return b.a() + c.a(); + } + + public String b() { + return a; + } + + public ItemStack a(int i) { + if (i >= b.a()) { + return c.a(i - b.a()); + } else { + return b.a(i); + } + } + + public ItemStack a(int i, int j) { + if (i >= b.a()) { + return c.a(i - b.a(), j); + } else { + return b.a(i, j); + } + } + + public void a(int i, ItemStack itemstack) { + if (i >= b.a()) { + c.a(i - b.a(), itemstack); + } else { + b.a(i, itemstack); + } + } + + public int c() { + return b.c(); + } + + public void d() { + b.d(); + c.d(); + } + + public boolean a_(EntityPlayer entityplayer) { + return b.a_(entityplayer) && c.a_(entityplayer); + } +} diff --git a/src/main/java/net/minecraft/server/InventoryPlayer.java b/src/main/java/net/minecraft/server/InventoryPlayer.java new file mode 100644 index 0000000000..186fa6e9f4 --- /dev/null +++ b/src/main/java/net/minecraft/server/InventoryPlayer.java @@ -0,0 +1,345 @@ +package net.minecraft.server; + + +public class InventoryPlayer + implements IInventory { + + public ItemStack a[]; + public ItemStack b[]; + public int c; + private EntityPlayer e; + private ItemStack f; + public boolean d; + + // CraftBukket start + public ItemStack[] getContents() { + return a; + } + + public ItemStack[] getArmorContents() { + return b; + } + // CraftBukket end + + public InventoryPlayer(EntityPlayer entityplayer) { + a = new ItemStack[36]; + b = new ItemStack[4]; + c = 0; + d = false; + e = entityplayer; + } + + public ItemStack e() { + return a[c]; + } + + private int d(int k) { + for (int l = 0; l < a.length; l++) { + if (a[l] != null && a[l].c == k) { + return l; + } + } + + return -1; + } + + private int e(int k) { + for (int l = 0; l < a.length; l++) { + if (a[l] != null && a[l].c == k && a[l].a < a[l].b() && a[l].a < c()) { + return l; + } + } + + return -1; + } + + private int j() { + for (int k = 0; k < a.length; k++) { + if (a[k] == null) { + return k; + } + } + + return -1; + } + + private int b(int k, int l) { + int i1 = e(k); + + if (i1 < 0) { + i1 = j(); + } + if (i1 < 0) { + return l; + } + if (a[i1] == null) { + a[i1] = new ItemStack(k, 0); + } + int j1 = l; + + if (j1 > a[i1].b() - a[i1].a) { + j1 = a[i1].b() - a[i1].a; + } + if (j1 > c() - a[i1].a) { + j1 = c() - a[i1].a; + } + if (j1 == 0) { + return l; + } else { + l -= j1; + a[i1].a += j1; + a[i1].b = 5; + return l; + } + } + + public void f() { + for (int k = 0; k < a.length; k++) { + if (a[k] != null && a[k].b > 0) { + a[k].b--; + } + } + + } + + public boolean b(int k) { + int l = d(k); + + if (l < 0) { + return false; + } + if (--a[l].a <= 0) { + a[l] = null; + } + return true; + } + + public boolean a(ItemStack itemstack) { + if (itemstack.d == 0) { + itemstack.a = b(itemstack.c, itemstack.a); + if (itemstack.a == 0) { + return true; + } + } + int k = j(); + + if (k >= 0) { + a[k] = itemstack; + a[k].b = 5; + return true; + } else { + return false; + } + } + + public ItemStack a(int k, int l) { + ItemStack aitemstack[] = a; + + if (k >= a.length) { + aitemstack = b; + k -= a.length; + } + if (aitemstack[k] != null) { + if (aitemstack[k].a <= l) { + ItemStack itemstack = aitemstack[k]; + + aitemstack[k] = null; + return itemstack; + } + ItemStack itemstack1 = aitemstack[k].a(l); + + if (aitemstack[k].a == 0) { + aitemstack[k] = null; + } + return itemstack1; + } else { + return null; + } + } + + public void a(int k, ItemStack itemstack) { + ItemStack aitemstack[] = a; + + if (k >= aitemstack.length) { + k -= aitemstack.length; + aitemstack = b; + } + aitemstack[k] = itemstack; + } + + public float a(Block block) { + float f1 = 1.0F; + + if (a[c] != null) { + f1 *= a[c].a(block); + } + return f1; + } + + public NBTTagList a(NBTTagList nbttaglist) { + for (int k = 0; k < a.length; k++) { + if (a[k] != null) { + NBTTagCompound nbttagcompound = new NBTTagCompound(); + + nbttagcompound.a("Slot", (byte) k); + a[k].a(nbttagcompound); + nbttaglist.a(nbttagcompound); + } + } + + for (int l = 0; l < b.length; l++) { + if (b[l] != null) { + NBTTagCompound nbttagcompound1 = new NBTTagCompound(); + + nbttagcompound1.a("Slot", (byte) (l + 100)); + b[l].a(nbttagcompound1); + nbttaglist.a(nbttagcompound1); + } + } + + return nbttaglist; + } + + public void b(NBTTagList nbttaglist) { + a = new ItemStack[36]; + b = new ItemStack[4]; + for (int k = 0; k < nbttaglist.b(); k++) { + NBTTagCompound nbttagcompound = (NBTTagCompound) nbttaglist.a(k); + int l = nbttagcompound.b("Slot") & 0xff; + ItemStack itemstack = new ItemStack(nbttagcompound); + + if (itemstack.a() == null) { + continue; + } + if (l >= 0 && l < a.length) { + a[l] = itemstack; + } + if (l >= 100 && l < b.length + 100) { + b[l - 100] = itemstack; + } + } + + } + + public int a() { + return a.length + 4; + } + + public ItemStack a(int k) { + ItemStack aitemstack[] = a; + + if (k >= aitemstack.length) { + k -= aitemstack.length; + aitemstack = b; + } + return aitemstack[k]; + } + + public String b() { + return "Inventory"; + } + + public int c() { + return 64; + } + + public int a(Entity entity) { + ItemStack itemstack = a(c); + + if (itemstack != null) { + return itemstack.a(entity); + } else { + return 1; + } + } + + public boolean b(Block block) { + if (block.bs != Material.d && block.bs != Material.e && block.bs != Material.t && block.bs != Material.s) { + return true; + } + ItemStack itemstack = a(c); + + if (itemstack != null) { + return itemstack.b(block); + } else { + return false; + } + } + + public int g() { + int k = 0; + int l = 0; + int i1 = 0; + + for (int j1 = 0; j1 < b.length; j1++) { + if (b[j1] != null && (b[j1].a() instanceof ItemArmor)) { + int k1 = b[j1].c(); + int l1 = b[j1].d; + int i2 = k1 - l1; + + l += i2; + i1 += k1; + int j2 = ((ItemArmor) b[j1].a()).bc; + + k += j2; + } + } + + if (i1 == 0) { + return 0; + } else { + return ((k - 1) * l) / i1 + 1; + } + } + + public void c(int k) { + for (int l = 0; l < b.length; l++) { + if (b[l] == null || !(b[l].a() instanceof ItemArmor)) { + continue; + } + b[l].b(k); + if (b[l].a == 0) { + b[l].a(e); + b[l] = null; + } + } + + } + + public void h() { + for (int k = 0; k < a.length; k++) { + if (a[k] != null) { + e.a(a[k], true); + a[k] = null; + } + } + + for (int l = 0; l < b.length; l++) { + if (b[l] != null) { + e.a(b[l], true); + b[l] = null; + } + } + + } + + public void d() { + d = true; + } + + public void b(ItemStack itemstack) { + f = itemstack; + e.a(itemstack); + } + + public ItemStack i() { + return f; + } + + public boolean a_(EntityPlayer entityplayer) { + if (e.G) { + return false; + } + return entityplayer.b((Entity)e) <= 64D; // CraftBukkit: downcast to Entity + } +} diff --git a/src/main/java/net/minecraft/server/ItemBlock.java b/src/main/java/net/minecraft/server/ItemBlock.java new file mode 100644 index 0000000000..72c4f21cf4 --- /dev/null +++ b/src/main/java/net/minecraft/server/ItemBlock.java @@ -0,0 +1,109 @@ +package net.minecraft.server; + +import org.bukkit.BlockFace; +import org.bukkit.craftbukkit.CraftBlock; +import org.bukkit.craftbukkit.CraftItemStack; +import org.bukkit.craftbukkit.CraftPlayer; +import org.bukkit.event.Event.Type; +import org.bukkit.event.block.BlockPlacedEvent; + + +public class ItemBlock extends Item { + + private int a; + + public ItemBlock(int i) { + super(i); + a = i + 256; + a(Block.m[i + 256].a(2)); + } + + public boolean a(ItemStack itemstack, EntityPlayer entityplayer, World world, int i, int j, int k, int l) { + // Craftbukkit start + // Bail if we have nothing of the item in hand + if (itemstack.a == 0) { + return false; + } + + // Craftbukkit store info of the clicked block + CraftBlock blockClicked = (CraftBlock) ((WorldServer) world).getWorld().getBlockAt(i, j, k); + BlockFace faceClicked = CraftBlock.notchToBlockFace(l); + + if (world.a(i, j, k) == Block.aS.bh) { + l = 0; + } else { + if (l == 0) { + j--; + } + if (l == 1) { + j++; + } + if (l == 2) { + k--; + } + if (l == 3) { + k++; + } + if (l == 4) { + i--; + } + if (l == 5) { + i++; + } + } + + // CraftBukkit store the old data so we can undo it + int oldMaterial = world.a(i, j, k); + int oldData = world.b(i, j, k); + + if (world.a(a, i, j, k, false)) { + Block block = Block.m[a]; + + // This executes the placement of the block + if (world.d(i, j, k, a)) { + CraftBlock placedBlock = (CraftBlock) blockClicked.getFace(faceClicked) ; + CraftItemStack itemInHand = new CraftItemStack(itemstack); + CraftPlayer thePlayer = new CraftPlayer(((WorldServer) world).getServer(), (EntityPlayerMP) entityplayer); + + int xFromSpawn = (int) MathHelper.e(i - world.m); + int distanceFromSpawn = (int) MathHelper.e(k - world.o); + + if (xFromSpawn > distanceFromSpawn) { + distanceFromSpawn = xFromSpawn; + } + + // Craftbukkit hardcoded Spawn distance for now + boolean canBuild = distanceFromSpawn > 16 || thePlayer.isOp(); + + BlockPlacedEvent bpe = new BlockPlacedEvent(Type.BLOCK_PLACED, placedBlock, blockClicked, itemInHand, thePlayer, canBuild); + ((WorldServer) world).getServer().getPluginManager().callEvent(bpe); + + if (bpe.isCancelled() || !bpe.canBuild()) { + // Craftbukkit Undo! + + // Specialcase iceblocks, replace with 'glass' first (so it doesn't explode into water) + if (this.a == 79) { + world.a(i, j, k, 20); + } + world.a(i, j, k, oldMaterial); + world.c(i, j, k, oldData); + } else { + world.g(i, j, k); + world.g(i, j, k, this.a); + + Block.m[a].c(world, i, j, k, l); + // Craftbukkit Decompiler doesn't record the downcast. Oops. + Block.m[a].a(world, i, j, k, (EntityLiving) entityplayer); + world.a((float) i + 0.5F, (float) j + 0.5F, (float) k + 0.5F, block.bq.c(), (block.bq.a() + 1.0F) / 2.0F, block.bq.b() * 0.8F); + itemstack.a--; + } + } + } + return true; + } + + public String a() { + return Block.m[a].e(); + } +} + diff --git a/src/main/java/net/minecraft/server/ItemBoat.java b/src/main/java/net/minecraft/server/ItemBoat.java new file mode 100644 index 0000000000..61102abb7f --- /dev/null +++ b/src/main/java/net/minecraft/server/ItemBoat.java @@ -0,0 +1,63 @@ +package net.minecraft.server; + +import org.bukkit.craftbukkit.CraftBlock; +import org.bukkit.craftbukkit.CraftItemStack; +import org.bukkit.craftbukkit.CraftPlayer; +import org.bukkit.event.Event.Type; +import org.bukkit.event.player.PlayerItemEvent; + + +public class ItemBoat extends Item { + + public ItemBoat(int i) { + super(i); + aX = 1; + } + + public ItemStack a(ItemStack itemstack, World world, EntityPlayer entityplayer) { + float f = 1.0F; + float f1 = entityplayer.y + (entityplayer.w - entityplayer.y) * f; + float f2 = entityplayer.x + (entityplayer.v - entityplayer.x) * f; + double d = entityplayer.m + (entityplayer.p - entityplayer.m) * (double) f; + double d1 = (entityplayer.n + (entityplayer.q - entityplayer.n) * (double) f + 1.6200000000000001D) - (double) entityplayer.H; + double d2 = entityplayer.o + (entityplayer.r - entityplayer.o) * (double) f; + Vec3D vec3d = Vec3D.b(d, d1, d2); + float f3 = MathHelper.b(-f2 * 0.01745329F - 3.141593F); + float f4 = MathHelper.a(-f2 * 0.01745329F - 3.141593F); + float f5 = -MathHelper.b(-f1 * 0.01745329F); + float f6 = MathHelper.a(-f1 * 0.01745329F); + float f7 = f4 * f5; + float f8 = f6; + float f9 = f3 * f5; + double d3 = 5D; + Vec3D vec3d1 = vec3d.c((double) f7 * d3, (double) f8 * d3, (double) f9 * d3); + MovingObjectPosition movingobjectposition = world.a(vec3d, vec3d1, true); + + if (movingobjectposition == null) { + return itemstack; + } + if (movingobjectposition.a == 0) { + int i = movingobjectposition.b; + int j = movingobjectposition.c; + int k = movingobjectposition.d; + + if (!world.z) { + // Craftbukkit start + // Boat placement + CraftBlock blockClicked = (CraftBlock) ((WorldServer) world).getWorld().getBlockAt(i, j, k); + CraftItemStack itemInHand = new CraftItemStack(itemstack); + CraftPlayer thePlayer = new CraftPlayer(((WorldServer) world).getServer(), (EntityPlayerMP) entityplayer); + PlayerItemEvent pie = new PlayerItemEvent(Type.PLAYER_ITEM, thePlayer, itemInHand, blockClicked, CraftBlock.notchToBlockFace(movingobjectposition.e)); + + ((WorldServer) world).getServer().getPluginManager().callEvent(pie); + + if (pie.isCancelled()) return itemstack; + + world.a(new EntityBoat(world, (float) i + 0.5F, (float) j + 1.5F, (float) k + 0.5F)); + } + itemstack.a--; + } + return itemstack; + } +} + diff --git a/src/main/java/net/minecraft/server/ItemBucket.java b/src/main/java/net/minecraft/server/ItemBucket.java new file mode 100644 index 0000000000..7fd30540db --- /dev/null +++ b/src/main/java/net/minecraft/server/ItemBucket.java @@ -0,0 +1,133 @@ +package net.minecraft.server; + +import org.bukkit.BlockFace; +import org.bukkit.craftbukkit.CraftBlock; +import org.bukkit.craftbukkit.CraftItemStack; +import org.bukkit.craftbukkit.CraftPlayer; +import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.event.Event.Type; +import org.bukkit.event.player.PlayerItemEvent; + + +public class ItemBucket extends Item { + + private int a; + + public ItemBucket(int i, int j) { + super(i); + aX = 1; + aY = 64; + a = j; + } + + public ItemStack a(ItemStack itemstack, World world, EntityPlayer entityplayer) { + float f = 1.0F; + float f1 = entityplayer.y + (entityplayer.w - entityplayer.y) * f; + float f2 = entityplayer.x + (entityplayer.v - entityplayer.x) * f; + double d = entityplayer.m + (entityplayer.p - entityplayer.m) * (double) f; + double d1 = (entityplayer.n + (entityplayer.q - entityplayer.n) * (double) f + 1.6200000000000001D) - (double) entityplayer.H; + double d2 = entityplayer.o + (entityplayer.r - entityplayer.o) * (double) f; + Vec3D vec3d = Vec3D.b(d, d1, d2); + float f3 = MathHelper.b(-f2 * 0.01745329F - 3.141593F); + float f4 = MathHelper.a(-f2 * 0.01745329F - 3.141593F); + float f5 = -MathHelper.b(-f1 * 0.01745329F); + float f6 = MathHelper.a(-f1 * 0.01745329F); + float f7 = f4 * f5; + float f8 = f6; + float f9 = f3 * f5; + double d3 = 5D; + Vec3D vec3d1 = vec3d.c((double) f7 * d3, (double) f8 * d3, (double) f9 * d3); + MovingObjectPosition movingobjectposition = world.a(vec3d, vec3d1, a == 0); + + if (movingobjectposition == null) { + return itemstack; + } + if (movingobjectposition.a == 0) { + int i = movingobjectposition.b; + int j = movingobjectposition.c; + int k = movingobjectposition.d; + + if (!world.a(entityplayer, i, j, k)) { + return itemstack; + } + + // Craftbukkit start + // Craftbukkit Click == placed when handling an empty bucket! + CraftWorld theWorld = ((WorldServer) world).getWorld(); + CraftBlock blockClicked = (CraftBlock) theWorld.getBlockAt(i, j, k); + BlockFace direction = CraftBlock.notchToBlockFace(movingobjectposition.e); + CraftPlayer thePlayer = new CraftPlayer(((WorldServer) world).getServer(), (EntityPlayerMP) entityplayer); + CraftItemStack itemInHand = new CraftItemStack(itemstack); + + if (a == 0) { + if (world.c(i, j, k) == Material.f && world.b(i, j, k) == 0) { + PlayerItemEvent pie = new PlayerItemEvent(Type.PLAYER_ITEM, thePlayer, itemInHand, blockClicked, direction); + ((WorldServer) world).getServer().getPluginManager().callEvent(pie); + + if (!pie.isCancelled()) { + world.d(i, j, k, 0); + return new ItemStack(Item.av); + } else { + return itemstack; + } + } + if (world.c(i, j, k) == Material.g && world.b(i, j, k) == 0) { + PlayerItemEvent pie = new PlayerItemEvent(Type.PLAYER_ITEM, thePlayer, itemInHand, blockClicked, direction); + ((WorldServer) world).getServer().getPluginManager().callEvent(pie); + + if (!pie.isCancelled()) { + world.d(i, j, k, 0); + return new ItemStack(Item.aw); + } else { + return itemstack; + } + } + } else { + if (a < 0) { + return new ItemStack(Item.au); + } + if (movingobjectposition.e == 0) { + j--; + } + if (movingobjectposition.e == 1) { + j++; + } + if (movingobjectposition.e == 2) { + k--; + } + if (movingobjectposition.e == 3) { + k++; + } + if (movingobjectposition.e == 4) { + i--; + } + if (movingobjectposition.e == 5) { + i++; + } + if (world.e(i, j, k) || !world.c(i, j, k).a()) { + if (world.q.d && a == Block.A.bh) { + world.a(d + 0.5D, d1 + 0.5D, d2 + 0.5D, "random.fizz", 0.5F, 2.6F + (world.l.nextFloat() - world.l.nextFloat()) * 0.8F); + for (int l = 0; l < 8; l++) { + world.a("largesmoke", (double) i + Math.random(), (double) j + Math.random(), (double) k + Math.random(), 0.0D, 0.0D, 0.0D); + } + } else { + // Craftbukkit bucket empty. + PlayerItemEvent pie = new PlayerItemEvent(Type.PLAYER_ITEM, thePlayer, itemInHand, blockClicked, direction); + ((WorldServer) world).getServer().getPluginManager().callEvent(pie); + + if (!pie.isCancelled()) { + world.b(i, j, k, a, 0); + } else { + return itemstack; + } + } + return new ItemStack(Item.au); + } + } + } else if (a == 0 && (movingobjectposition.g instanceof EntityCow)) { + return new ItemStack(Item.aE); + } + return itemstack; + } +} + diff --git a/src/main/java/net/minecraft/server/ItemFlintAndSteel.java b/src/main/java/net/minecraft/server/ItemFlintAndSteel.java new file mode 100644 index 0000000000..5a2f9d430b --- /dev/null +++ b/src/main/java/net/minecraft/server/ItemFlintAndSteel.java @@ -0,0 +1,65 @@ +package net.minecraft.server; + +import org.bukkit.craftbukkit.CraftBlock; +import org.bukkit.craftbukkit.CraftItemStack; +import org.bukkit.craftbukkit.CraftPlayer; +import org.bukkit.event.Event.Type; +import org.bukkit.event.player.PlayerItemEvent; + + +public class ItemFlintAndSteel extends Item { + + public ItemFlintAndSteel(int i) { + super(i); + aX = 1; + aY = 64; + } + + public boolean a(ItemStack itemstack, EntityPlayer entityplayer, World world, int i, int j, int k, int l) { + // Craftbukkit start - get the clicked block + CraftBlock blockClicked = (CraftBlock) ((WorldServer) world).getWorld().getBlockAt(i, j, k); + + if (l == 0) { + j--; + } + if (l == 1) { + j++; + } + if (l == 2) { + k--; + } + if (l == 3) { + k++; + } + if (l == 4) { + i--; + } + if (l == 5) { + i++; + } + int i1 = world.a(i, j, k); + + if (i1 == 0) { + // Craftbukkit start + // Flint and steel + + CraftItemStack itemInHand = new CraftItemStack(itemstack); + CraftPlayer thePlayer = new CraftPlayer(((WorldServer) world).getServer(), (EntityPlayerMP) entityplayer); + PlayerItemEvent pie = new PlayerItemEvent(Type.PLAYER_ITEM, thePlayer, itemInHand, blockClicked, CraftBlock.notchToBlockFace(l)); + + ((WorldServer) world).getServer().getPluginManager().callEvent(pie); + + boolean preventLighter = pie.isCancelled(); + + if (preventLighter) { + return false; + } else { + world.a((double) i + 0.5D, (double) j + 0.5D, (double) k + 0.5D, "fire.ignite", 1.0F, b.nextFloat() * 0.4F + 0.8F); + world.d(i, j, k, Block.ar.bh); + } + } + itemstack.b(1); + return true; + } +} + diff --git a/src/main/java/net/minecraft/server/ItemHoe.java b/src/main/java/net/minecraft/server/ItemHoe.java new file mode 100644 index 0000000000..4002370fc8 --- /dev/null +++ b/src/main/java/net/minecraft/server/ItemHoe.java @@ -0,0 +1,63 @@ +package net.minecraft.server; + +import org.bukkit.craftbukkit.CraftBlock; +import org.bukkit.craftbukkit.CraftItemStack; +import org.bukkit.craftbukkit.CraftPlayer; +import org.bukkit.event.Event.Type; +import org.bukkit.event.player.PlayerItemEvent; + + +public class ItemHoe extends Item { + + public ItemHoe(int i, int j) { + super(i); + aX = 1; + aY = 32 << j; + } + + public boolean a(ItemStack itemstack, EntityPlayer entityplayer, World world, int i, int j, int k, int l) { + int i1 = world.a(i, j, k); + Material material = world.c(i, j + 1, k); + + if (!material.a() && i1 == Block.u.bh || i1 == Block.v.bh) { + // Craftbukkit start + // Hoes + CraftBlock blockClicked = (CraftBlock) ((WorldServer) world).getWorld().getBlockAt(i, j, k); + CraftItemStack itemInHand = new CraftItemStack(itemstack); + CraftPlayer thePlayer = new CraftPlayer(((WorldServer) world).getServer(), (EntityPlayerMP) entityplayer); + PlayerItemEvent pie = new PlayerItemEvent(Type.PLAYER_ITEM, thePlayer, itemInHand, blockClicked, CraftBlock.notchToBlockFace(l)); + + ((WorldServer) world).getServer().getPluginManager().callEvent(pie); + + if (pie.isCancelled()) return false; + + Block block = Block.aA; + + world.a((float) i + 0.5F, (float) j + 0.5F, (float) k + 0.5F, block.bq.c(), (block.bq.a() + 1.0F) / 2.0F, block.bq.b() * 0.8F); + if (world.z) { + return true; + } + world.d(i, j, k, block.bh); + itemstack.b(1); + if (world.l.nextInt(8) == 0 && i1 == Block.u.bh) { + int j1 = 1; + + for (int k1 = 0; k1 < j1; k1++) { + float f = 0.7F; + float f1 = world.l.nextFloat() * f + (1.0F - f) * 0.5F; + float f2 = 1.2F; + float f3 = world.l.nextFloat() * f + (1.0F - f) * 0.5F; + EntityItem entityitem = new EntityItem(world, (float) i + f1, (float) j + f2, (float) k + f3, new ItemStack(Item.Q)); + + entityitem.c = 10; + world.a(entityitem); + } + + } + return true; + } else { + return false; + } + } +} + diff --git a/src/main/java/net/minecraft/server/ItemMinecart.java b/src/main/java/net/minecraft/server/ItemMinecart.java new file mode 100644 index 0000000000..dfbd443b65 --- /dev/null +++ b/src/main/java/net/minecraft/server/ItemMinecart.java @@ -0,0 +1,45 @@ +package net.minecraft.server; + +import org.bukkit.craftbukkit.CraftBlock; +import org.bukkit.craftbukkit.CraftItemStack; +import org.bukkit.craftbukkit.CraftPlayer; +import org.bukkit.event.Event.Type; +import org.bukkit.event.player.PlayerItemEvent; + + +public class ItemMinecart extends Item { + + public int a; + + public ItemMinecart(int i, int j) { + super(i); + aX = 1; + a = j; + } + + public boolean a(ItemStack itemstack, EntityPlayer entityplayer, World world, int i, int j, int k, int l) { + int i1 = world.a(i, j, k); + + if (i1 == Block.aG.bh) { + // Craftbukkit start + // Minecarts + CraftBlock blockClicked = (CraftBlock) ((WorldServer) world).getWorld().getBlockAt(i, j, k); + CraftItemStack itemInHand = new CraftItemStack(itemstack); + CraftPlayer thePlayer = new CraftPlayer(((WorldServer) world).getServer(), (EntityPlayerMP) entityplayer); + PlayerItemEvent pie = new PlayerItemEvent(Type.PLAYER_ITEM, thePlayer, itemInHand, blockClicked, CraftBlock.notchToBlockFace(l)); + + ((WorldServer) world).getServer().getPluginManager().callEvent(pie); + + if (pie.isCancelled()) return false; + + if (!world.z) { + world.a(new EntityMinecart(world, (float) i + 0.5F, (float) j + 0.5F, (float) k + 0.5F, a)); + } + itemstack.a--; + return true; + } else { + return false; + } + } +} + diff --git a/src/main/java/net/minecraft/server/ItemRedstone.java b/src/main/java/net/minecraft/server/ItemRedstone.java new file mode 100644 index 0000000000..f983fd1b76 --- /dev/null +++ b/src/main/java/net/minecraft/server/ItemRedstone.java @@ -0,0 +1,58 @@ +package net.minecraft.server; + +import org.bukkit.craftbukkit.CraftBlock; +import org.bukkit.craftbukkit.CraftItemStack; +import org.bukkit.craftbukkit.CraftPlayer; +import org.bukkit.event.Event.Type; +import org.bukkit.event.player.PlayerItemEvent; + + +public class ItemRedstone extends Item { + + public ItemRedstone(int i) { + super(i); + } + + public boolean a(ItemStack itemstack, EntityPlayer entityplayer, World world, int i, int j, int k, int l) { + // Craftbukkit start get the clicked block + CraftBlock blockClicked = (CraftBlock) ((WorldServer) world).getWorld().getBlockAt(i, j, k); + + if (l == 0) { + j--; + } + if (l == 1) { + j++; + } + if (l == 2) { + k--; + } + if (l == 3) { + k++; + } + if (l == 4) { + i--; + } + if (l == 5) { + i++; + } + if (!world.e(i, j, k)) { + return false; + } + if (Block.av.a(world, i, j, k)) { + // Craftbukkit start + // Redstone + CraftItemStack itemInHand = new CraftItemStack(itemstack); + CraftPlayer thePlayer = new CraftPlayer(((WorldServer) world).getServer(), (EntityPlayerMP) entityplayer); + PlayerItemEvent pie = new PlayerItemEvent(Type.PLAYER_ITEM, thePlayer, itemInHand, blockClicked, CraftBlock.notchToBlockFace(l)); + + ((WorldServer) world).getServer().getPluginManager().callEvent(pie); + + if (pie.isCancelled()) return false; + + itemstack.a--; + world.d(i, j, k, Block.av.bh); + } + return true; + } +} + diff --git a/src/main/java/net/minecraft/server/ItemSeeds.java b/src/main/java/net/minecraft/server/ItemSeeds.java new file mode 100644 index 0000000000..ea47512551 --- /dev/null +++ b/src/main/java/net/minecraft/server/ItemSeeds.java @@ -0,0 +1,47 @@ +package net.minecraft.server; + +import org.bukkit.craftbukkit.CraftBlock; +import org.bukkit.craftbukkit.CraftItemStack; +import org.bukkit.craftbukkit.CraftPlayer; +import org.bukkit.event.Event.Type; +import org.bukkit.event.player.PlayerItemEvent; + + +public class ItemSeeds extends Item { + + private int a; + + public ItemSeeds(int i, int j) { + super(i); + a = j; + } + + public boolean a(ItemStack itemstack, EntityPlayer entityplayer, World world, int i, int j, int k, int l) { + if (l != 1) { + return false; + } + int i1 = world.a(i, j, k); + + if (i1 == Block.aA.bh) { + // Craftbukkit start + // Seeds + CraftBlock blockClicked = (CraftBlock) ((WorldServer) world).getWorld().getBlockAt(i, j, k); + CraftItemStack itemInHand = new CraftItemStack(itemstack); + CraftPlayer thePlayer = new CraftPlayer(((WorldServer) world).getServer(), (EntityPlayerMP) entityplayer); + PlayerItemEvent pie = new PlayerItemEvent(Type.PLAYER_ITEM, thePlayer, itemInHand, blockClicked, CraftBlock.notchToBlockFace(l)); + + ((WorldServer) world).getServer().getPluginManager().callEvent(pie); + + if (!pie.isCancelled()) { + world.d(i, j + 1, k, a); + itemstack.a--; + return true; + } else { + return false; + } + } else { + return false; + } + } +} + diff --git a/src/main/java/net/minecraft/server/ItemSign.java b/src/main/java/net/minecraft/server/ItemSign.java new file mode 100644 index 0000000000..c7f949eadd --- /dev/null +++ b/src/main/java/net/minecraft/server/ItemSign.java @@ -0,0 +1,72 @@ +package net.minecraft.server; + +import org.bukkit.craftbukkit.CraftBlock; +import org.bukkit.craftbukkit.CraftItemStack; +import org.bukkit.craftbukkit.CraftPlayer; +import org.bukkit.event.Event.Type; +import org.bukkit.event.player.PlayerItemEvent; + + +public class ItemSign extends Item { + + public ItemSign(int i) { + super(i); + aY = 64; + aX = 1; + } + + public boolean a(ItemStack itemstack, EntityPlayer entityplayer, World world, int i, int j, int k, int l) { + if (l == 0) { + return false; + } + if (!world.c(i, j, k).a()) { + return false; + } + + // Craftbukkit - store the clicked block + CraftBlock blockClicked = (CraftBlock) ((WorldServer) world).getWorld().getBlockAt(i, j, k); + + if (l == 1) { + j++; + } + if (l == 2) { + k--; + } + if (l == 3) { + k++; + } + if (l == 4) { + i--; + } + if (l == 5) { + i++; + } + if (!Block.aD.a(world, i, j, k)) { + return false; + } + + // Craftbukkit start + // Signs + CraftItemStack itemInHand = new CraftItemStack(itemstack); + CraftPlayer thePlayer = new CraftPlayer(((WorldServer) world).getServer(), (EntityPlayerMP) entityplayer); + PlayerItemEvent pie = new PlayerItemEvent(Type.PLAYER_ITEM, thePlayer, itemInHand, blockClicked, CraftBlock.notchToBlockFace(l)); + + ((WorldServer) world).getServer().getPluginManager().callEvent(pie); + + if (pie.isCancelled()) return false; + + if (l == 1) { + world.b(i, j, k, Block.aD.bh, MathHelper.b((double) (((entityplayer.v + 180F) * 16F) / 360F) + 0.5D) & 0xf); + } else { + world.b(i, j, k, Block.aI.bh, l); + } + itemstack.a--; + TileEntitySign tileentitysign = (TileEntitySign) world.l(i, j, k); + + if (tileentitysign != null) { + entityplayer.a(tileentitysign); + } + return true; + } +} + diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java index c3b2568cf4..b54a1d4c34 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -136,6 +136,8 @@ implements ICommandListener, Runnable { private void e() { i = null; j = 0; + + server.loadPlugins(); } private void f() { diff --git a/src/main/java/net/minecraft/server/NetServerHandler.java b/src/main/java/net/minecraft/server/NetServerHandler.java index 2fd1c49f78..fb97d21172 100644 --- a/src/main/java/net/minecraft/server/NetServerHandler.java +++ b/src/main/java/net/minecraft/server/NetServerHandler.java @@ -2,12 +2,17 @@ package net.minecraft.server; import java.util.*; import java.util.logging.Logger; + +import org.bukkit.BlockFace; import org.bukkit.Location; import org.bukkit.craftbukkit.CraftBlock; +import org.bukkit.craftbukkit.CraftItemStack; import org.bukkit.craftbukkit.CraftPlayer; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.event.Event.Type; +import org.bukkit.event.block.BlockRightClickedEvent; import org.bukkit.event.player.PlayerChatEvent; +import org.bukkit.event.player.PlayerItemEvent; import org.bukkit.event.player.PlayerMoveEvent; @@ -290,43 +295,74 @@ implements ICommandListener { d.e.B = false; } - // Craftbukkit start + // Craftbukkit start - store the last block right clicked and what type it was CraftBlock lastRightClicked; - // Craftbukkit stop - + int lastMaterial; + public void a(Packet15Place packet15place) { ItemStack itemstack = e.an.e(); - boolean flag = d.e.B = d.f.g(e.aw); - - // Craftbukkit start + // Craftbukkit we don't check spawn protection here anymore + /* boolean flag = */d.e.B = d.f.g(e.aw); + CraftBlock blockClicked = null; - CraftBlock blockPlaced = null; + BlockFace blockFace = null; if (packet15place.d == 255) { - // ITEM_USE -- if we have a lastRightClicked then it could be a usable location - blockClicked = lastRightClicked; + // Craftbukkit ITEM_USE -- if we have a lastRightClicked then it could be a usable location + if (packet15place.e != null && packet15place.e.c == lastMaterial) { + blockClicked = lastRightClicked; + } else if (lastMaterial == 0) { + blockClicked = lastRightClicked; + } lastRightClicked = null; + lastMaterial = 0; } else { - // RIGHTCLICK or BLOCK_PLACE .. or nothing + // Craftbukkit RIGHTCLICK or BLOCK_PLACE .. or nothing blockClicked = (CraftBlock) d.e.getWorld().getBlockAt(packet15place.a, packet15place.b, packet15place.c); - // TODO: we don't have "faceclicked" concept in bukkit - // blockClicked.setFaceClicked(Block.Face.fromId(paramgt.d)); lastRightClicked = blockClicked; + lastMaterial = (packet15place.e == null) ? 0 : packet15place.e.c; } - - // If we clicked on something then we also have a location to place the block + if (blockClicked != null && itemstack != null) { - blockPlaced = (CraftBlock) blockClicked.getFace(CraftBlock.notchToBlockFace(packet15place.d)); - // TODO: in hMod we've set the new type already. We haven't yet here. - // blockPlaced = new Block( localil.c, blockClicked.getX(), blockClicked.getY(), blockClicked.getZ()); + blockFace = CraftBlock.notchToBlockFace(packet15place.d); + } else { + blockFace = BlockFace.Self; } - // Craftbukkit stop + + // Craftbukkit if rightclick decremented the item, always send the update packet. + // this is not here for Craftbukkit's own functionality; rather it is to fix + // a notch bug where the item doesn't update correctly. + boolean always = false; if (packet15place.d == 255) { if (itemstack == null) { return; } - e.c.a(e, d.e, itemstack); + + CraftItemStack craftItem = new CraftItemStack(itemstack); + CraftPlayer player = new CraftPlayer(server, e); + PlayerItemEvent pie = new PlayerItemEvent(Type.PLAYER_ITEM, player, craftItem, blockClicked, blockFace); + + // Craftbukkit We still call this event even in spawn protection. + // Don't call this event if using Buckets / signs + switch (craftItem.getType()) { + case Sign: + case Bucket: + case WaterBucket: + case LavaBucket: + break; + default: + server.getPluginManager().callEvent(pie); + } + + if (!pie.isCancelled()) { + int itemstackAmount = itemstack.a; + e.c.a(e, d.e, itemstack); + // Craftbukkit notch decrements the counter by 1 in the above method with food, + // snowballs and so forth, but he does it in a place that doesnt cause the + // inventory update packet to get sent + always = (itemstack.a != itemstackAmount); + } } else { int l = packet15place.a; int i1 = packet15place.b; @@ -338,9 +374,18 @@ implements ICommandListener { if (l1 > i2) { i2 = l1; } - if (i2 > 16 || flag) { - e.c.a(e, d.e, itemstack, l, i1, j1, k1); - } + + // Craftbukkit start + CraftItemStack craftItem = new CraftItemStack(itemstack); + CraftPlayer player = new CraftPlayer(server, e); +// boolean canBuild = (i2 > 16) || flag; + BlockRightClickedEvent brce = new BlockRightClickedEvent(Type.BLOCK_RIGHTCLICKED, blockClicked, blockFace, craftItem, player); + server.getPluginManager().callEvent(brce); + + // Craftbukkit WE HAVE MOVED THE SPAWN PROTECTION CHECK DOWN INTO CLASS ItemBlock!!! + e.c.a(e, d.e, itemstack, l, i1, j1, k1); + + // These are the response packets back to the client e.a.b(new Packet53BlockChange(l, i1, j1, d.e)); if (k1 == 0) { i1--; @@ -371,12 +416,12 @@ implements ICommandListener { e.ap.a(); e.am = false; - if (!ItemStack.a(e.an.e(), packet15place.e)) { + if (always || !ItemStack.a(e.an.e(), packet15place.e)) { b(new Packet103(e.ap.f, slot.c, e.an.e())); } d.e.B = false; } - + public void a(String s, Object aobj[]) { a.info((new StringBuilder()).append(e.aw).append(" lost connection: ").append(s).toString()); d.f.a(new Packet3Chat((new StringBuilder()).append("\247e").append(e.aw).append(" left the game.").toString())); @@ -418,7 +463,7 @@ implements ICommandListener { // CraftBukkit start PlayerChatEvent event = new PlayerChatEvent(Type.PLAYER_CHAT, player, s); server.getPluginManager().callEvent(event); - s = (new StringBuilder()).append("<").append(event.getPlayer().getName()).append("> ").append(event.getMessage()).toString(); + s = String.format(event.getFormat(), event.getPlayer().getDisplayName(), event.getMessage()); if (event.isCancelled()) return; // CraftBukkit stop diff --git a/src/main/java/net/minecraft/server/Slot.java b/src/main/java/net/minecraft/server/Slot.java new file mode 100644 index 0000000000..63234dd4af --- /dev/null +++ b/src/main/java/net/minecraft/server/Slot.java @@ -0,0 +1,51 @@ +package net.minecraft.server; + + +public class Slot { + + public final int a; // CraftBukkit: private -> public + public final IInventory b; // CraftBukkit: private -> public + public int c; + public int d; + public int e; + + public Slot(IInventory iinventory, int i, int j, int k) { + b = iinventory; + a = i; + d = j; + e = k; + } + + public void b() { + d(); + } + + public boolean a(ItemStack itemstack) { + return true; + } + + public ItemStack c() { + return b.a(a); + } + + public void b(ItemStack itemstack) { + b.a(a, itemstack); + d(); + } + + public void d() { + b.d(); + } + + public int a() { + return b.c(); + } + + public ItemStack a(int i) { + return b.a(a, i); + } + + public boolean a(IInventory iinventory, int i) { + return iinventory == b && i == a; + } +} diff --git a/src/main/java/net/minecraft/server/TileEntityChest.java b/src/main/java/net/minecraft/server/TileEntityChest.java new file mode 100644 index 0000000000..cc5e7f81b8 --- /dev/null +++ b/src/main/java/net/minecraft/server/TileEntityChest.java @@ -0,0 +1,103 @@ +package net.minecraft.server; + + +public class TileEntityChest extends TileEntity + implements IInventory { + + private ItemStack e[]; + + // CraftBukkit start + public ItemStack[] getContents() { + return e; + } + // CraftBukkit end + + public TileEntityChest() { + e = new ItemStack[36]; + } + + public int a() { + return 27; + } + + public ItemStack a(int i) { + return e[i]; + } + + public ItemStack a(int i, int j) { + if (e[i] != null) { + if (e[i].a <= j) { + ItemStack itemstack = e[i]; + + e[i] = null; + d(); + return itemstack; + } + ItemStack itemstack1 = e[i].a(j); + + if (e[i].a == 0) { + e[i] = null; + } + d(); + return itemstack1; + } else { + return null; + } + } + + public void a(int i, ItemStack itemstack) { + e[i] = itemstack; + if (itemstack != null && itemstack.a > c()) { + itemstack.a = c(); + } + d(); + } + + public String b() { + return "Chest"; + } + + public void a(NBTTagCompound nbttagcompound) { + super.a(nbttagcompound); + NBTTagList nbttaglist = nbttagcompound.k("Items"); + + e = new ItemStack[a()]; + for (int i = 0; i < nbttaglist.b(); i++) { + NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.a(i); + int j = nbttagcompound1.b("Slot") & 0xff; + + if (j >= 0 && j < e.length) { + e[j] = new ItemStack(nbttagcompound1); + } + } + + } + + public void b(NBTTagCompound nbttagcompound) { + super.b(nbttagcompound); + NBTTagList nbttaglist = new NBTTagList(); + + for (int i = 0; i < e.length; i++) { + if (e[i] != null) { + NBTTagCompound nbttagcompound1 = new NBTTagCompound(); + + nbttagcompound1.a("Slot", (byte) i); + e[i].a(nbttagcompound1); + nbttaglist.a(nbttagcompound1); + } + } + + nbttagcompound.a("Items", nbttaglist); + } + + public int c() { + return 64; + } + + public boolean a_(EntityPlayer entityplayer) { + if (a.l(b, c, d) != this) { + return false; + } + return entityplayer.d((double) b + 0.5D, (double) c + 0.5D, (double) d + 0.5D) <= 64D; + } +} diff --git a/src/main/java/net/minecraft/server/TileEntityFurnace.java b/src/main/java/net/minecraft/server/TileEntityFurnace.java new file mode 100644 index 0000000000..ff266f7cf0 --- /dev/null +++ b/src/main/java/net/minecraft/server/TileEntityFurnace.java @@ -0,0 +1,240 @@ +package net.minecraft.server; + + +public class TileEntityFurnace extends TileEntity + implements IInventory { + + private ItemStack h[]; + public int e; + public int f; + public int g; + + // CraftBukkit start + public ItemStack[] getContents() { + return h; + } + // CraftBukkit end + + public TileEntityFurnace() { + h = new ItemStack[3]; + e = 0; + f = 0; + g = 0; + } + + public int a() { + return h.length; + } + + public ItemStack a(int j) { + return h[j]; + } + + public ItemStack a(int j, int k) { + if (h[j] != null) { + if (h[j].a <= k) { + ItemStack itemstack = h[j]; + + h[j] = null; + return itemstack; + } + ItemStack itemstack1 = h[j].a(k); + + if (h[j].a == 0) { + h[j] = null; + } + return itemstack1; + } else { + return null; + } + } + + public void a(int j, ItemStack itemstack) { + h[j] = itemstack; + if (itemstack != null && itemstack.a > c()) { + itemstack.a = c(); + } + } + + public String b() { + return "Furnace"; + } + + public void a(NBTTagCompound nbttagcompound) { + super.a(nbttagcompound); + NBTTagList nbttaglist = nbttagcompound.k("Items"); + + h = new ItemStack[a()]; + for (int j = 0; j < nbttaglist.b(); j++) { + NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.a(j); + byte byte0 = nbttagcompound1.b("Slot"); + + if (byte0 >= 0 && byte0 < h.length) { + h[byte0] = new ItemStack(nbttagcompound1); + } + } + + e = nbttagcompound.c("BurnTime"); + g = nbttagcompound.c("CookTime"); + f = a(h[1]); + } + + public void b(NBTTagCompound nbttagcompound) { + super.b(nbttagcompound); + nbttagcompound.a("BurnTime", (short) e); + nbttagcompound.a("CookTime", (short) g); + NBTTagList nbttaglist = new NBTTagList(); + + for (int j = 0; j < h.length; j++) { + if (h[j] != null) { + NBTTagCompound nbttagcompound1 = new NBTTagCompound(); + + nbttagcompound1.a("Slot", (byte) j); + h[j].a(nbttagcompound1); + nbttaglist.a(nbttagcompound1); + } + } + + nbttagcompound.a("Items", nbttaglist); + } + + public int c() { + return 64; + } + + public boolean g() { + return e > 0; + } + + public void e() { + boolean flag = e > 0; + boolean flag1 = false; + + if (e > 0) { + e--; + } + if (!a.z) { + if (e == 0 && i()) { + f = e = a(h[1]); + if (e > 0) { + flag1 = true; + if (h[1] != null) { + h[1].a--; + if (h[1].a == 0) { + h[1] = null; + } + } + } + } + if (g() && i()) { + g++; + if (g == 200) { + g = 0; + h(); + flag1 = true; + } + } else { + g = 0; + } + if (flag != (e > 0)) { + flag1 = true; + BlockFurnace.a(e > 0, a, b, c, d); + } + } + if (flag1) { + d(); + } + } + + private boolean i() { + if (h[0] == null) { + return false; + } + int j = b(h[0].a().aW); + + if (j < 0) { + return false; + } + if (h[2] == null) { + return true; + } + if (h[2].c != j) { + return false; + } + if (h[2].a < c() && h[2].a < h[2].b()) { + return true; + } + return h[2].a < Item.c[j].b(); + } + + public void h() { + if (!i()) { + return; + } + int j = b(h[0].a().aW); + + if (h[2] == null) { + h[2] = new ItemStack(j, 1); + } else if (h[2].c == j) { + h[2].a++; + } + h[0].a--; + if (h[0].a <= 0) { + h[0] = null; + } + } + + private int b(int j) { + if (j == Block.H.bh) { + return Item.m.aW; + } + if (j == Block.G.bh) { + return Item.n.aW; + } + if (j == Block.aw.bh) { + return Item.l.aW; + } + if (j == Block.E.bh) { + return Block.M.bh; + } + if (j == Item.ao.aW) { + return Item.ap.aW; + } + if (j == Item.aS.aW) { + return Item.aT.aW; + } + if (j == Block.w.bh) { + return Block.t.bh; + } + if (j == Item.aG.aW) { + return Item.aF.aW; + } else { + return -1; + } + } + + private int a(ItemStack itemstack) { + if (itemstack == null) { + return 0; + } + int j = itemstack.a().aW; + + if (j < 256 && Block.m[j].bs == Material.c) { + return 300; + } + if (j == Item.B.aW) { + return 100; + } + if (j == Item.k.aW) { + return 1600; + } + return j != Item.aw.aW ? 0 : 20000; + } + + public boolean a_(EntityPlayer entityplayer) { + if (a.l(b, c, d) != this) { + return false; + } + return entityplayer.d((double) b + 0.5D, (double) c + 0.5D, (double) d + 0.5D) <= 64D; + } +} diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java index 11d3561c55..47af8d8b80 100644 --- a/src/main/java/net/minecraft/server/WorldServer.java +++ b/src/main/java/net/minecraft/server/WorldServer.java @@ -36,17 +36,23 @@ public class WorldServer extends World { @Override public boolean c(int i1, int j1, int k1, int l1) { boolean result = super.c(i1, j1, k1, l1); - if (world != null) world.updateBlock(i1, j1, k1); + if ((result) && (world != null)) world.updateBlock(i1, j1, k1); return result; } @Override - public boolean d(int i1, int j1, int k1, int l1) { - boolean result = super.d(i1, j1, k1, l1); - if (world != null) world.updateBlock(i1, j1, k1); + public boolean a(int i1, int j1, int k1, int l1) { + boolean result = super.a(i1, j1, k1, l1); + if ((result) && (world != null)) world.updateBlock(i1, j1, k1); return result; } + @Override + public void a(int i1, int j1, int k1, TileEntity tileentity) { + super.a(i1, j1, k1, tileentity); + if (world != null) world.updateBlock(i1, j1, k1); + } + public CraftWorld getWorld() { return world; } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/CraftBlock.java index 19dce3c70e..64b13a4fe3 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftBlock.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftBlock.java @@ -1,7 +1,11 @@ package org.bukkit.craftbukkit; +import net.minecraft.server.MobSpawnerBase; import org.bukkit.*; +import org.bukkit.block.BlockState; +import org.bukkit.craftbukkit.block.CraftBlockState; +import org.bukkit.craftbukkit.block.CraftSign; public class CraftBlock implements Block { private final CraftWorld world; @@ -113,10 +117,11 @@ public class CraftBlock implements Block { * Sets the type-ID of this block * * @param type Type-ID to change this block to + * @return whether the block was changed */ - public void setTypeID(final int type) { + public boolean setTypeID(final int type) { this.type = type; - world.getHandle().d(x, y, z, type); + return world.getHandle().d(x, y, z, type); } /** @@ -153,7 +158,27 @@ public class CraftBlock implements Block { * @return Block at the given face */ public Block getFace(final BlockFace face) { - return getRelative(face.getModX(), face.getModY(), face.getModZ()); + return getFace(face, 1); + } + + /** + * Gets the block at the given distance of the given face
+ *
+ * For example, the following method places water at 100,102,100; two blocks + * above 100,100,100. + *
+     * Block block = world.getBlockAt(100,100,100);
+     * Block shower = block.getFace(BlockFace.Up, 2);
+     * shower.setType(Material.WATER);
+     * 
+ * + * @param face Face of this block to return + * @param distance Distance to get the block at + * @return Block at the given face + */ + public Block getFace(final BlockFace face, final int distance) { + return getRelative(face.getModX() * distance, face.getModY() * distance, + face.getModZ() * distance); } /** @@ -168,6 +193,38 @@ public class CraftBlock implements Block { return getWorld().getBlockAt(getX() + modX, getY() + modY, getZ() + modZ); } + /** + * Gets the face relation of this block compared to the given block
+ *
+ * For example: + *
+     * Block current = world.getBlockAt(100, 100, 100);
+     * Block target = world.getBlockAt(100, 101, 100);
+     *
+     * current.getFace(target) == BlockFace.Up;
+     * 
+ *
+ * If the given block is not connected to this block, null may be returned + * + * @param block Block to compare against this block + * @return BlockFace of this block which has the requested block, or null + */ + public BlockFace getFace(final Block block) { + BlockFace[] values = BlockFace.values(); + + for (BlockFace face : values) { + if ( + (this.getX() + face.getModX() == block.getX()) && + (this.getY() + face.getModY() == block.getY()) && + (this.getZ() + face.getModZ() == block.getZ()) + ) { + return face; + } + } + + return null; + } + @Override public String toString() { return "CraftBlock{" + "world=" + world + "x=" + x + "y=" + y + "z=" + z + "type=" + type + "data=" + data + '}'; @@ -197,4 +254,50 @@ public class CraftBlock implements Block { return BlockFace.Self; } } + + public BlockState getState() { + Material material = getType(); + + switch (material) { + case Sign: + case SignPost: + case WallSign: + return new CraftSign(this); + default: + return new CraftBlockState(this); + } + } + + public Biome getBiome() { + // TODO: This may not be 100% accurate; investigate into getting per-block instead of per-chunk + MobSpawnerBase base = world.getHandle().a().a(chunk.getX(), chunk.getZ()); + + if (base == MobSpawnerBase.a) { + return Biome.RAINFOREST; + } else if (base == MobSpawnerBase.b) { + return Biome.SWAMPLAND; + } else if (base == MobSpawnerBase.c) { + return Biome.SEASONAL_FOREST; + } else if (base == MobSpawnerBase.d) { + return Biome.FOREST; + } else if (base == MobSpawnerBase.e) { + return Biome.SAVANNA; + } else if (base == MobSpawnerBase.f) { + return Biome.SHRUBLAND; + } else if (base == MobSpawnerBase.g) { + return Biome.TAIGA; + } else if (base == MobSpawnerBase.h) { + return Biome.DESERT; + } else if (base == MobSpawnerBase.i) { + return Biome.PLAINS; + } else if (base == MobSpawnerBase.j) { + return Biome.ICE_DESERT; + } else if (base == MobSpawnerBase.k) { + return Biome.TUNDRA; + } else if (base == MobSpawnerBase.l) { + return Biome.HELL; + } + + return null; + } } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftBoat.java b/src/main/java/org/bukkit/craftbukkit/CraftBoat.java new file mode 100644 index 0000000000..cad1e40779 --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/CraftBoat.java @@ -0,0 +1,18 @@ +package org.bukkit.craftbukkit; + +import net.minecraft.server.EntityBoat; +import org.bukkit.Boat; + +/** + * A minecart. + * + * @author sk89q + */ +public class CraftBoat extends CraftVehicle implements Boat { + protected EntityBoat boat; + + public CraftBoat(CraftServer server, EntityBoat entity) { + super(server, entity); + boat = entity; + } +} diff --git a/src/main/java/org/bukkit/craftbukkit/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/CraftEntity.java index 11e5847e31..d9ac3190e9 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftEntity.java @@ -4,6 +4,8 @@ package org.bukkit.craftbukkit; import net.minecraft.server.Entity; import net.minecraft.server.WorldServer; import org.bukkit.Location; +import org.bukkit.Vector; +import org.bukkit.Vehicle; import org.bukkit.World; public abstract class CraftEntity implements org.bukkit.Entity { @@ -19,6 +21,16 @@ public abstract class CraftEntity implements org.bukkit.Entity { return new Location(getWorld(), entity.p, entity.q, entity.r, entity.v, entity.w); } + public Vector getVelocity() { + return new Vector(entity.s, entity.t, entity.u); + } + + public void setVelocity(Vector vel) { + entity.s = vel.getX(); + entity.t = vel.getY(); + entity.u = vel.getZ(); + } + public World getWorld() { return ((WorldServer)entity.l).getWorld(); } @@ -27,6 +39,10 @@ public abstract class CraftEntity implements org.bukkit.Entity { entity.b(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); } + public void teleportTo(org.bukkit.Entity destination) { + teleportTo(destination.getLocation()); + } + public int getEntityID() { return entity.g; } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftHumanEntity.java b/src/main/java/org/bukkit/craftbukkit/CraftHumanEntity.java index b03f096725..91437f4f8c 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftHumanEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftHumanEntity.java @@ -2,22 +2,18 @@ package org.bukkit.craftbukkit; import net.minecraft.server.EntityPlayer; -import net.minecraft.server.InventoryPlayer; import org.bukkit.HumanEntity; import org.bukkit.ItemStack; +import org.bukkit.PlayerInventory; public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity { private EntityPlayer entity; + private CraftInventoryPlayer inventory; public CraftHumanEntity(final CraftServer server, final EntityPlayer entity) { super(server, entity); this.entity = entity; - } - - public ItemStack getSelectedItem() { - // TODO: Implement inventories - final InventoryPlayer inventory = entity.an; - return new ItemStack(inventory.e().c, inventory.e().a); + this.inventory = new CraftInventoryPlayer( entity.an ); } public String getName() { @@ -34,6 +30,14 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity { this.entity = entity; } + public PlayerInventory getInventory() { + return inventory; + } + + public ItemStack getItemInHand() { + return getInventory().getItemInHand(); + } + @Override public String toString() { return "CraftHumanEntity{" + "id=" + getEntityID() + "name=" + getName() + '}'; diff --git a/src/main/java/org/bukkit/craftbukkit/CraftInventory.java b/src/main/java/org/bukkit/craftbukkit/CraftInventory.java new file mode 100644 index 0000000000..c74ecea373 --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/CraftInventory.java @@ -0,0 +1,195 @@ +package org.bukkit.craftbukkit; + +import java.util.HashMap; + +import net.minecraft.server.IInventory; + +import org.bukkit.ItemStack; +import org.bukkit.Material; + +public class CraftInventory implements org.bukkit.Inventory { + protected IInventory inventory; + + public CraftInventory(IInventory inventory) { + this.inventory = inventory; + } + + public IInventory getInventory() { + return inventory; + } + + public int getSize() { + return getInventory().a(); + } + + public String getName() { + return getInventory().b(); + } + + public ItemStack getItem(int index) { + return new CraftItemStack(getInventory().a(index)); + } + + public ItemStack[] getContents() { + ItemStack[] items = new ItemStack[getSize()]; + net.minecraft.server.ItemStack[] mcItems = getInventory().getContents(); + + for (int i = 0; i < mcItems.length; i++ ) { + items[i] = new CraftItemStack(mcItems[i]); + } + + return items; + } + + public void setItem(int index, ItemStack item) { + getInventory().a( index, new net.minecraft.server.ItemStack( item.getTypeID(), item.getAmount())); + } + + public boolean contains(int materialId) { + for (ItemStack item: getContents()) { + if (item.getTypeID() == materialId) { + return true; + } + } + return false; + } + + public boolean contains(Material material) { + return contains(material.getID()); + } + + public boolean contains(ItemStack item) { + for (ItemStack i: getContents()) { + if (item.equals(i)) { + return true; + } + } + return false; + } + + public HashMap all(int materialId) { + HashMap slots = new HashMap(); + + ItemStack[] inventory = getContents(); + for (int i = 0; i < inventory.length; i++) { + ItemStack item = inventory[i]; + if (item.getTypeID() == materialId) { + slots.put( i, item ); + } + } + return slots; + } + + public HashMap all(Material material) { + return all(material.getID()); + } + + public HashMap all(ItemStack item) { + HashMap slots = new HashMap(); + + ItemStack[] inventory = getContents(); + for (int i = 0; i < inventory.length; i++) { + if (item.equals(inventory[i])) { + slots.put( i, item ); + } + } + return slots; + } + + public int first(int materialId) { + ItemStack[] inventory = getContents(); + for (int i = 0; i < inventory.length; i++) { + if (inventory[i].getTypeID() == materialId) { + return i; + } + } + return -1; + } + + public int first(Material material) { + return first(material.getID()); + } + + public int first(ItemStack item) { + ItemStack[] inventory = getContents(); + for (int i = 0; i < inventory.length; i++) { + if (item.equals(inventory[i])) { + return i; + } + } + return -1; + } + + public int firstEmpty() { + return first(Material.Air); + } + + public int firstPartial(int materialId) { + ItemStack[] inventory = getContents(); + for (int i = 0; i < inventory.length; i++) { + if (inventory[i].getAmount() <= inventory[i].getMaxStackSize()) { + return i; + } + } + return -1; + } + + public int firstPartial(Material material) { + return firstPartial(material.getID()); + } + + public int firstPartial(ItemStack item) { + return firstPartial(item.getTypeID()); + } + + public HashMap addItem(ItemStack... items) { + HashMap leftover = new HashMap(); + + /* TODO: some optimization + * - Create a 'firstPartial' with a 'fromIndex' + * - Record the lastPartial per Material + * - Cache firstEmpty result + */ + + for (int i = 0; i < items.length; i++) { + ItemStack item = items[i]; + while (true) { + // Do we already have a stack of it? + int firstPartial = firstPartial( item.getTypeID() ); + + // Drat! no partial stack + if (firstPartial == -1) { + // Find a free spot! + int firstFree = firstEmpty(); + + if (firstFree == -1) { + // No space at all! + leftover.put(i, item); + } else { + // Just store it + setItem( firstFree, item ); + } + break; + } + + // So, apparently it might only partially fit, well lets do just that + ItemStack partialItem = getItem(firstPartial); + + int amount = item.getAmount(); + int partialAmount = partialItem.getAmount(); + int maxAmount = partialItem.getMaxStackSize(); + + // Check if it fully fits + if (amount + partialAmount <= maxAmount) { + partialItem.setAmount( amount + partialAmount ); + break; + } + + // It fits partially + partialItem.setAmount( maxAmount ); + item.setAmount( amount + partialAmount - maxAmount ); + } + } + return leftover; + } +} diff --git a/src/main/java/org/bukkit/craftbukkit/CraftInventoryPlayer.java b/src/main/java/org/bukkit/craftbukkit/CraftInventoryPlayer.java new file mode 100644 index 0000000000..3ee882fc60 --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/CraftInventoryPlayer.java @@ -0,0 +1,67 @@ +package org.bukkit.craftbukkit; + +import java.util.ArrayList; + +import net.minecraft.server.InventoryPlayer; + +import org.bukkit.ItemStack; +import org.bukkit.PlayerInventory; + +public class CraftInventoryPlayer extends CraftInventory implements PlayerInventory { + public CraftInventoryPlayer(net.minecraft.server.InventoryPlayer inventory) { + super(inventory); + } + + public InventoryPlayer getInventory() { + return (InventoryPlayer) inventory; + } + + public ArrayList getArmorContents() { + ArrayList items = new ArrayList(); + for (net.minecraft.server.ItemStack item : getInventory().getArmorContents()) { + ItemStack i = null; + if (item != null) { + i = new CraftItemStack(item); + } + items.add(i); + } + + return items; + } + + public ItemStack getItemInHand() { + return new CraftItemStack( getInventory().e() ); + } + + public ItemStack getHelmet() { + return getItem( getSize() - 4 ); + } + + public ItemStack getChestplate() { + return getItem( getSize() - 3 ); + } + + public ItemStack getLeggings() { + return getItem( getSize() - 2 ); + } + + public ItemStack getBoots() { + return getItem( getSize() - 1 ); + } + + public void setHelmet(ItemStack helmet) { + setItem( getSize() - 4, helmet ); + } + + public void setChestplate(ItemStack chestplate) { + setItem( getSize() - 3, chestplate ); + } + + public void setLeggings(ItemStack leggings) { + setItem( getSize() - 2, leggings ); + } + + public void setBoots(ItemStack boots) { + setItem( getSize() - 1, boots ); + } +} diff --git a/src/main/java/org/bukkit/craftbukkit/CraftItemDrop.java b/src/main/java/org/bukkit/craftbukkit/CraftItemDrop.java new file mode 100644 index 0000000000..0def182530 --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/CraftItemDrop.java @@ -0,0 +1,23 @@ +package org.bukkit.craftbukkit; + +import net.minecraft.server.EntityItem; +import org.bukkit.ItemDrop; +import org.bukkit.ItemStack; + +/** + * Represents an item drop. + * + * @author sk89q + */ +public class CraftItemDrop extends CraftEntity implements ItemDrop { + private EntityItem item; + + public CraftItemDrop(CraftServer server, EntityItem ent) { + super(server, ent); + this.item = ent; + } + + public ItemStack getItemStack() { + return new CraftItemStack(item.a); + } +} diff --git a/src/main/java/org/bukkit/craftbukkit/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/CraftItemStack.java index ed80091064..d1571ac46f 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftItemStack.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftItemStack.java @@ -7,55 +7,83 @@ public class CraftItemStack extends ItemStack { protected net.minecraft.server.ItemStack item; public CraftItemStack(net.minecraft.server.ItemStack item) { - super(item.c, item.a); + super(item != null ? item.c : 0, item != null ? item.a : 0); this.item = item; } /* - * Unsure if we have to syn before each of these calls the values in 'item' + * Unsure if we have to sync before each of these calls the values in 'item' * are all public. */ @Override public Material getType() { - super.setTypeID(item.c); // sync, needed? + super.setTypeID(item != null ? item.c : 0); // sync, needed? return super.getType(); } @Override public int getTypeID() { - super.setTypeID(item.c); // sync, needed? - return item.c; + super.setTypeID(item != null ? item.c : 0); // sync, needed? + return item != null ? item.c : 0; } @Override public void setTypeID(int type) { - super.setTypeID(item.c); - item.c = type; + if (type == 0) { + super.setTypeID(0); + super.setAmount(0); + item = null; + } else { + if (item == null) { + item = new net.minecraft.server.ItemStack(type); + super.setAmount(1); + } else { + item.c = type; + super.setTypeID(item.c); + } + } } @Override public int getAmount() { - super.setAmount(item.a); // sync, needed? + super.setAmount(item != null ? item.a : 0); // sync, needed? return item.a; } @Override public void setAmount(int amount) { - super.setAmount(amount); - item.a = amount; + if (amount == 0) { + super.setTypeID(0); + super.setAmount(0); + item = null; + } else { + super.setAmount(amount); + item.a = amount; + } } @Override public void setDamage(final byte damage) { - super.setDamage(damage); - item.d = damage; + // Ignore damage if item is null + if (item != null) { + super.setDamage(damage); + item.d = damage; + } } @Override public byte getDamage() { - super.setDamage((byte) item.d); // sync, needed? - return (byte) item.d; + if (item != null) { + super.setDamage((byte) item.d); // sync, needed? + return (byte) item.d; + } else { + return 0; + } } + @Override + public int getMaxStackSize() { + return item.a().b(); + } } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/CraftLivingEntity.java index 369314deea..449ea62fe8 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftLivingEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftLivingEntity.java @@ -2,13 +2,16 @@ package org.bukkit.craftbukkit; import net.minecraft.server.Entity; +import net.minecraft.server.EntityArrow; import net.minecraft.server.EntityEgg; import net.minecraft.server.EntityLiving; import net.minecraft.server.EntitySnowball; +import org.bukkit.Arrow; import org.bukkit.Egg; import org.bukkit.LivingEntity; import org.bukkit.Snowball; +import org.bukkit.Vehicle; public class CraftLivingEntity extends CraftEntity implements LivingEntity { private EntityLiving entity; @@ -58,4 +61,37 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { world.a(snowball); return new CraftSnowball(server, snowball); } + + public Arrow shootArrow() { + net.minecraft.server.World world = ((CraftWorld)getWorld()).getHandle(); + EntityArrow snowball = new EntityArrow(world, entity); + world.a(snowball); + return new CraftArrow(server, snowball); + } + + public boolean isInsideVehicle() { + return entity.k != null; + } + + public boolean leaveVehicle() { + if (entity.k == null) { + return false; + } + + entity.setPassengerOf(null); + return true; + } + + public Vehicle getVehicle() { + if (entity.k == null) { + return null; + } + + org.bukkit.Entity vehicle = ((CraftWorld)getWorld()).toCraftEntity(entity.k); + if (vehicle instanceof Vehicle) { + return (Vehicle)vehicle; + } + + return null; + } } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftMappable.java b/src/main/java/org/bukkit/craftbukkit/CraftMappable.java new file mode 100644 index 0000000000..8e411846bd --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/CraftMappable.java @@ -0,0 +1,16 @@ +package org.bukkit.craftbukkit; + +/** + * Indicates that an object has a method to get its CraftBukkit-equivalent + * CraftEntity object from its Minecraft net.minecraft.server.Entity object. + * + * @author sk89q + */ +public interface CraftMappable { + /** + * Gets the CraftEntity version. + * + * @return + */ + public CraftEntity getCraftEntity(); +} diff --git a/src/main/java/org/bukkit/craftbukkit/CraftMinecart.java b/src/main/java/org/bukkit/craftbukkit/CraftMinecart.java index 44082603ba..0d55ad8219 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftMinecart.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftMinecart.java @@ -1,9 +1,7 @@ package org.bukkit.craftbukkit; import net.minecraft.server.EntityMinecart; -import org.bukkit.LivingEntity; import org.bukkit.Minecart; -import org.bukkit.Vector; /** * A minecart. @@ -38,25 +36,6 @@ public class CraftMinecart extends CraftVehicle implements Minecart { minecart = entity; } - public Vector getVelocity() { - return new Vector(minecart.s, minecart.t, minecart.u); - } - - public void setVelocity(Vector vel) { - minecart.s = vel.getX(); - minecart.t = vel.getY(); - minecart.u = vel.getZ(); - } - - public LivingEntity getPassenger() { - // @TODO: Implement - return null; - } - - public boolean isEmpty() { - return minecart.j == null; - } - public void setDamage(int damage) { minecart.a = damage; } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/CraftPlayer.java index 195f437496..90c3d7cc0e 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftPlayer.java @@ -9,11 +9,12 @@ import org.bukkit.Location; import org.bukkit.Player; public class CraftPlayer extends CraftHumanEntity implements Player { - private EntityPlayerMP entity; + private String name; public CraftPlayer(CraftServer server, EntityPlayerMP entity) { super(server, entity); + this.name = getName(); this.entity = entity; } @@ -58,6 +59,14 @@ public class CraftPlayer extends CraftHumanEntity implements Player { entity.a.a(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); } + public String getDisplayName() { + return name; + } + + public void setDisplayName(final String name) { + this.name = name; + } + @Override public String toString() { return "CraftPlayer{" + "name=" + getName() + '}'; diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 4d814ed16f..c3b9c7cdab 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -1,6 +1,7 @@ package org.bukkit.craftbukkit; import java.io.File; +import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -26,7 +27,9 @@ public final class CraftServer implements Server { this.server = server; pluginManager.RegisterInterface(JavaPluginLoader.class); - + } + + public void loadPlugins() { File pluginFolder = (File)console.options.valueOf("plugins"); if (pluginFolder.exists()) { @@ -78,6 +81,27 @@ public final class CraftServer implements Server { public Player getPlayer(final EntityPlayerMP entity) { return entity.a.getPlayer(); } + + public List matchPlayer(String partialName) { + List matchedPlayers = new ArrayList(); + + for (Player iterPlayer : this.getOnlinePlayers()) { + String iterPlayerName = iterPlayer.getName(); + + if (partialName.equalsIgnoreCase(iterPlayerName)) { + // Exact match + matchedPlayers.clear(); + matchedPlayers.add(iterPlayer); + break; + } + if (iterPlayerName.toLowerCase().indexOf(partialName.toLowerCase()) != -1) { + // Partial match + matchedPlayers.add(iterPlayer); + } + } + + return matchedPlayers; + } public PluginManager getPluginManager() { return pluginManager; diff --git a/src/main/java/org/bukkit/craftbukkit/CraftSlot.java b/src/main/java/org/bukkit/craftbukkit/CraftSlot.java new file mode 100644 index 0000000000..32b12b7a0f --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/CraftSlot.java @@ -0,0 +1,25 @@ +package org.bukkit.craftbukkit; + +import org.bukkit.Inventory; +import org.bukkit.ItemStack; +import net.minecraft.server.Slot; + +public class CraftSlot implements org.bukkit.Slot { + private final Slot slot; + + public CraftSlot(Slot slot) { + this.slot = slot; + } + + public Inventory getInventory() { + return new CraftInventory( slot.b ); + } + + public int getIndex() { + return slot.a; + } + + public ItemStack getItem() { + return new CraftItemStack( slot.c() ); + } +} diff --git a/src/main/java/org/bukkit/craftbukkit/CraftStorageMinecart.java b/src/main/java/org/bukkit/craftbukkit/CraftStorageMinecart.java index 7567529e31..3063482daa 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftStorageMinecart.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftStorageMinecart.java @@ -1,11 +1,8 @@ package org.bukkit.craftbukkit; -import java.util.ArrayList; -import java.util.List; - import net.minecraft.server.EntityMinecart; -import org.bukkit.ItemStack; +import org.bukkit.Inventory; import org.bukkit.StorageMinecart; /** @@ -14,32 +11,14 @@ import org.bukkit.StorageMinecart; * @author sk89q */ public class CraftStorageMinecart extends CraftMinecart implements StorageMinecart { + private CraftInventory inventory; + public CraftStorageMinecart(CraftServer server, EntityMinecart entity) { super(server, entity); + inventory = new CraftInventory( entity ); } - public int getSize() { - return minecart.c(); - } - - public String getName() { - return minecart.b(); - } - - public ItemStack getItem(int index) { - return new CraftItemStack(minecart.a(index)); - } - - public List getContents() { - ArrayList items = new ArrayList(); - for (net.minecraft.server.ItemStack item: minecart.getContents()) { - ItemStack i = null; - if (item != null) { - i = new CraftItemStack( item ); - } - items.add(i); - } - - return items; + public Inventory getInventory() { + return inventory; } } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftVehicle.java b/src/main/java/org/bukkit/craftbukkit/CraftVehicle.java index a5c03868c4..ffc93da19b 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftVehicle.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftVehicle.java @@ -1,7 +1,7 @@ package org.bukkit.craftbukkit; -import net.minecraft.server.Entity; - +import org.bukkit.Entity; +import org.bukkit.Vector; import org.bukkit.Vehicle; /** @@ -10,7 +10,29 @@ import org.bukkit.Vehicle; * @author sk89q */ public abstract class CraftVehicle extends CraftEntity implements Vehicle { - public CraftVehicle(CraftServer server, Entity entity) { + public CraftVehicle(CraftServer server, net.minecraft.server.Entity entity) { super(server, entity); } + + public Entity getPassenger() { + return ((CraftWorld)getWorld()).toCraftEntity(getHandle().j); + } + + public boolean setPassenger(Entity passenger) { + ((CraftEntity)passenger).getHandle().setPassengerOf(getHandle()); + return true; + } + + public boolean isEmpty() { + return getHandle().j == null; + } + + public boolean eject() { + if (getHandle().j == null) { + return false; + } + + getHandle().j.setPassengerOf(null); + return true; + } } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 74c49a9ec1..35f2a3a833 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -6,13 +6,25 @@ import java.util.Map; import net.minecraft.server.EntityMinecart; import java.util.Random; + +import net.minecraft.server.EntityBoat; +import net.minecraft.server.EntityEgg; +import net.minecraft.server.EntityItem; +import net.minecraft.server.EntityLiving; +import net.minecraft.server.EntityPlayerMP; +import net.minecraft.server.EntitySnowball; +import net.minecraft.server.EntityArrow; +import net.minecraft.server.EntityPlayer; +import net.minecraft.server.TileEntity; import net.minecraft.server.WorldGenBigTree; import net.minecraft.server.WorldServer; -import net.minecraft.server.EntityArrow; import net.minecraft.server.WorldGenTrees; import org.bukkit.Arrow; import org.bukkit.Block; +import org.bukkit.Boat; import org.bukkit.Chunk; +import org.bukkit.ItemDrop; +import org.bukkit.ItemStack; import org.bukkit.Location; import org.bukkit.Minecart; import org.bukkit.PoweredMinecart; @@ -101,6 +113,28 @@ public class CraftWorld implements World { public WorldServer getHandle() { return world; } + + public ItemDrop dropItem(Location loc, ItemStack item) { + net.minecraft.server.ItemStack stack = + new net.minecraft.server.ItemStack( + item.getTypeID(), item.getAmount(), item.getDamage()); + EntityItem entity = new EntityItem(world, loc.getX(), loc.getY(), + loc.getZ(), stack); + entity.c = 10; + world.a(entity); + return new CraftItemDrop(world.getServer(), entity); + } + + public ItemDrop dropItemNaturally(Location loc, ItemStack item) { + double xs = world.l.nextFloat() * 0.7F + (1.0F - 0.7F) * 0.5D; + double ys = world.l.nextFloat() * 0.7F + (1.0F - 0.7F) * 0.5D; + double zs = world.l.nextFloat() * 0.7F + (1.0F - 0.7F) * 0.5D; + loc = loc.clone(); + loc.setX(loc.getX() + xs); + loc.setX(loc.getY() + ys); + loc.setX(loc.getZ() + zs); + return dropItem(loc, item); + } public Arrow spawnArrow(Location loc, Vector velocity, float speed, float spread) { @@ -138,6 +172,13 @@ public class CraftWorld implements World { return new CraftPoweredMinecart(world.getServer(), minecart); } + public Boat spawnBoat(Location loc) { + EntityBoat boat = + new EntityBoat(world, loc.getX(), loc.getY(), loc.getZ()); + world.a(boat); + return new CraftBoat(world.getServer(), boat); + } + public boolean generateTree(Location loc) { WorldGenTrees treeGen = new WorldGenTrees(); return treeGen.a(world, rand, @@ -149,6 +190,40 @@ public class CraftWorld implements World { return treeGen.a(world, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); } + + public CraftEntity toCraftEntity(net.minecraft.server.Entity entity) { + if (entity instanceof CraftMappable) { + return ((CraftMappable)entity).getCraftEntity(); + } else if (entity instanceof EntityItem) { + return new CraftItemDrop(world.getServer(), (EntityItem)entity); + } else if (entity instanceof EntityArrow) { + return new CraftArrow(world.getServer(), (EntityArrow)entity); + } else if (entity instanceof EntityEgg) { + return new CraftEgg(world.getServer(), (EntityEgg)entity); + } else if (entity instanceof EntityPlayerMP) { + return new CraftPlayer(world.getServer(), (EntityPlayerMP)entity); + } else if (entity instanceof EntitySnowball) { + return new CraftSnowball(world.getServer(), (EntitySnowball)entity); + } else if (entity instanceof EntityPlayer) { + return new CraftHumanEntity(world.getServer(), (EntityPlayer)entity); + } else if (entity instanceof EntityLiving) { + return new CraftLivingEntity(world.getServer(), (EntityLiving)entity); + } else { + return null; + } + } + + public TileEntity getTileEntityAt(final int x, final int y, final int z) { + return world.l(x, y, z); + } + + public String getName() { + return world.w; + } + + public long getId() { + return world.u; + } @Override public String toString() { diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java new file mode 100644 index 0000000000..f2a0c2756d --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java @@ -0,0 +1,168 @@ + +package org.bukkit.craftbukkit.block; + +import org.bukkit.Block; +import org.bukkit.Chunk; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.BlockState; +import org.bukkit.craftbukkit.CraftChunk; +import org.bukkit.craftbukkit.CraftWorld; + +public class CraftBlockState implements BlockState { + private final CraftWorld world; + private final CraftChunk chunk; + private final int x; + private final int y; + private final int z; + protected int type; + protected byte data; + protected byte light; + + public CraftBlockState(final Block block) { + this.world = (CraftWorld)block.getWorld(); + this.x = block.getX(); + this.y = block.getY(); + this.z = block.getZ(); + this.type = block.getTypeID(); + this.data = block.getData(); + this.light = block.getLightLevel(); + this.chunk = (CraftChunk)block.getChunk(); + } + + /** + * Gets the world which contains this Block + * + * @return World containing this block + */ + public World getWorld() { + return world; + } + + /** + * Gets the x-coordinate of this block + * + * @return x-coordinate + */ + public int getX() { + return x; + } + + /** + * Gets the y-coordinate of this block + * + * @return y-coordinate + */ + public int getY() { + return y; + } + + /** + * Gets the z-coordinate of this block + * + * @return z-coordinate + */ + public int getZ() { + return z; + } + + /** + * Gets the chunk which contains this block + * + * @return Containing Chunk + */ + public Chunk getChunk() { + return chunk; + } + + /** + * Sets the metadata for this block + * + * @param data New block specific metadata + */ + public void setData(final byte data) { + this.data = data; + world.getHandle().c(x, y, z, data); + } + + /** + * Gets the metadata for this block + * + * @return block specific metadata + */ + public byte getData() { + return data; + } + + /** + * Sets the type of this block + * + * @param type Material to change this block to + */ + public void setType(final Material type) { + setTypeID(type.getID()); + } + + /** + * Sets the type-ID of this block + * + * @param type Type-ID to change this block to + */ + public void setTypeID(final int type) { + this.type = type; + world.getHandle().d(x, y, z, type); + } + + /** + * Gets the type of this block + * + * @return block type + */ + public Material getType() { + return Material.getMaterial(getTypeID()); + } + + /** + * Gets the type-ID of this block + * + * @return block type-ID + */ + public int getTypeID() { + return type; + } + + /** + * Gets the light level between 0-15 + * + * @return light level + */ + public byte getLightLevel() { + return light; + } + + public Block getBlock() { + return world.getBlockAt(x, y, z); + } + + public boolean update() { + return update(false); + } + + public boolean update(boolean force) { // TODO + Block block = getBlock(); + + synchronized (block) { + if (block.getType() != this.getType()) { + if (force) { + block.setTypeID(this.getTypeID()); + } else { + return false; + } + } + + block.setData(data); + } + + return true; + } +} diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java b/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java new file mode 100644 index 0000000000..a3a8649b93 --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java @@ -0,0 +1,42 @@ + +package org.bukkit.craftbukkit.block; + +import net.minecraft.server.TileEntitySign; +import org.bukkit.Block; +import org.bukkit.block.Sign; +import org.bukkit.craftbukkit.CraftWorld; + +public class CraftSign extends CraftBlockState implements Sign { + private final CraftWorld world; + private final TileEntitySign sign; + + public CraftSign(final Block block) { + super(block); + + world = (CraftWorld)block.getWorld(); + sign = (TileEntitySign)world.getTileEntityAt(getX(), getY(), getZ()); + } + + public String[] getLines() { + return sign.e; + } + + public String getLine(int index) throws IndexOutOfBoundsException { + return sign.e[index]; + } + + public void setLine(int index, String line) throws IndexOutOfBoundsException { + sign.e[index] = line; + } + + @Override + public boolean update(boolean force) { + boolean result = super.update(force); + + if (result) { + sign.d(); + } + + return result; + } +}