forked from MinecraftForge/MinecraftForge
/
Entity.java.patch
346 lines (324 loc) · 17.7 KB
/
Entity.java.patch
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
--- a/net/minecraft/entity/Entity.java
+++ b/net/minecraft/entity/Entity.java
@@ -109,12 +109,13 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-public abstract class Entity implements INameable, ICommandSource {
+public abstract class Entity extends net.minecraftforge.common.capabilities.CapabilityProvider<Entity> implements INameable, ICommandSource, net.minecraftforge.common.extensions.IForgeEntity {
protected static final Logger field_184243_a = LogManager.getLogger();
private static final AtomicInteger field_213331_b = new AtomicInteger();
private static final List<ItemStack> field_190535_b = Collections.emptyList();
private static final AxisAlignedBB field_174836_a = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D);
private static double field_70155_l = 1.0D;
+ @Deprecated // Forge: Use the getter to allow overriding in mods
private final EntityType<?> field_200606_g;
private int field_145783_c = field_213331_b.incrementAndGet();
public boolean field_70156_m;
@@ -140,6 +141,7 @@
public boolean field_70124_G;
public boolean field_70133_I;
protected Vector3d field_213328_B = Vector3d.field_186680_a;
+ @Deprecated //Forge: Use isAlive, remove(boolean) and revive() instead of directly accessing this field. To allow the entity to react to and better control this information.
public boolean field_70128_L;
public float field_70141_P;
public float field_70140_Q;
@@ -195,6 +197,7 @@
private float field_213326_aJ;
public Entity(EntityType<?> p_i48580_1_, World p_i48580_2_) {
+ super(Entity.class);
this.field_200606_g = p_i48580_1_;
this.field_70170_p = p_i48580_2_;
this.field_213325_aI = p_i48580_1_.func_220334_j();
@@ -211,7 +214,11 @@
this.field_70180_af.func_187214_a(field_189655_aD, false);
this.field_70180_af.func_187214_a(field_213330_X, Pose.STANDING);
this.func_70088_a();
- this.field_213326_aJ = this.func_213316_a(Pose.STANDING, this.field_213325_aI);
+ net.minecraftforge.event.entity.EntityEvent.Size sizeEvent = net.minecraftforge.event.ForgeEventFactory.getEntitySizeForge(this, Pose.STANDING, this.field_213325_aI, this.func_213316_a(Pose.STANDING, this.field_213325_aI));
+ this.field_213325_aI = sizeEvent.getNewSize();
+ this.field_213326_aJ = sizeEvent.getNewEyeHeight();
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.EntityEvent.EntityConstructing(this));
+ this.gatherCapabilities();
}
@OnlyIn(Dist.CLIENT)
@@ -317,7 +324,13 @@
}
public void func_70106_y() {
+ this.remove(false);
+ }
+
+ public void remove(boolean keepData) {
this.field_70128_L = true;
+ if (!keepData)
+ this.invalidateCaps();
}
public void func_213301_b(Pose p_213301_1_) {
@@ -330,6 +343,7 @@
public boolean func_233562_a_(Entity p_233562_1_, double p_233562_2_) {
double d0 = p_233562_1_.field_233557_ao_.field_72450_a - this.field_233557_ao_.field_72450_a;
+ if (this.isAddedToWorld() && !this.field_70170_p.field_72995_K && field_70170_p instanceof ServerWorld) ((ServerWorld)this.field_70170_p).func_217464_b(this); // Forge - Process chunk registration after moving.
double d1 = p_233562_1_.field_233557_ao_.field_72448_b - this.field_233557_ao_.field_72448_b;
double d2 = p_233562_1_.field_233557_ao_.field_72449_c - this.field_233557_ao_.field_72449_c;
return d0 * d0 + d1 * d1 + d2 * d2 < p_233562_2_ * p_233562_2_;
@@ -560,7 +574,7 @@
this.field_70140_Q = (float)((double)this.field_70140_Q + (double)MathHelper.func_76133_a(func_213296_b(vector3d)) * 0.6D);
this.field_82151_R = (float)((double)this.field_82151_R + (double)MathHelper.func_76133_a(d0 * d0 + d1 * d1 + d2 * d2) * 0.6D);
- if (this.field_82151_R > this.field_70150_b && !blockstate.func_196958_f()) {
+ if (this.field_82151_R > this.field_70150_b && !blockstate.isAir(this.field_70170_p, blockpos)) {
this.field_70150_b = this.func_203009_ad();
if (this.func_70090_H()) {
Entity entity = this.func_184207_aI() && this.func_184179_bs() != null ? this.func_184179_bs() : this;
@@ -575,7 +589,7 @@
} else {
this.func_180429_a(blockpos, blockstate);
}
- } else if (this.field_82151_R > this.field_191959_ay && this.func_191957_ae() && blockstate.func_196958_f()) {
+ } else if (this.field_82151_R > this.field_191959_ay && this.func_191957_ae() && blockstate.isAir(this.field_70170_p, blockpos)) {
this.field_191959_ay = this.func_191954_d(this.field_82151_R);
}
}
@@ -591,8 +605,9 @@
float f2 = this.func_225515_ai_();
this.func_213317_d(this.func_213322_ci().func_216372_d((double)f2, 1.0D, (double)f2));
- if (this.field_70170_p.func_234939_c_(this.func_174813_aQ().func_186664_h(0.001D)).noneMatch((p_233572_0_) -> {
- return p_233572_0_.func_235714_a_(BlockTags.field_232872_am_) || p_233572_0_.func_203425_a(Blocks.field_150353_l);
+ if (BlockPos.func_239581_a_(this.func_174813_aQ().func_186664_h(0.001D)).noneMatch((p_233572_0_) -> {
+ BlockState state = field_70170_p.func_180495_p(p_233572_0_);
+ return state.func_235714_a_(BlockTags.field_232872_am_) || state.func_203425_a(Blocks.field_150353_l) || state.isBurning(field_70170_p, p_233572_0_);
}) && this.field_190534_ay <= 0) {
this.func_241209_g_(-this.func_190531_bD());
}
@@ -611,11 +626,10 @@
int j = MathHelper.func_76128_c(this.field_233557_ao_.field_72448_b - (double)0.2F);
int k = MathHelper.func_76128_c(this.field_233557_ao_.field_72449_c);
BlockPos blockpos = new BlockPos(i, j, k);
- if (this.field_70170_p.func_180495_p(blockpos).func_196958_f()) {
+ if (this.field_70170_p.func_175623_d(blockpos)) {
BlockPos blockpos1 = blockpos.func_177977_b();
BlockState blockstate = this.field_70170_p.func_180495_p(blockpos1);
- Block block = blockstate.func_177230_c();
- if (block.func_203417_a(BlockTags.field_219748_G) || block.func_203417_a(BlockTags.field_219757_z) || block instanceof FenceGateBlock) {
+ if (blockstate.collisionExtendsVertically(this.field_70170_p, blockpos1, this)) {
return blockpos1;
}
}
@@ -801,6 +815,7 @@
public void func_174829_m() {
AxisAlignedBB axisalignedbb = this.func_174813_aQ();
this.func_226288_n_((axisalignedbb.field_72340_a + axisalignedbb.field_72336_d) / 2.0D, axisalignedbb.field_72338_b, (axisalignedbb.field_72339_c + axisalignedbb.field_72334_f) / 2.0D);
+ if (this.isAddedToWorld() && !this.field_70170_p.field_72995_K && field_70170_p instanceof ServerWorld) ((ServerWorld)this.field_70170_p).func_217464_b(this); // Forge - Process chunk registration after moving.
}
protected SoundEvent func_184184_Z() {
@@ -849,7 +864,7 @@
protected void func_180429_a(BlockPos p_180429_1_, BlockState p_180429_2_) {
if (!p_180429_2_.func_185904_a().func_76224_d()) {
BlockState blockstate = this.field_70170_p.func_180495_p(p_180429_1_.func_177984_a());
- SoundType soundtype = blockstate.func_203425_a(Blocks.field_150433_aE) ? blockstate.func_215695_r() : p_180429_2_.func_215695_r();
+ SoundType soundtype = blockstate.func_203425_a(Blocks.field_150433_aE) ? blockstate.getSoundType(field_70170_p, p_180429_1_, this) : p_180429_2_.getSoundType(field_70170_p, p_180429_1_, this);
this.func_184185_a(soundtype.func_185844_d(), soundtype.func_185843_a() * 0.15F, soundtype.func_185847_b());
}
}
@@ -1056,9 +1071,10 @@
int k = MathHelper.func_76128_c(this.func_226281_cx_());
BlockPos blockpos = new BlockPos(i, j, k);
BlockState blockstate = this.field_70170_p.func_180495_p(blockpos);
+ if(!blockstate.addRunningEffects(field_70170_p, blockpos, this))
if (blockstate.func_185901_i() != BlockRenderType.INVISIBLE) {
Vector3d vector3d = this.func_213322_ci();
- this.field_70170_p.func_195594_a(new BlockParticleData(ParticleTypes.field_197611_d, blockstate), this.func_226277_ct_() + (this.field_70146_Z.nextDouble() - 0.5D) * (double)this.field_213325_aI.field_220315_a, this.func_226278_cu_() + 0.1D, this.func_226281_cx_() + (this.field_70146_Z.nextDouble() - 0.5D) * (double)this.field_213325_aI.field_220315_a, vector3d.field_72450_a * -4.0D, 1.5D, vector3d.field_72449_c * -4.0D);
+ this.field_70170_p.func_195594_a(new BlockParticleData(ParticleTypes.field_197611_d, blockstate).setPos(blockpos), this.func_226277_ct_() + (this.field_70146_Z.nextDouble() - 0.5D) * (double)this.field_213325_aI.field_220315_a, this.func_226278_cu_() + 0.1D, this.func_226281_cx_() + (this.field_70146_Z.nextDouble() - 0.5D) * (double)this.field_213325_aI.field_220315_a, vector3d.field_72450_a * -4.0D, 1.5D, vector3d.field_72449_c * -4.0D);
}
}
@@ -1377,6 +1393,7 @@
if (this.field_184238_ar) {
p_189511_1_.func_74757_a("Glowing", this.field_184238_ar);
}
+ p_189511_1_.func_74757_a("CanUpdate", canUpdate);
if (!this.field_184236_aF.isEmpty()) {
ListNBT listnbt = new ListNBT();
@@ -1388,6 +1405,10 @@
p_189511_1_.func_218657_a("Tags", listnbt);
}
+ CompoundNBT caps = serializeCaps();
+ if (caps != null) p_189511_1_.func_218657_a("ForgeCaps", caps);
+ if (persistentData != null) p_189511_1_.func_218657_a("ForgeData", persistentData);
+
this.func_213281_b(p_189511_1_);
if (this.func_184207_aI()) {
ListNBT listnbt1 = new ListNBT();
@@ -1458,6 +1479,9 @@
this.func_174810_b(p_70020_1_.func_74767_n("Silent"));
this.func_189654_d(p_70020_1_.func_74767_n("NoGravity"));
this.func_184195_f(p_70020_1_.func_74767_n("Glowing"));
+ if (p_70020_1_.func_150297_b("ForgeData", 10)) persistentData = p_70020_1_.func_74775_l("ForgeData");
+ if (p_70020_1_.func_150297_b("CanUpdate", 99)) this.canUpdate(p_70020_1_.func_74767_n("CanUpdate"));
+ if (p_70020_1_.func_150297_b("ForgeCaps", 10)) deserializeCaps(p_70020_1_.func_74775_l("ForgeCaps"));
if (p_70020_1_.func_150297_b("Tags", 9)) {
this.field_184236_aF.clear();
ListNBT listnbt3 = p_70020_1_.func_150295_c("Tags", 8);
@@ -1546,6 +1570,8 @@
} else {
ItemEntity itementity = new ItemEntity(this.field_70170_p, this.func_226277_ct_(), this.func_226278_cu_() + (double)p_70099_2_, this.func_226281_cx_(), p_70099_1_);
itementity.func_174869_p();
+ if (captureDrops() != null) captureDrops().add(itementity);
+ else
this.field_70170_p.func_217376_c(itementity);
return itementity;
}
@@ -1582,6 +1608,7 @@
public void func_70098_U() {
this.func_213317_d(Vector3d.field_186680_a);
+ if (canUpdate())
this.func_70071_h_();
if (this.func_184218_aH()) {
this.func_184187_bx().func_184232_k(this);
@@ -1627,6 +1654,7 @@
}
}
+ if (!net.minecraftforge.event.ForgeEventFactory.canMountEntity(this, p_184205_1_, true)) return false;
if (p_184205_2_ || this.func_184228_n(p_184205_1_) && p_184205_1_.func_184219_q(this)) {
if (this.func_184218_aH()) {
this.func_184210_p();
@@ -1659,6 +1687,7 @@
public void func_233575_bb_() {
if (this.field_184239_as != null) {
Entity entity = this.field_184239_as;
+ if (!net.minecraftforge.event.ForgeEventFactory.canMountEntity(this, entity, false)) return;
this.field_184239_as = null;
entity.func_184225_p(this);
}
@@ -1816,6 +1845,7 @@
return !this.func_184188_bt().isEmpty();
}
+ @Deprecated //Forge: Use rider sensitive version
public boolean func_205710_ba() {
return true;
}
@@ -2032,7 +2062,7 @@
}
protected ITextComponent func_225513_by_() {
- return this.field_200606_g.func_212546_e();
+ return this.func_200600_R().func_212546_e(); // Forge: Use getter to allow overriding by mods
}
public boolean func_70028_i(Entity p_70028_1_) {
@@ -2087,6 +2117,10 @@
@Nullable
public Entity func_241206_a_(ServerWorld p_241206_1_) {
+ return this.changeDimension(p_241206_1_, p_241206_1_.func_85176_s());
+ }
+ @Nullable
+ public Entity changeDimension(ServerWorld p_241206_1_, net.minecraftforge.common.util.ITeleporter teleporter) {
if (this.field_70170_p instanceof ServerWorld && !this.field_70128_L) {
this.field_70170_p.func_217381_Z().func_76320_a("changeDimension");
this.func_213319_R();
@@ -2095,6 +2129,7 @@
if (portalinfo == null) {
return null;
} else {
+ Entity transportedEntity = teleporter.placeEntity(this, (ServerWorld) this.field_70170_p, p_241206_1_, this.field_70177_z, spawnPortal -> { //Forge: Start vanilla logic
this.field_70170_p.func_217381_Z().func_219895_b("reloading");
Entity entity = this.func_200600_R().func_200721_a(p_241206_1_);
if (entity != null) {
@@ -2102,17 +2137,19 @@
entity.func_70012_b(portalinfo.field_222505_a.field_72450_a, portalinfo.field_222505_a.field_72448_b, portalinfo.field_222505_a.field_72449_c, portalinfo.field_242960_c, entity.field_70125_A);
entity.func_213317_d(portalinfo.field_222506_b);
p_241206_1_.func_217460_e(entity);
- if (p_241206_1_.func_234923_W_() == World.field_234920_i_) {
+ if (spawnPortal && p_241206_1_.func_234923_W_() == World.field_234920_i_) {
ServerWorld.func_241121_a_(p_241206_1_);
}
}
+ return entity;
+ }); //Forge: End vanilla logic
this.func_241204_bJ_();
this.field_70170_p.func_217381_Z().func_76319_b();
((ServerWorld)this.field_70170_p).func_82742_i();
p_241206_1_.func_82742_i();
this.field_70170_p.func_217381_Z().func_76319_b();
- return entity;
+ return transportedEntity;
}
} else {
return null;
@@ -2320,9 +2357,10 @@
public void func_213323_x_() {
EntitySize entitysize = this.field_213325_aI;
Pose pose = this.func_213283_Z();
- EntitySize entitysize1 = this.func_213305_a(pose);
+ net.minecraftforge.event.entity.EntityEvent.Size sizeEvent = net.minecraftforge.event.ForgeEventFactory.getEntitySizeForge(this, pose, this.func_213305_a(pose), this.func_213316_a(pose, entitysize));
+ EntitySize entitysize1 = sizeEvent.getNewSize();
this.field_213325_aI = entitysize1;
- this.field_213326_aJ = this.func_213316_a(pose, entitysize1);
+ this.field_213326_aJ = sizeEvent.getNewEyeHeight();
if (entitysize1.field_220315_a < entitysize.field_220315_a) {
double d0 = (double)entitysize1.field_220315_a / 2.0D;
this.func_174826_a(new AxisAlignedBB(this.func_226277_ct_() - d0, this.func_226278_cu_(), this.func_226281_cx_() - d0, this.func_226277_ct_() + d0, this.func_226278_cu_() + (double)entitysize1.field_220316_b, this.func_226281_cx_() + d0));
@@ -2796,6 +2834,7 @@
this.field_233555_aA_ = true;
}
+ if (this.isAddedToWorld() && !this.field_70170_p.field_72995_K && !this.field_70128_L) this.field_70170_p.func_212866_a_((int) Math.floor(p_226288_1_) >> 4, (int) Math.floor(p_226288_5_) >> 4); // Forge - ensure target chunk is loaded.
}
@@ -2811,4 +2850,63 @@
public interface IMoveCallback {
void accept(Entity p_accept_1_, double p_accept_2_, double p_accept_4_, double p_accept_6_);
}
+
+ /* ================================== Forge Start =====================================*/
+
+ private boolean canUpdate = true;
+ @Override
+ public void canUpdate(boolean value) {
+ this.canUpdate = value;
+ }
+ @Override
+ public boolean canUpdate() {
+ return this.canUpdate;
+ }
+ private Collection<ItemEntity> captureDrops = null;
+ @Override
+ public Collection<ItemEntity> captureDrops() {
+ return captureDrops;
+ }
+ @Override
+ public Collection<ItemEntity> captureDrops(Collection<ItemEntity> value) {
+ Collection<ItemEntity> ret = captureDrops;
+ this.captureDrops = value;
+ return ret;
+ }
+ private CompoundNBT persistentData;
+ @Override
+ public CompoundNBT getPersistentData() {
+ if (persistentData == null)
+ persistentData = new CompoundNBT();
+ return persistentData;
+ }
+ @Override
+ public boolean canTrample(BlockState state, BlockPos pos, float fallDistance) {
+ return field_70170_p.field_73012_v.nextFloat() < fallDistance - 0.5F
+ && this instanceof LivingEntity
+ && (this instanceof PlayerEntity || net.minecraftforge.event.ForgeEventFactory.getMobGriefingEvent(field_70170_p, this))
+ && this.func_213311_cf() * this.func_213311_cf() * this.func_213302_cg() > 0.512F;
+ }
+
+ /**
+ * Internal use for keeping track of entities that are tracked by a world, to
+ * allow guarantees that entity position changes will force a chunk load, avoiding
+ * potential issues with entity desyncing and bad chunk data.
+ */
+ private boolean isAddedToWorld;
+
+ @Override
+ public final boolean isAddedToWorld() { return this.isAddedToWorld; }
+
+ @Override
+ public void onAddedToWorld() { this.isAddedToWorld = true; }
+
+ @Override
+ public void onRemovedFromWorld() { this.isAddedToWorld = false; }
+
+ @Override
+ public void revive() {
+ this.field_70128_L = false;
+ this.reviveCaps();
+ }
}