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

314 lines
13 KiB
Diff

--- ../src-base/minecraft/net/minecraft/entity/Entity.java
+++ ../src-work/minecraft/net/minecraft/entity/Entity.java
@@ -83,7 +83,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-public abstract class Entity implements ICommandSender
+public abstract class Entity implements ICommandSender, net.minecraftforge.common.capabilities.ICapabilitySerializable<NBTTagCompound>
{
private static final Logger field_184243_a = LogManager.getLogger();
private static final List<ItemStack> field_190535_b = Collections.<ItemStack>emptyList();
@@ -193,7 +193,7 @@
if (p_i1582_1_ != null)
{
- this.field_71093_bK = p_i1582_1_.field_73011_w.func_186058_p().func_186068_a();
+ this.field_71093_bK = p_i1582_1_.field_73011_w.getDimension();
}
this.field_70180_af = new EntityDataManager(this);
@@ -204,8 +204,16 @@
this.field_70180_af.func_187214_a(field_184234_aB, Boolean.valueOf(false));
this.field_70180_af.func_187214_a(field_189655_aD, Boolean.valueOf(false));
this.func_70088_a();
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.EntityEvent.EntityConstructing(this));
+ capabilities = net.minecraftforge.event.ForgeEventFactory.gatherCapabilities(this);
}
+ /** Forge: Used to store custom data for each entity. */
+ private NBTTagCompound customEntityData;
+ public boolean captureDrops = false;
+ public java.util.ArrayList<EntityItem> capturedDrops = new java.util.ArrayList<EntityItem>();
+ private net.minecraftforge.common.capabilities.CapabilityDispatcher capabilities;
+
public int func_145782_y()
{
return this.field_145783_c;
@@ -976,7 +984,7 @@
protected void func_180429_a(BlockPos p_180429_1_, Block p_180429_2_)
{
- SoundType soundtype = p_180429_2_.func_185467_w();
+ SoundType soundtype = p_180429_2_.getSoundType(field_70170_p.func_180495_p(p_180429_1_), field_70170_p, p_180429_1_, this);
if (this.field_70170_p.func_180495_p(p_180429_1_.func_177984_a()).func_177230_c() == Blocks.field_150431_aC)
{
@@ -1183,12 +1191,12 @@
BlockPos blockpos = new BlockPos(this.field_70165_t, d0, this.field_70161_v);
IBlockState iblockstate = this.field_70170_p.func_180495_p(blockpos);
+ Boolean result = iblockstate.func_177230_c().isEntityInsideMaterial(this.field_70170_p, blockpos, iblockstate, this, d0, p_70055_1_, true);
+ if (result != null) return result;
+
if (iblockstate.func_185904_a() == p_70055_1_)
{
- float f = BlockLiquid.func_149801_b(iblockstate.func_177230_c().func_176201_c(iblockstate)) - 0.11111111F;
- float f1 = (float)(blockpos.func_177956_o() + 1) - f;
- boolean flag = d0 < (double)f1;
- return !flag && this instanceof EntityPlayer ? false : flag;
+ return net.minecraftforge.common.ForgeHooks.isInsideOfMaterial(p_70055_1_, this, blockpos);
}
else
{
@@ -1620,6 +1628,9 @@
p_189511_1_.func_74782_a("Tags", nbttaglist);
}
+ if (customEntityData != null) p_189511_1_.func_74782_a("ForgeData", customEntityData);
+ if (this.capabilities != null) p_189511_1_.func_74782_a("ForgeCaps", this.capabilities.serializeNBT());
+
this.func_70014_b(p_189511_1_);
if (this.func_184207_aI())
@@ -1727,6 +1738,9 @@
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_74764_b("ForgeData")) customEntityData = p_70020_1_.func_74775_l("ForgeData");
+ if (this.capabilities != null && p_70020_1_.func_74764_b("ForgeCaps")) this.capabilities.deserializeNBT(p_70020_1_.func_74775_l("ForgeCaps"));
+
if (p_70020_1_.func_150297_b("Tags", 9))
{
this.field_184236_aF.clear();
@@ -1818,7 +1832,10 @@
{
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();
- this.field_70170_p.func_72838_d(entityitem);
+ if (captureDrops)
+ this.capturedDrops.add(entityitem);
+ else
+ this.field_70170_p.func_72838_d(entityitem);
return entityitem;
}
}
@@ -1932,6 +1949,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())
@@ -1967,6 +1985,7 @@
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);
}
@@ -2412,6 +2431,7 @@
{
if (!this.field_70170_p.field_72995_K && !this.field_70128_L)
{
+ if (!net.minecraftforge.common.ForgeHooks.onTravelToDimension(this, p_184204_1_)) return null;
this.field_70170_p.field_72984_F.func_76320_a("changeDimension");
MinecraftServer minecraftserver = this.func_184102_h();
int i = this.field_71093_bK;
@@ -2505,7 +2525,7 @@
public float func_180428_a(Explosion p_180428_1_, World p_180428_2_, BlockPos p_180428_3_, IBlockState p_180428_4_)
{
- return p_180428_4_.func_177230_c().func_149638_a(this);
+ return p_180428_4_.func_177230_c().getExplosionResistance(p_180428_2_, p_180428_3_, this, p_180428_1_);
}
public boolean func_174816_a(Explosion p_174816_1_, World p_174816_2_, BlockPos p_174816_3_, IBlockState p_174816_4_, float p_174816_5_)
@@ -2802,6 +2822,184 @@
EnchantmentHelper.func_151385_b(p_174815_1_, p_174815_2_);
}
+ /* ================================== Forge Start =====================================*/
+ /**
+ * Returns a NBTTagCompound that can be used to store custom data for this entity.
+ * It will be written, and read from disc, so it persists over world saves.
+ * @return A NBTTagCompound
+ */
+ public NBTTagCompound getEntityData()
+ {
+ if (customEntityData == null)
+ {
+ customEntityData = new NBTTagCompound();
+ }
+ return customEntityData;
+ }
+
+ /**
+ * Used in model rendering to determine if the entity riding this entity should be in the 'sitting' position.
+ * @return false to prevent an entity that is mounted to this entity from displaying the 'sitting' animation.
+ */
+ public boolean shouldRiderSit()
+ {
+ return true;
+ }
+
+ /**
+ * Called when a user uses the creative pick block button on this entity.
+ *
+ * @param target The full target the player is looking at
+ * @return A ItemStack to add to the player's inventory, empty ItemStack if nothing should be added.
+ */
+ public ItemStack getPickedResult(RayTraceResult target)
+ {
+ if (this instanceof net.minecraft.entity.item.EntityPainting)
+ {
+ return new ItemStack(net.minecraft.init.Items.field_151159_an);
+ }
+ else if (this instanceof EntityLeashKnot)
+ {
+ return new ItemStack(net.minecraft.init.Items.field_151058_ca);
+ }
+ else if (this instanceof net.minecraft.entity.item.EntityItemFrame)
+ {
+ ItemStack held = ((net.minecraft.entity.item.EntityItemFrame)this).func_82335_i();
+ if (held.func_190926_b())
+ {
+ return new ItemStack(net.minecraft.init.Items.field_151160_bD);
+ }
+ else
+ {
+ return held.func_77946_l();
+ }
+ }
+ else if (this instanceof net.minecraft.entity.item.EntityMinecart)
+ {
+ return ((net.minecraft.entity.item.EntityMinecart)this).getCartItem();
+ }
+ else if (this instanceof net.minecraft.entity.item.EntityBoat)
+ {
+ return new ItemStack(((EntityBoat)this).func_184455_j());
+ }
+ else if (this instanceof net.minecraft.entity.item.EntityArmorStand)
+ {
+ return new ItemStack(net.minecraft.init.Items.field_179565_cj);
+ }
+ else if (this instanceof net.minecraft.entity.item.EntityEnderCrystal)
+ {
+ return new ItemStack(net.minecraft.init.Items.field_185158_cP);
+ }
+ else
+ {
+ ResourceLocation name = EntityList.func_191301_a(this);
+ if (name != null && EntityList.field_75627_a.containsKey(name))
+ {
+ ItemStack stack = new ItemStack(net.minecraft.init.Items.field_151063_bx);
+ net.minecraft.item.ItemMonsterPlacer.func_185078_a(stack, name);
+ return stack;
+ }
+ }
+ return ItemStack.field_190927_a;
+ }
+
+ public UUID getPersistentID()
+ {
+ return field_96093_i;
+ }
+
+ /**
+ * Reset the entity ID to a new value. Not to be used from Mod code
+ */
+ public final void resetEntityId()
+ {
+ this.field_145783_c = field_70152_a++;
+ }
+
+ public boolean shouldRenderInPass(int pass)
+ {
+ return pass == 0;
+ }
+
+ /**
+ * Returns true if the entity is of the @link{EnumCreatureType} provided
+ * @param type The EnumCreatureType type this entity is evaluating
+ * @param forSpawnCount If this is being invoked to check spawn count caps.
+ * @return If the creature is of the type provided
+ */
+ public boolean isCreatureType(EnumCreatureType type, boolean forSpawnCount)
+ {
+ if (forSpawnCount && (this instanceof EntityLiving) && ((EntityLiving)this).func_104002_bU()) return false;
+ return type.func_75598_a().isAssignableFrom(this.getClass());
+ }
+
+ /**
+ * If a rider of this entity can interact with this entity. Should return true on the
+ * ridden entity if so.
+ *
+ * @return if the entity can be interacted with from a rider
+ */
+ public boolean canRiderInteract()
+ {
+ return false;
+ }
+
+ /**
+ * If the rider should be dismounted from the entity when the entity goes under water
+ *
+ * @param rider The entity that is riding
+ * @return if the entity should be dismounted when under water
+ */
+ public boolean shouldDismountInWater(Entity rider)
+ {
+ return this instanceof EntityLivingBase;
+ }
+
+ @Override
+ public boolean hasCapability(net.minecraftforge.common.capabilities.Capability<?> capability, @Nullable net.minecraft.util.EnumFacing facing)
+ {
+ if (getCapability(capability, facing) != null)
+ return true;
+ return capabilities == null ? false : capabilities.hasCapability(capability, facing);
+ }
+
+ @Override
+ @Nullable
+ public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, @Nullable net.minecraft.util.EnumFacing facing)
+ {
+ return capabilities == null ? null : capabilities.getCapability(capability, facing);
+ }
+
+ public void deserializeNBT(NBTTagCompound nbt)
+ {
+ this.func_70020_e(nbt);
+ }
+
+ public NBTTagCompound serializeNBT()
+ {
+ NBTTagCompound ret = new NBTTagCompound();
+ ret.func_74778_a("id", this.func_70022_Q());
+ return this.func_189511_e(ret);
+ }
+
+ /**
+ * Checks if this {@link Entity} can trample a {@link Block}.
+ *
+ * @param world The world in which the block will be trampled
+ * @param block The block being tested
+ * @param pos The block pos
+ * @param fallDistance The fall distance
+ * @return {@code true} if this entity can trample, {@code false} otherwise
+ */
+ public boolean canTrample(World world, Block block, BlockPos pos, float fallDistance)
+ {
+ return world.field_73012_v.nextFloat() < fallDistance - 0.5F
+ && this instanceof EntityLivingBase
+ && (this instanceof EntityPlayer || world.func_82736_K().func_82766_b("mobGriefing"))
+ && this.field_70130_N * this.field_70130_N * this.field_70131_O > 0.512F;
+ }
+ /* ================================== Forge End =====================================*/
+
public void func_184178_b(EntityPlayerMP p_184178_1_)
{
}