Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
1package net.minecraft.server;
2
3import java.util.ArrayList;
4import java.util.List;
5
6import org.bukkit.event.painting.PaintingBreakByEntityEvent;
7import org.bukkit.event.painting.PaintingBreakByWorldEvent;
8
9import uk.betacraft.uberbukkit.Uberbukkit;
10
11public class EntityPainting extends Entity {
12
13 private int f;
14 public int a;
15 public int b;
16 public int c;
17 public int d;
18 public EnumArt e;
19
20 public EntityPainting(World world) {
21 super(world);
22 this.f = 0;
23 this.a = 0;
24 this.height = 0.0F;
25 this.b(0.5F, 0.5F);
26 }
27
28 public EntityPainting(World world, int i, int j, int k, int l) {
29 this(world);
30 this.b = i;
31 this.c = j;
32 this.d = k;
33 ArrayList arraylist = new ArrayList();
34 EnumArt[] aenumart = EnumArt.values();
35 int i1 = aenumart.length;
36
37 for (int j1 = 0; j1 < i1; ++j1) {
38 EnumArt enumart = aenumart[j1];
39
40 // uberbukkit - make paintings show just the motives that exist in the target version
41 if (enumart == EnumArt.BURNINGSKULL && Uberbukkit.getTargetPVN() < 8) continue;
42
43 this.e = enumart;
44 this.b(l);
45 if (this.h()) {
46 arraylist.add(enumart);
47 }
48 }
49
50 if (arraylist.size() > 0) {
51 this.e = (EnumArt) arraylist.get(this.random.nextInt(arraylist.size()));
52 }
53
54 this.b(l);
55 }
56
57 protected void b() {
58 }
59
60 public void b(int i) {
61 this.a = i;
62 this.lastYaw = this.yaw = (float) (i * 90);
63 float f = (float) this.e.B;
64 float f1 = (float) this.e.C;
65 float f2 = (float) this.e.B;
66
67 if (i != 0 && i != 2) {
68 f = 0.5F;
69 } else {
70 f2 = 0.5F;
71 }
72
73 f /= 32.0F;
74 f1 /= 32.0F;
75 f2 /= 32.0F;
76 float f3 = (float) this.b + 0.5F;
77 float f4 = (float) this.c + 0.5F;
78 float f5 = (float) this.d + 0.5F;
79 float f6 = 0.5625F;
80
81 if (i == 0) {
82 f5 -= f6;
83 }
84
85 if (i == 1) {
86 f3 -= f6;
87 }
88
89 if (i == 2) {
90 f5 += f6;
91 }
92
93 if (i == 3) {
94 f3 += f6;
95 }
96
97 if (i == 0) {
98 f3 -= this.c(this.e.B);
99 }
100
101 if (i == 1) {
102 f5 += this.c(this.e.B);
103 }
104
105 if (i == 2) {
106 f3 += this.c(this.e.B);
107 }
108
109 if (i == 3) {
110 f5 -= this.c(this.e.B);
111 }
112
113 f4 += this.c(this.e.C);
114 this.setPosition((double) f3, (double) f4, (double) f5);
115 float f7 = -0.00625F;
116
117 this.boundingBox.c((double) (f3 - f - f7), (double) (f4 - f1 - f7), (double) (f5 - f2 - f7), (double) (f3 + f + f7), (double) (f4 + f1 + f7), (double) (f5 + f2 + f7));
118 }
119
120 private float c(int i) {
121 return i == 32 ? 0.5F : (i == 64 ? 0.5F : 0.0F);
122 }
123
124 public void m_() {
125 if (this.f++ == 100 && !this.world.isStatic) {
126 this.f = 0;
127 if (!this.h()) {
128 // CraftBukkit start
129 PaintingBreakByWorldEvent event = new PaintingBreakByWorldEvent((org.bukkit.entity.Painting) this.getBukkitEntity());
130 this.world.getServer().getPluginManager().callEvent(event);
131
132 if (event.isCancelled()) {
133 return;
134 }
135 // CraftBukkit end
136
137 this.die();
138 this.world.addEntity(new EntityItem(this.world, this.locX, this.locY, this.locZ, new ItemStack(Item.PAINTING)));
139 }
140 }
141 }
142
143 public boolean h() {
144 if (this.world.getEntities(this, this.boundingBox).size() > 0) {
145 return false;
146 } else {
147 int i = this.e.B / 16;
148 int j = this.e.C / 16;
149 int k = this.b;
150 int l = this.c;
151 int i1 = this.d;
152
153 if (this.a == 0) {
154 k = MathHelper.floor(this.locX - (double) ((float) this.e.B / 32.0F));
155 }
156
157 if (this.a == 1) {
158 i1 = MathHelper.floor(this.locZ - (double) ((float) this.e.B / 32.0F));
159 }
160
161 if (this.a == 2) {
162 k = MathHelper.floor(this.locX - (double) ((float) this.e.B / 32.0F));
163 }
164
165 if (this.a == 3) {
166 i1 = MathHelper.floor(this.locZ - (double) ((float) this.e.B / 32.0F));
167 }
168
169 l = MathHelper.floor(this.locY - (double) ((float) this.e.C / 32.0F));
170
171 int j1;
172
173 for (int k1 = 0; k1 < i; ++k1) {
174 for (j1 = 0; j1 < j; ++j1) {
175 Material material;
176
177 if (this.a != 0 && this.a != 2) {
178 material = this.world.getMaterial(this.b, l + j1, i1 + k1);
179 } else {
180 material = this.world.getMaterial(k + k1, l + j1, this.d);
181 }
182
183 if (!material.isBuildable()) {
184 return false;
185 }
186 }
187 }
188
189 List list = this.world.b((Entity) this, this.boundingBox);
190
191 for (j1 = 0; j1 < list.size(); ++j1) {
192 if (list.get(j1) instanceof EntityPainting) {
193 return false;
194 }
195 }
196
197 return true;
198 }
199 }
200
201 public boolean l_() {
202 return true;
203 }
204
205 public boolean damageEntity(Entity entity, int i) {
206 if (!this.dead && !this.world.isStatic) {
207 // CraftBukkit start
208 PaintingBreakByEntityEvent event = new PaintingBreakByEntityEvent((org.bukkit.entity.Painting) this.getBukkitEntity(), entity == null ? null : entity.getBukkitEntity());
209 this.world.getServer().getPluginManager().callEvent(event);
210
211 if (event.isCancelled()) {
212 return true;
213 }
214 // CraftBukkit end
215
216 this.die();
217 this.af();
218 this.world.addEntity(new EntityItem(this.world, this.locX, this.locY, this.locZ, new ItemStack(Item.PAINTING)));
219 }
220
221 return true;
222 }
223
224 public void b(NBTTagCompound nbttagcompound) {
225 nbttagcompound.a("Dir", (byte) this.a);
226 nbttagcompound.setString("Motive", this.e.A);
227 nbttagcompound.a("TileX", this.b);
228 nbttagcompound.a("TileY", this.c);
229 nbttagcompound.a("TileZ", this.d);
230 }
231
232 public void a(NBTTagCompound nbttagcompound) {
233 this.a = nbttagcompound.c("Dir");
234 this.b = nbttagcompound.e("TileX");
235 this.c = nbttagcompound.e("TileY");
236 this.d = nbttagcompound.e("TileZ");
237 String s = nbttagcompound.getString("Motive");
238 EnumArt[] aenumart = EnumArt.values();
239 int i = aenumart.length;
240
241 for (int j = 0; j < i; ++j) {
242 EnumArt enumart = aenumart[j];
243
244 if (enumart.A.equals(s)) {
245
246 // uberbukkit - make paintings show just the motives that exist in the target version
247 if (enumart == EnumArt.BURNINGSKULL && Uberbukkit.getTargetPVN() < 8) break;
248
249 this.e = enumart;
250 }
251 }
252
253 if (this.e == null) {
254 this.e = EnumArt.KEBAB;
255 }
256
257 this.b(this.a);
258 }
259
260 public void a(double d0, double d1, double d2) {
261 if (!this.world.isStatic && d0 * d0 + d1 * d1 + d2 * d2 > 0.0D) {
262 this.die();
263 this.world.addEntity(new EntityItem(this.world, this.locX, this.locY, this.locZ, new ItemStack(Item.PAINTING)));
264 }
265 }
266
267 public void b(double d0, double d1, double d2) {
268 if (!this.world.isStatic && d0 * d0 + d1 * d1 + d2 * d2 > 0.0D) {
269 this.die();
270 this.world.addEntity(new EntityItem(this.world, this.locX, this.locY, this.locZ, new ItemStack(Item.PAINTING)));
271 }
272 }
273}