Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
1package net.minecraft.server;
2
3// CraftBukkit start
4
5import com.legacyminecraft.poseidon.PoseidonConfig;
6import org.bukkit.craftbukkit.block.CraftBlockState;
7import org.bukkit.craftbukkit.event.CraftEventFactory;
8import org.bukkit.event.block.BlockPlaceEvent;
9// CraftBukkit end
10
11import uk.betacraft.uberbukkit.UberbukkitConfig;
12
13public class ItemBlock extends Item {
14
15 private int id;
16
17 public ItemBlock(int i) {
18 super(i);
19 this.id = i + 256;
20 this.b(Block.byId[i + 256].a(2));
21 }
22
23 public boolean a(ItemStack itemstack, EntityHuman entityhuman, World world, int i, int j, int k, int l) {
24 int clickedX = i, clickedY = j, clickedZ = k; // CraftBukkit
25
26 if (world.getTypeId(i, j, k) == Block.SNOW.id) {
27 l = 0;
28 } else {
29 if (l == 0) {
30 --j;
31 }
32
33 if (l == 1) {
34 ++j;
35 }
36
37 if (l == 2) {
38 --k;
39 }
40
41 if (l == 3) {
42 ++k;
43 }
44
45 if (l == 4) {
46 --i;
47 }
48
49 if (l == 5) {
50 ++i;
51 }
52 }
53
54 if (itemstack.count == 0) {
55 return false;
56 } else if (!UberbukkitConfig.getInstance().getBoolean("mechanics.allow_blocks_at_y_127", false) && j == 127 && Block.byId[this.id].material.isBuildable()) {
57 return false;
58 } else if (world.a(this.id, i, j, k, false, l)) {
59 Block block = Block.byId[this.id];
60
61 // CraftBukkit start - This executes the placement of the block
62 CraftBlockState replacedBlockState = CraftBlockState.getBlockState(world, i, j, k);
63
64 // There are like 30 combinations you can mix and match steps and double steps
65 // of different materials, so there are a lot of different cases of what
66 // would happen if you place x step onto another y step, so let's just keep
67 // track of the entire state
68 CraftBlockState blockStateBelow = null;
69 // Toggles whether the normal or the block below is used for the place event
70 boolean eventUseBlockBelow = false;
71 if ((world.getTypeId(i, j - 1, k) == Block.STEP.id || world.getTypeId(i, j - 1, k) == Block.DOUBLE_STEP.id) && (itemstack.id == Block.DOUBLE_STEP.id || itemstack.id == Block.STEP.id)) {
72 blockStateBelow = CraftBlockState.getBlockState(world, i, j - 1, k);
73 // Step is placed on step, forms a doublestep replacing the original step, so we need the lower block
74 eventUseBlockBelow = itemstack.id == Block.STEP.id && blockStateBelow.getTypeId() == Block.STEP.id;
75 }
76
77 /**
78 * @see net.minecraft.server.World#setTypeIdAndData(int i, int j, int k, int l, int i1)
79 *
80 * This replaces world.setTypeIdAndData(IIIII), we're doing this because we need to
81 * hook between the 'placement' and the informing to 'world' so we can
82 * sanely undo this.
83 *
84 * Whenever the call to 'world.setTypeIdAndData' changes we need to figure out again what to
85 * replace this with.
86 */
87 if (world.setRawTypeIdAndData(i, j, k, this.id, this.filterData(itemstack.getData()))) { // <-- world.setTypeIdAndData does this to place the block
88 BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, eventUseBlockBelow ? blockStateBelow : replacedBlockState, clickedX, clickedY, clickedZ, block);
89
90 if (event.isCancelled() || !event.canBuild()) {
91 if (blockStateBelow != null) { // Used for steps
92 world.setTypeIdAndData(i, j, k, replacedBlockState.getTypeId(), replacedBlockState.getRawData());
93 world.setTypeIdAndData(i, j - 1, k, blockStateBelow.getTypeId(), blockStateBelow.getRawData());
94
95 } else {
96
97 if (this.id == Block.ICE.id) {
98 // Ice will explode if we set straight to 0
99 world.setTypeId(i, j, k, 20);
100 }
101
102 world.setTypeIdAndData(i, j, k, replacedBlockState.getTypeId(), replacedBlockState.getRawData());
103 }
104 return true;
105
106 }
107 // CraftBukkit end
108
109 if (PoseidonConfig.getInstance().getConfigBoolean("world.settings.pistons.other-fixes.enabled", true) && (this.id == 29 || this.id == 33)) {
110 Block.byId[this.id].postPlace(world, i, j, k, l);
111 Block.byId[this.id].postPlace(world, i, j, k, entityhuman);
112 world.update(i, j, k, this.id); // <-- world.setTypeIdAndData does this on success (tell the world)
113 } else {
114 world.update(i, j, k, this.id);
115 Block.byId[this.id].postPlace(world, i, j, k, l);
116 Block.byId[this.id].postPlace(world, i, j, k, entityhuman);
117 }
118
119 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);
120 --itemstack.count;
121 }
122
123 return true;
124 } else {
125 return false;
126 }
127 }
128
129 public String a() {
130 return Block.byId[this.id].l();
131 }
132}