diff options
author | durron597 <martin.jared@gmail.com> | 2011-01-08 08:33:54 -0500 |
---|---|---|
committer | durron597 <martin.jared@gmail.com> | 2011-01-08 08:33:54 -0500 |
commit | eb4b30185fb79aa07fc74e955134df1e5be35859 (patch) | |
tree | 91196cbe0f4a941ae914fd987ac1967330fb6adc /src/main/java/net/minecraft/server/BlockChest.java | |
parent | fab66092e2e5379c4f3fa9cf37f37320c8ac0e18 (diff) | |
download | craftbukkit-eb4b30185fb79aa07fc74e955134df1e5be35859.tar craftbukkit-eb4b30185fb79aa07fc74e955134df1e5be35859.tar.gz craftbukkit-eb4b30185fb79aa07fc74e955134df1e5be35859.tar.lz craftbukkit-eb4b30185fb79aa07fc74e955134df1e5be35859.tar.xz craftbukkit-eb4b30185fb79aa07fc74e955134df1e5be35859.zip |
Added BLOCK_INTERACT event
Diffstat (limited to 'src/main/java/net/minecraft/server/BlockChest.java')
-rw-r--r-- | src/main/java/net/minecraft/server/BlockChest.java | 169 |
1 files changed, 169 insertions, 0 deletions
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 00000000..90e41e33 --- /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(); + } +} + |