Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
at develop 91 lines 3.2 kB view raw
1package net.minecraft.server; 2 3// CraftBukkit start 4 5import org.bukkit.craftbukkit.block.CraftBlockState; 6import org.bukkit.craftbukkit.event.CraftEventFactory; 7import org.bukkit.event.block.BlockPlaceEvent; 8// CraftBukkit end 9 10public class ItemReed extends Item { 11 12 private int id; 13 14 public ItemReed(int i, Block block) { 15 super(i); 16 this.id = block.id; 17 } 18 19 public boolean a(ItemStack itemstack, EntityHuman entityhuman, World world, int i, int j, int k, int l) { 20 int clickedX = i, clickedY = j, clickedZ = k; // CraftBukkit 21 22 if (world.getTypeId(i, j, k) == Block.SNOW.id) { 23 l = 0; 24 } else { 25 if (l == 0) { 26 --j; 27 } 28 29 if (l == 1) { 30 ++j; 31 } 32 33 if (l == 2) { 34 --k; 35 } 36 37 if (l == 3) { 38 ++k; 39 } 40 41 if (l == 4) { 42 --i; 43 } 44 45 if (l == 5) { 46 ++i; 47 } 48 } 49 50 if (itemstack.count == 0) { 51 return false; 52 } else { 53 if (world.a(this.id, i, j, k, false, l)) { 54 Block block = Block.byId[this.id]; 55 56 // CraftBukkit start - This executes the placement of the block 57 CraftBlockState replacedBlockState = CraftBlockState.getBlockState(world, i, j, k); // CraftBukkit 58 /** 59 * @see net.minecraft.server.World#setTypeId(int i, int j, int k, int l) 60 * 61 * This replaces world.setTypeId(IIII), we're doing this because we need to 62 * hook between the 'placement' and the informing to 'world' so we can 63 * sanely undo this. 64 * 65 * Whenever the call to 'world.setTypeId' changes we need to figure out again what to 66 * replace this with. 67 */ 68 if (world.setRawTypeId(i, j, k, this.id)) { // <-- world.e does this to place the block 69 BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, replacedBlockState, clickedX, clickedY, clickedZ, block); 70 71 if (event.isCancelled() || !event.canBuild()) { 72 // CraftBukkit - undo; this only has reed, repeater and pie blocks 73 world.setTypeIdAndData(i, j, k, replacedBlockState.getTypeId(), replacedBlockState.getRawData()); 74 75 return true; 76 } 77 78 world.update(i, j, k, this.id); // <-- world.setTypeId does this on success (tell the world) 79 // CraftBukkit end 80 81 Block.byId[this.id].postPlace(world, i, j, k, l); 82 Block.byId[this.id].postPlace(world, i, j, k, entityhuman); 83 world.makeSound((double) ((float) i + 0.5F), (double) ((float) j + 0.5F), (double) ((float) k + 0.5F), block.stepSound.getName(), (block.stepSound.getVolume1() + 1.0F) / 2.0F, block.stepSound.getVolume2() * 0.8F); 84 --itemstack.count; 85 } 86 } 87 88 return true; 89 } 90 } 91}