ForgePatch/patches/minecraft/net/minecraft/entity/Entity.java.patch

272 lines
14 KiB
Diff

--- a/net/minecraft/entity/Entity.java
+++ b/net/minecraft/entity/Entity.java
@@ -97,7 +97,7 @@
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 implements INameable, ICommandSource, net.minecraftforge.common.extensions.IForgeEntity {
protected static final Logger field_184243_a = LogManager.getLogger();
private static final List<ItemStack> field_190535_b = Collections.<ItemStack>emptyList();
private static final AxisAlignedBB field_174836_a = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D);
@@ -210,7 +210,7 @@
this.field_70170_p = p_i48580_2_;
this.func_70107_b(0.0D, 0.0D, 0.0D);
if (p_i48580_2_ != null) {
- this.field_71093_bK = p_i48580_2_.field_73011_w.func_186058_p().func_186068_a();
+ this.field_71093_bK = p_i48580_2_.field_73011_w.getId();
}
this.field_70180_af = new EntityDataManager(this);
@@ -221,6 +221,8 @@
this.field_70180_af.func_187214_a(field_184234_aB, false);
this.field_70180_af.func_187214_a(field_189655_aD, false);
this.func_70088_a();
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.EntityEvent.EntityConstructing(this));
+ this.gatherCapabilities();
}
public EntityType<?> func_200600_R() {
@@ -324,6 +326,7 @@
this.field_70165_t = p_70107_1_;
this.field_70163_u = p_70107_3_;
this.field_70161_v = p_70107_5_;
+ if (this.isAddedToWorld() && !this.field_70170_p.field_72995_K) this.field_70170_p.func_72866_a(this, false); // Forge - Process chunk registration after moving.
float f = this.field_70130_N / 2.0F;
float f1 = this.field_70131_O;
this.func_174826_a(new AxisAlignedBB(p_70107_1_ - (double)f, p_70107_3_, p_70107_5_ - (double)f, p_70107_1_ + (double)f, p_70107_3_ + (double)f1, p_70107_5_ + (double)f));
@@ -794,6 +797,7 @@
this.field_70165_t = (axisalignedbb.field_72340_a + axisalignedbb.field_72336_d) / 2.0D;
this.field_70163_u = axisalignedbb.field_72338_b;
this.field_70161_v = (axisalignedbb.field_72339_c + axisalignedbb.field_72334_f) / 2.0D;
+ if (this.isAddedToWorld() && !this.field_70170_p.field_72995_K) this.field_70170_p.func_72866_a(this, false); // Forge - Process chunk registration after moving.
}
protected SoundEvent func_184184_Z() {
@@ -845,7 +849,7 @@
protected void func_180429_a(BlockPos p_180429_1_, IBlockState p_180429_2_) {
if (!p_180429_2_.func_185904_a().func_76224_d()) {
- SoundType soundtype = this.field_70170_p.func_180495_p(p_180429_1_.func_177984_a()).func_177230_c() == Blocks.field_150433_aE ? Blocks.field_150433_aE.func_185467_w() : p_180429_2_.func_177230_c().func_185467_w();
+ SoundType soundtype = this.field_70170_p.func_180495_p(p_180429_1_.func_177984_a()).func_177230_c() == Blocks.field_150433_aE ? Blocks.field_150433_aE.func_185467_w() : 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());
}
}
@@ -1040,6 +1044,7 @@
int k = MathHelper.func_76128_c(this.field_70161_v);
BlockPos blockpos = new BlockPos(i, j, k);
IBlockState iblockstate = this.field_70170_p.func_180495_p(blockpos);
+ if (!iblockstate.addRunningEffects(field_70170_p, blockpos, this))
if (iblockstate.func_185901_i() != EnumBlockRenderType.INVISIBLE) {
this.field_70170_p.func_195594_a(new BlockParticleData(Particles.field_197611_d, iblockstate), this.field_70165_t + ((double)this.field_70146_Z.nextFloat() - 0.5D) * (double)this.field_70130_N, this.func_174813_aQ().field_72338_b + 0.1D, this.field_70161_v + ((double)this.field_70146_Z.nextFloat() - 0.5D) * (double)this.field_70130_N, -this.field_70159_w * 4.0D, 1.5D, -this.field_70179_y * 4.0D);
}
@@ -1053,7 +1058,7 @@
double d0 = this.field_70163_u + (double)this.func_70047_e();
BlockPos blockpos = new BlockPos(this.field_70165_t, d0, this.field_70161_v);
IFluidState ifluidstate = this.field_70170_p.func_204610_c(blockpos);
- return ifluidstate.func_206884_a(p_208600_1_) && d0 < (double)((float)blockpos.func_177956_o() + ifluidstate.func_206885_f() + 0.11111111F);
+ return ifluidstate.isEntityInside(field_70170_p, blockpos, this, d0, p_208600_1_, true);
}
}
@@ -1122,6 +1127,7 @@
this.field_70126_B -= 360.0F;
}
+ if (!this.field_70170_p.field_72995_K) this.field_70170_p.func_72964_e((int) Math.floor(this.field_70165_t) >> 4, (int) Math.floor(this.field_70161_v) >> 4); // Forge - ensure target chunk is loaded.
this.func_70107_b(this.field_70165_t, this.field_70163_u, this.field_70161_v);
this.func_70101_b(p_70080_7_, p_70080_8_);
}
@@ -1370,6 +1376,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()) {
NBTTagList nbttaglist = new NBTTagList();
@@ -1381,6 +1388,9 @@
p_189511_1_.func_74782_a("Tags", nbttaglist);
}
+ NBTTagCompound caps = serializeCaps();
+ if (caps != null) p_189511_1_.func_74782_a("ForgeCaps", caps);
+
this.func_70014_b(p_189511_1_);
if (this.func_184207_aI()) {
NBTTagList nbttaglist1 = new NBTTagList();
@@ -1466,6 +1476,8 @@
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("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();
NBTTagList nbttaglist1 = p_70020_1_.func_150295_c("Tags", 8);
@@ -1546,6 +1558,8 @@
} else {
EntityItem entityitem = new EntityItem(this.field_70170_p, this.field_70165_t, this.field_70163_u + (double)p_70099_2_, this.field_70161_v, p_70099_1_);
entityitem.func_174869_p();
+ if (captureDrops() != null) captureDrops().add(entityitem);
+ else
this.field_70170_p.func_72838_d(entityitem);
return entityitem;
}
@@ -1595,6 +1609,7 @@
this.field_70159_w = 0.0D;
this.field_70181_x = 0.0D;
this.field_70179_y = 0.0D;
+ if (canUpdate())
this.func_70071_h_();
if (this.func_184218_aH()) {
entity.func_184232_k(this);
@@ -1636,6 +1651,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();
@@ -1663,6 +1679,7 @@
public void func_184210_p() {
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);
}
@@ -1789,10 +1806,15 @@
return !this.func_184188_bt().isEmpty();
}
+ @Deprecated //Forge: Use rider sensitive version
public boolean func_205710_ba() {
return true;
}
+ public boolean canBeRiddenInWater(Entity rider) {
+ return func_205710_ba();
+ }
+
public boolean func_70093_af() {
return this.func_70083_f(1);
}
@@ -2053,6 +2075,14 @@
@Nullable
public Entity func_184204_a(int p_184204_1_) {
+ if (this.field_70170_p.field_72995_K || this.field_70128_L) return null;
+ return changeDimension(p_184204_1_, this.func_184102_h().func_71218_a(p_184204_1_).func_85176_s());
+ }
+
+ @Nullable // Forge: Entities that require custom handling should override this method, not the other
+ public Entity changeDimension(int p_184204_1_, net.minecraftforge.common.util.ITeleporter teleporter)
+ {
+ if (!net.minecraftforge.common.ForgeHooks.onTravelToDimension(this, p_184204_1_)) return null;
if (!this.field_70170_p.field_72995_K && !this.field_70128_L) {
this.field_70170_p.field_72984_F.func_76320_a("changeDimension");
MinecraftServer minecraftserver = this.func_184102_h();
@@ -2060,7 +2090,7 @@
WorldServer worldserver = minecraftserver.func_71218_a(i);
WorldServer worldserver1 = minecraftserver.func_71218_a(p_184204_1_);
this.field_71093_bK = p_184204_1_;
- if (i == 1 && p_184204_1_ == 1) {
+ if (i == 1 && p_184204_1_ == 1 && teleporter.isVanilla()) {
worldserver1 = minecraftserver.func_200667_a(DimensionType.OVERWORLD);
this.field_71093_bK = 0;
}
@@ -2069,16 +2099,17 @@
this.field_70128_L = false;
this.field_70170_p.field_72984_F.func_76320_a("reposition");
BlockPos blockpos;
- if (p_184204_1_ == 1) {
+ if (p_184204_1_ == 1 && teleporter.isVanilla()) {
blockpos = worldserver1.func_180504_m();
} else {
- double d0 = this.field_70165_t;
- double d1 = this.field_70161_v;
+ double moveFactor = worldserver.field_73011_w.getMovementFactor() / worldserver1.field_73011_w.getMovementFactor();
+ double d0 = MathHelper.func_151237_a(this.field_70165_t * moveFactor, worldserver1.func_175723_af().func_177726_b() + 16.0D, worldserver1.func_175723_af().func_177728_d() - 16.0D);
+ double d1 = MathHelper.func_151237_a(this.field_70161_v * moveFactor, worldserver1.func_175723_af().func_177736_c() + 16.0D, worldserver1.func_175723_af().func_177733_e() - 16.0D);
double d2 = 8.0D;
- if (p_184204_1_ == -1) {
+ if (false && p_184204_1_ == -1) {
d0 = MathHelper.func_151237_a(d0 / 8.0D, worldserver1.func_175723_af().func_177726_b() + 16.0D, worldserver1.func_175723_af().func_177728_d() - 16.0D);
d1 = MathHelper.func_151237_a(d1 / 8.0D, worldserver1.func_175723_af().func_177736_c() + 16.0D, worldserver1.func_175723_af().func_177733_e() - 16.0D);
- } else if (p_184204_1_ == 0) {
+ } else if (false && p_184204_1_ == 0) {
d0 = MathHelper.func_151237_a(d0 * 8.0D, worldserver1.func_175723_af().func_177726_b() + 16.0D, worldserver1.func_175723_af().func_177728_d() - 16.0D);
d1 = MathHelper.func_151237_a(d1 * 8.0D, worldserver1.func_175723_af().func_177736_c() + 16.0D, worldserver1.func_175723_af().func_177733_e() - 16.0D);
}
@@ -2087,8 +2118,7 @@
d1 = (double)MathHelper.func_76125_a((int)d1, -29999872, 29999872);
float f = this.field_70177_z;
this.func_70012_b(d0, this.field_70163_u, d1, 90.0F, 0.0F);
- Teleporter teleporter = worldserver1.func_85176_s();
- teleporter.func_180620_b(this, f);
+ teleporter.placeEntity(worldserver1, this, f);
blockpos = new BlockPos(this);
}
@@ -2097,7 +2127,7 @@
Entity entity = this.func_200600_R().func_200721_a(worldserver1);
if (entity != null) {
entity.func_180432_n(this);
- if (i == 1 && p_184204_1_ == 1) {
+ if (i == 1 && p_184204_1_ == 1 && teleporter.isVanilla()) {
BlockPos blockpos1 = worldserver1.func_205770_a(Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, worldserver1.func_175694_M());
entity.func_174828_a(blockpos1, entity.field_70177_z, entity.field_70125_A);
} else {
@@ -2591,4 +2621,49 @@
public double func_212107_bY() {
return this.field_211517_W;
}
+
+ private boolean canUpdate = false;
+ @Override
+ public void canUpdate(boolean value) {
+ this.canUpdate = value;
+ }
+ @Override
+ public boolean canUpdate() {
+ return this.canUpdate;
+ }
+ private Collection<EntityItem> captureDrops = null;
+ @Override
+ public Collection<EntityItem> captureDrops() {
+ return captureDrops;
+ }
+ @Override
+ public Collection<EntityItem> captureDrops(Collection<EntityItem> value) {
+ Collection<EntityItem> ret = captureDrops;
+ this.captureDrops = value;
+ return ret;
+ }
+ @Override
+ public boolean canTrample(IBlockState state, BlockPos pos, float fallDistance) {
+ return field_70170_p.field_73012_v.nextFloat() < fallDistance - 0.5F
+ && this instanceof EntityLivingBase
+ && (this instanceof EntityPlayer || net.minecraftforge.event.ForgeEventFactory.getMobGriefingEvent(field_70170_p, this))
+ && this.field_70130_N * this.field_70130_N * this.field_70131_O > 0.512F;
+ }
+
+ /* ================================== Forge Start =====================================*/
+ /**
+ * 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; }
}