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

215 lines
10 KiB
Diff
Raw Normal View History

--- 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 LOGGER = LogManager.getLogger();
private static final List<ItemStack> EMPTY_EQUIPMENT = Collections.<ItemStack>emptyList();
private static final AxisAlignedBB ZERO_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D);
@@ -210,7 +210,7 @@
this.world = p_i48580_2_;
this.setPosition(0.0D, 0.0D, 0.0D);
if (p_i48580_2_ != null) {
- this.dimension = p_i48580_2_.provider.getDimensionType().getId();
+ this.dimension = p_i48580_2_.provider.getId();
}
this.dataManager = new EntityDataManager(this);
@@ -221,6 +221,8 @@
this.dataManager.register(SILENT, false);
this.dataManager.register(NO_GRAVITY, false);
this.entityInit();
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.EntityEvent.EntityConstructing(this));
+ this.gatherCapabilities();
}
public EntityType<?> func_200600_R() {
@@ -845,7 +847,7 @@
protected void playStepSound(BlockPos pos, IBlockState blockIn) {
if (!blockIn.getMaterial().isLiquid()) {
- SoundType soundtype = this.world.getBlockState(pos.up()).getBlock() == Blocks.SNOW ? Blocks.SNOW.getSoundType() : blockIn.getBlock().getSoundType();
+ SoundType soundtype = this.world.getBlockState(pos.up()).getBlock() == Blocks.SNOW ? Blocks.SNOW.getSoundType() : blockIn.getSoundType(world, pos, this);
this.playSound(soundtype.getStepSound(), soundtype.getVolume() * 0.15F, soundtype.getPitch());
}
}
@@ -1040,6 +1042,7 @@
int k = MathHelper.floor(this.posZ);
BlockPos blockpos = new BlockPos(i, j, k);
IBlockState iblockstate = this.world.getBlockState(blockpos);
+ if (!iblockstate.addRunningEffects(world, blockpos, this))
if (iblockstate.getRenderType() != EnumBlockRenderType.INVISIBLE) {
this.world.func_195594_a(new BlockParticleData(Particles.field_197611_d, iblockstate), this.posX + ((double)this.rand.nextFloat() - 0.5D) * (double)this.width, this.getEntityBoundingBox().minY + 0.1D, this.posZ + ((double)this.rand.nextFloat() - 0.5D) * (double)this.width, -this.motionX * 4.0D, 1.5D, -this.motionZ * 4.0D);
}
@@ -1053,7 +1056,7 @@
double d0 = this.posY + (double)this.getEyeHeight();
BlockPos blockpos = new BlockPos(this.posX, d0, this.posZ);
IFluidState ifluidstate = this.world.func_204610_c(blockpos);
- return ifluidstate.func_206884_a(p_208600_1_) && d0 < (double)((float)blockpos.getY() + ifluidstate.func_206885_f() + 0.11111111F);
+ return ifluidstate.isEntityInside(world, blockpos, this, d0, p_208600_1_, true);
}
}
@@ -1370,6 +1373,7 @@
if (this.glowing) {
compound.setBoolean("Glowing", this.glowing);
}
+ compound.setBoolean("CanUpdate", canUpdate);
if (!this.tags.isEmpty()) {
NBTTagList nbttaglist = new NBTTagList();
@@ -1381,6 +1385,9 @@
compound.setTag("Tags", nbttaglist);
}
+ NBTTagCompound caps = serializeCaps();
+ if (caps != null) compound.setTag("ForgeCaps", caps);
+
this.writeEntityToNBT(compound);
if (this.isBeingRidden()) {
NBTTagList nbttaglist1 = new NBTTagList();
@@ -1466,6 +1473,8 @@
this.setSilent(compound.getBoolean("Silent"));
this.setNoGravity(compound.getBoolean("NoGravity"));
this.setGlowing(compound.getBoolean("Glowing"));
+ if (compound.hasKey("CanUpdate", 99)) this.canUpdate(compound.getBoolean("CanUpdate"));
+ if (compound.hasKey("ForgeCaps", 10)) deserializeCaps(compound.getCompoundTag("ForgeCaps"));
if (compound.hasKey("Tags", 9)) {
this.tags.clear();
NBTTagList nbttaglist1 = compound.getTagList("Tags", 8);
@@ -1546,6 +1555,8 @@
} else {
EntityItem entityitem = new EntityItem(this.world, this.posX, this.posY + (double)offsetY, this.posZ, stack);
entityitem.setDefaultPickupDelay();
+ if (captureDrops() != null) captureDrops().add(entityitem);
+ else
this.world.spawnEntity(entityitem);
return entityitem;
}
@@ -1595,6 +1606,7 @@
this.motionX = 0.0D;
this.motionY = 0.0D;
this.motionZ = 0.0D;
+ if (canUpdate())
this.onUpdate();
if (this.isRiding()) {
entity.updatePassenger(this);
@@ -1636,6 +1648,7 @@
}
}
+ if (!net.minecraftforge.event.ForgeEventFactory.canMountEntity(this, entityIn, true)) return false;
if (force || this.canBeRidden(entityIn) && entityIn.canFitPassenger(this)) {
if (this.isRiding()) {
this.dismountRidingEntity();
@@ -1663,6 +1676,7 @@
public void dismountRidingEntity() {
if (this.ridingEntity != null) {
Entity entity = this.ridingEntity;
+ if (!net.minecraftforge.event.ForgeEventFactory.canMountEntity(this, entity, false)) return;
this.ridingEntity = null;
entity.removePassenger(this);
}
@@ -2053,6 +2067,14 @@
@Nullable
public Entity changeDimension(int dimensionIn) {
+ if (this.world.isRemote || this.isDead) return null;
+ return changeDimension(dimensionIn, this.getServer().getWorld(dimensionIn).getDefaultTeleporter());
+ }
+
+ @Nullable // Forge: Entities that require custom handling should override this method, not the other
+ public Entity changeDimension(int dimensionIn, net.minecraftforge.common.util.ITeleporter teleporter)
+ {
+ if (!net.minecraftforge.common.ForgeHooks.onTravelToDimension(this, dimensionIn)) return null;
if (!this.world.isRemote && !this.isDead) {
this.world.profiler.startSection("changeDimension");
MinecraftServer minecraftserver = this.getServer();
@@ -2060,7 +2082,7 @@
WorldServer worldserver = minecraftserver.getWorld(i);
WorldServer worldserver1 = minecraftserver.getWorld(dimensionIn);
this.dimension = dimensionIn;
- if (i == 1 && dimensionIn == 1) {
+ if (i == 1 && dimensionIn == 1 && teleporter.isVanilla()) {
worldserver1 = minecraftserver.func_200667_a(DimensionType.OVERWORLD);
this.dimension = 0;
}
@@ -2069,16 +2091,17 @@
this.isDead = false;
this.world.profiler.startSection("reposition");
BlockPos blockpos;
- if (dimensionIn == 1) {
+ if (dimensionIn == 1 && teleporter.isVanilla()) {
blockpos = worldserver1.getSpawnCoordinate();
} else {
- double d0 = this.posX;
- double d1 = this.posZ;
+ double moveFactor = worldserver.provider.getMovementFactor() / worldserver1.provider.getMovementFactor();
+ double d0 = MathHelper.clamp(this.posX * moveFactor, worldserver1.getWorldBorder().minX() + 16.0D, worldserver1.getWorldBorder().maxX() - 16.0D);
+ double d1 = MathHelper.clamp(this.posZ * moveFactor, worldserver1.getWorldBorder().minZ() + 16.0D, worldserver1.getWorldBorder().maxZ() - 16.0D);
double d2 = 8.0D;
- if (dimensionIn == -1) {
+ if (false && dimensionIn == -1) {
d0 = MathHelper.clamp(d0 / 8.0D, worldserver1.getWorldBorder().minX() + 16.0D, worldserver1.getWorldBorder().maxX() - 16.0D);
d1 = MathHelper.clamp(d1 / 8.0D, worldserver1.getWorldBorder().minZ() + 16.0D, worldserver1.getWorldBorder().maxZ() - 16.0D);
- } else if (dimensionIn == 0) {
+ } else if (false && dimensionIn == 0) {
d0 = MathHelper.clamp(d0 * 8.0D, worldserver1.getWorldBorder().minX() + 16.0D, worldserver1.getWorldBorder().maxX() - 16.0D);
d1 = MathHelper.clamp(d1 * 8.0D, worldserver1.getWorldBorder().minZ() + 16.0D, worldserver1.getWorldBorder().maxZ() - 16.0D);
}
@@ -2087,8 +2110,7 @@
d1 = (double)MathHelper.clamp((int)d1, -29999872, 29999872);
float f = this.rotationYaw;
this.setLocationAndAngles(d0, this.posY, d1, 90.0F, 0.0F);
- Teleporter teleporter = worldserver1.getDefaultTeleporter();
- teleporter.placeInExistingPortal(this, f);
+ teleporter.placeEntity(worldserver1, this, f);
blockpos = new BlockPos(this);
}
@@ -2097,7 +2119,7 @@
Entity entity = this.func_200600_R().func_200721_a(worldserver1);
if (entity != null) {
entity.copyDataFromOld(this);
- if (i == 1 && dimensionIn == 1) {
+ if (i == 1 && dimensionIn == 1 && teleporter.isVanilla()) {
BlockPos blockpos1 = worldserver1.func_205770_a(Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, worldserver1.getSpawnPoint());
entity.moveToBlockPosAndAngles(blockpos1, entity.rotationYaw, entity.rotationPitch);
} else {
@@ -2591,4 +2613,32 @@
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 world.rand.nextFloat() < fallDistance - 0.5F
+ && this instanceof EntityLivingBase
+ && (this instanceof EntityPlayer || net.minecraftforge.event.ForgeEventFactory.getMobGriefingEvent(world, this))
+ && this.width * this.width * this.height > 0.512F;
+ }
}