1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
--- ../work/decompile-8eb82bde//net/minecraft/server/EntityHanging.java Mon Dec 15 15:33:27 2014
+++ src/main/java/net/minecraft/server/EntityHanging.java Mon Dec 15 15:33:27 2014
@@ -4,6 +4,13 @@
import java.util.List;
import org.apache.commons.lang3.Validate;
+// CraftBukkit start
+import org.bukkit.entity.Hanging;
+import org.bukkit.entity.Painting;
+import org.bukkit.event.hanging.HangingBreakEvent;
+import org.bukkit.event.painting.PaintingBreakEvent;
+// CraftBukkit end
+
public abstract class EntityHanging extends Entity {
private int c;
@@ -30,30 +37,35 @@
this.o();
}
- private void o() {
- if (this.direction != null) {
- double d0 = (double) this.blockPosition.getX() + 0.5D;
- double d1 = (double) this.blockPosition.getY() + 0.5D;
- double d2 = (double) this.blockPosition.getZ() + 0.5D;
+ /* CraftBukkit start - bounding box calculation made static (for spawn usage)
+
+ l is from function l()
+ m is from function m()
+
+ Placing here as it's more likely to be noticed as something which needs to be updated
+ then something in a CraftBukkit file.
+ */
+ public static AxisAlignedBB calculateBoundingBox(BlockPosition blockPosition, EnumDirection direction, int width, int height) {
+ double d0 = (double) blockPosition.getX() + 0.5D;
+ double d1 = (double) blockPosition.getY() + 0.5D;
+ double d2 = (double) blockPosition.getZ() + 0.5D;
double d3 = 0.46875D;
- double d4 = this.a(this.l());
- double d5 = this.a(this.m());
+ double d4 = width % 32 == 0 ? 0.5D : 0.0D;
+ double d5 = height % 32 == 0 ? 0.5D : 0.0D;
- d0 -= (double) this.direction.getAdjacentX() * 0.46875D;
- d2 -= (double) this.direction.getAdjacentZ() * 0.46875D;
+ d0 -= (double) direction.getAdjacentX() * 0.46875D;
+ d2 -= (double) direction.getAdjacentZ() * 0.46875D;
d1 += d5;
- EnumDirection enumdirection = this.direction.f();
+ EnumDirection enumdirection = direction.f();
d0 += d4 * (double) enumdirection.getAdjacentX();
d2 += d4 * (double) enumdirection.getAdjacentZ();
- this.locX = d0;
- this.locY = d1;
- this.locZ = d2;
- double d6 = (double) this.l();
- double d7 = (double) this.m();
- double d8 = (double) this.l();
- if (this.direction.k() == EnumAxis.Z) {
+ double d6 = (double) width;
+ double d7 = (double) height;
+ double d8 = (double) width;
+
+ if (direction.k() == EnumAxis.Z) {
d8 = 1.0D;
} else {
d6 = 1.0D;
@@ -62,7 +74,20 @@
d6 /= 32.0D;
d7 /= 32.0D;
d8 /= 32.0D;
- this.a(new AxisAlignedBB(d0 - d6, d1 - d7, d2 - d8, d0 + d6, d1 + d7, d2 + d8));
+ return new AxisAlignedBB(d0 - d6, d1 - d7, d2 - d8, d0 + d6, d1 + d7, d2 + d8);
+ }
+ // CraftBukkit end
+
+ // PAIL: rename
+ private void o() {
+ if (this.direction != null) {
+ // CraftBukkit start code moved in to calculateBoundingBox
+ AxisAlignedBB bb = calculateBoundingBox(this.blockPosition,this.direction,this.l(),this.m());
+ this.locX = (bb.a + bb.d) / 2.0D;
+ this.locY = (bb.b + bb.e) / 2.0D;
+ this.locZ = (bb.c + bb.f) / 2.0D;
+ this.a(bb);
+ // CraftBukkit end
}
}
@@ -77,6 +102,33 @@
if (this.c++ == 100 && !this.world.isStatic) {
this.c = 0;
if (!this.dead && !this.survives()) {
+ // CraftBukkit start - fire break events
+ Material material = this.world.getType(new BlockPosition(this)).getBlock().getMaterial();
+ HangingBreakEvent.RemoveCause cause;
+
+ if (!material.equals(Material.AIR)) {
+ // TODO: This feels insufficient to catch 100% of suffocation cases
+ cause = HangingBreakEvent.RemoveCause.OBSTRUCTION;
+ } else {
+ cause = HangingBreakEvent.RemoveCause.PHYSICS;
+ }
+
+ HangingBreakEvent event = new HangingBreakEvent((Hanging) this.getBukkitEntity(), cause);
+ this.world.getServer().getPluginManager().callEvent(event);
+
+ PaintingBreakEvent paintingEvent = null;
+ if (this instanceof EntityPainting) {
+ // Fire old painting event until it can be removed
+ paintingEvent = new PaintingBreakEvent((Painting) this.getBukkitEntity(), PaintingBreakEvent.RemoveCause.valueOf(cause.name()));
+ paintingEvent.setCancelled(event.isCancelled());
+ this.world.getServer().getPluginManager().callEvent(paintingEvent);
+ }
+
+ if (dead || event.isCancelled() || (paintingEvent != null && paintingEvent.isCancelled())) {
+ return;
+ }
+ // CraftBukkit end
+
this.die();
this.b((Entity) null);
}
@@ -138,6 +190,32 @@
return false;
} else {
if (!this.dead && !this.world.isStatic) {
+ // CraftBukkit start - fire break events
+ HangingBreakEvent event = new HangingBreakEvent((Hanging) this.getBukkitEntity(), HangingBreakEvent.RemoveCause.DEFAULT);
+ PaintingBreakEvent paintingEvent = null;
+ if (damagesource.getEntity() != null) {
+ event = new org.bukkit.event.hanging.HangingBreakByEntityEvent((Hanging) this.getBukkitEntity(), damagesource.getEntity() == null ? null : damagesource.getEntity().getBukkitEntity());
+
+ if (this instanceof EntityPainting) {
+ // Fire old painting event until it can be removed
+ paintingEvent = new org.bukkit.event.painting.PaintingBreakByEntityEvent((Painting) this.getBukkitEntity(), damagesource.getEntity() == null ? null : damagesource.getEntity().getBukkitEntity());
+ }
+ } else if (damagesource.isExplosion()) {
+ event = new HangingBreakEvent((Hanging) this.getBukkitEntity(), HangingBreakEvent.RemoveCause.EXPLOSION);
+ }
+
+ this.world.getServer().getPluginManager().callEvent(event);
+
+ if (paintingEvent != null) {
+ paintingEvent.setCancelled(event.isCancelled());
+ this.world.getServer().getPluginManager().callEvent(paintingEvent);
+ }
+
+ if (this.dead || event.isCancelled() || (paintingEvent != null && paintingEvent.isCancelled())) {
+ return true;
+ }
+ // CraftBukkit end
+
this.die();
this.ac();
this.b(damagesource.getEntity());
@@ -149,6 +227,18 @@
public void move(double d0, double d1, double d2) {
if (!this.world.isStatic && !this.dead && d0 * d0 + d1 * d1 + d2 * d2 > 0.0D) {
+ if (this.dead) return; // CraftBukkit
+
+ // CraftBukkit start - fire break events
+ // TODO - Does this need its own cause? Seems to only be triggered by pistons
+ HangingBreakEvent event = new HangingBreakEvent((Hanging) this.getBukkitEntity(), HangingBreakEvent.RemoveCause.PHYSICS);
+ this.world.getServer().getPluginManager().callEvent(event);
+
+ if (this.dead || event.isCancelled()) {
+ return;
+ }
+ // CraftBukkit end
+
this.die();
this.b((Entity) null);
}
@@ -156,7 +246,7 @@
}
public void g(double d0, double d1, double d2) {
- if (!this.world.isStatic && !this.dead && d0 * d0 + d1 * d1 + d2 * d2 > 0.0D) {
+ if (false && !this.world.isStatic && !this.dead && d0 * d0 + d1 * d1 + d2 * d2 > 0.0D) { // CraftBukkit - not needed
this.die();
this.b((Entity) null);
}
|