Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
1package net.minecraft.server;
2
3import org.bukkit.event.entity.EntityDamageEvent;
4
5import java.util.Iterator;
6import java.util.Random;
7
8import uk.betacraft.uberbukkit.UberbukkitConfig;
9
10public class BlockBed extends Block {
11
12 public static final int[][] a = new int[][] { { 0, 1 }, { -1, 0 }, { 0, -1 }, { 1, 0 } };
13
14 public BlockBed(int i) {
15 super(i, 134, Material.CLOTH);
16 this.o();
17 }
18
19 public boolean interact(World world, int i, int j, int k, EntityHuman entityhuman) {
20 if (world.isStatic) {
21 return true;
22 } else {
23 int l = world.getData(i, j, k);
24
25 if (!d(l)) {
26 int i1 = c(l);
27
28 i += a[i1][0];
29 k += a[i1][1];
30 if (world.getTypeId(i, j, k) != this.id) {
31 return true;
32 }
33
34 l = world.getData(i, j, k);
35 }
36
37 // uberbukkit
38 if (!world.worldProvider.d() && UberbukkitConfig.getInstance().getBoolean("mechanics.nether_bed_explode", true)) {
39 double d0 = (double) i + 0.5D;
40 double d1 = (double) j + 0.5D;
41 double d2 = (double) k + 0.5D;
42
43 world.setTypeId(i, j, k, 0);
44 int j1 = c(l);
45
46 i += a[j1][0];
47 k += a[j1][1];
48 if (world.getTypeId(i, j, k) == this.id) {
49 world.setTypeId(i, j, k, 0);
50 d0 = (d0 + (double) i + 0.5D) / 2.0D;
51 d1 = (d1 + (double) j + 0.5D) / 2.0D;
52 d2 = (d2 + (double) k + 0.5D) / 2.0D;
53 }
54
55 world.createExplosion((Entity) null, (double) ((float) i + 0.5F), (double) ((float) j + 0.5F), (double) ((float) k + 0.5F), 5.0F, true, EntityDamageEvent.DamageCause.BED_EXPLOSION); //Project poseidon
56 return true;
57 } else {
58 if (e(l)) {
59 EntityHuman entityhuman1 = null;
60 Iterator iterator = world.players.iterator();
61
62 while (iterator.hasNext()) {
63 EntityHuman entityhuman2 = (EntityHuman) iterator.next();
64
65 if (entityhuman2.isSleeping()) {
66 ChunkCoordinates chunkcoordinates = entityhuman2.A;
67
68 if (chunkcoordinates.x == i && chunkcoordinates.y == j && chunkcoordinates.z == k) {
69 entityhuman1 = entityhuman2;
70 }
71 }
72 }
73
74 if (entityhuman1 != null) {
75 entityhuman.a("tile.bed.occupied");
76 return true;
77 }
78
79 a(world, i, j, k, false);
80 }
81
82 EnumBedError enumbederror = entityhuman.a(i, j, k);
83
84 if (enumbederror == EnumBedError.OK) {
85 a(world, i, j, k, true);
86 return true;
87 } else {
88 if (enumbederror == EnumBedError.NOT_POSSIBLE_NOW) {
89 entityhuman.a("tile.bed.noSleep");
90 }
91
92 return true;
93 }
94 }
95 }
96 }
97
98 public int a(int i, int j) {
99 if (i == 0) {
100 return Block.WOOD.textureId;
101 } else {
102 int k = c(j);
103 int l = BedBlockTextures.c[k][i];
104
105 return d(j) ? (l == 2 ? this.textureId + 2 + 16 : (l != 5 && l != 4 ? this.textureId + 1 : this.textureId + 1 + 16)) : (l == 3 ? this.textureId - 1 + 16 : (l != 5 && l != 4 ? this.textureId : this.textureId + 16));
106 }
107 }
108
109 public boolean b() {
110 return false;
111 }
112
113 public boolean a() {
114 return false;
115 }
116
117 public void a(IBlockAccess iblockaccess, int i, int j, int k) {
118 this.o();
119 }
120
121 public void doPhysics(World world, int i, int j, int k, int l) {
122 int i1 = world.getData(i, j, k);
123 int j1 = c(i1);
124
125 if (d(i1)) {
126 if (world.getTypeId(i - a[j1][0], j, k - a[j1][1]) != this.id) {
127 world.setTypeId(i, j, k, 0);
128 }
129 } else if (world.getTypeId(i + a[j1][0], j, k + a[j1][1]) != this.id) {
130 world.setTypeId(i, j, k, 0);
131 if (!world.isStatic) {
132 this.g(world, i, j, k, i1);
133 }
134 }
135 }
136
137 public int a(int i, Random random) {
138 return d(i) ? 0 : Item.BED.id;
139 }
140
141 private void o() {
142 this.a(0.0F, 0.0F, 0.0F, 1.0F, 0.5625F, 1.0F);
143 }
144
145 public static int c(int i) {
146 return i & 3;
147 }
148
149 public static boolean d(int i) {
150 return (i & 8) != 0;
151 }
152
153 public static boolean e(int i) {
154 return (i & 4) != 0;
155 }
156
157 public static void a(World world, int i, int j, int k, boolean flag) {
158 int l = world.getData(i, j, k);
159
160 if (flag) {
161 l |= 4;
162 } else {
163 l &= -5;
164 }
165
166 world.setData(i, j, k, l);
167 }
168
169 public static ChunkCoordinates f(World world, int i, int j, int k, int l) {
170 int i1 = world.getData(i, j, k);
171 int j1 = c(i1);
172
173 for (int k1 = 0; k1 <= 1; ++k1) {
174 int l1 = i - a[j1][0] * k1 - 1;
175 int i2 = k - a[j1][1] * k1 - 1;
176 int j2 = l1 + 2;
177 int k2 = i2 + 2;
178
179 for (int l2 = l1; l2 <= j2; ++l2) {
180 for (int i3 = i2; i3 <= k2; ++i3) {
181 if (world.e(l2, j - 1, i3) && world.isEmpty(l2, j, i3) && world.isEmpty(l2, j + 1, i3)) {
182 if (l <= 0) {
183 return new ChunkCoordinates(l2, j, i3);
184 }
185
186 --l;
187 }
188 }
189 }
190 }
191
192 return null;
193 }
194
195 public void dropNaturally(World world, int i, int j, int k, int l, float f) {
196 if (!d(l)) {
197 super.dropNaturally(world, i, j, k, l, f);
198 }
199 }
200
201 public int e() {
202 return 1;
203 }
204}