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 org.bukkit.craftbukkit.block.CraftBlockState;
6import org.bukkit.craftbukkit.event.CraftEventFactory;
7import org.bukkit.event.block.BlockPlaceEvent;
8// CraftBukkit end
9
10public class ItemBed extends Item {
11
12 public ItemBed(int i) {
13 super(i);
14 }
15
16 public boolean a(ItemStack itemstack, EntityHuman entityhuman, World world, int i, int j, int k, int l) {
17 if (l != 1) {
18 return false;
19 } else {
20 int clickedX = i, clickedY = j, clickedZ = k; // CraftBukkit
21
22 ++j;
23 BlockBed blockbed = (BlockBed) Block.BED;
24 int i1 = MathHelper.floor((double) (entityhuman.yaw * 4.0F / 360.0F) + 0.5D) & 3;
25 byte b0 = 0;
26 byte b1 = 0;
27
28 if (i1 == 0) {
29 b1 = 1;
30 }
31
32 if (i1 == 1) {
33 b0 = -1;
34 }
35
36 if (i1 == 2) {
37 b1 = -1;
38 }
39
40 if (i1 == 3) {
41 b0 = 1;
42 }
43
44 if (world.isEmpty(i, j, k) && world.isEmpty(i + b0, j, k + b1) && world.e(i, j - 1, k) && world.e(i + b0, j - 1, k + b1)) {
45 CraftBlockState blockState = CraftBlockState.getBlockState(world, i, j, k); // CraftBukkit
46
47 world.setTypeIdAndData(i, j, k, blockbed.id, i1);
48
49 // CraftBukkit start - bed
50 BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, clickedX, clickedY, clickedZ, blockbed);
51
52 if (event.isCancelled() || !event.canBuild()) {
53 event.getBlockPlaced().setTypeIdAndData(blockState.getTypeId(), blockState.getRawData(), false);
54 return false;
55 }
56 // CraftBukkit end
57
58 world.setTypeIdAndData(i + b0, j, k + b1, blockbed.id, i1 + 8);
59 --itemstack.count;
60 return true;
61 } else {
62 return false;
63 }
64 }
65 }
66}