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

312 lines
12 KiB
Diff

--- ../src-base/minecraft/net/minecraft/entity/Entity.java
+++ ../src-work/minecraft/net/minecraft/entity/Entity.java
@@ -128,6 +128,14 @@
private final CommandResultStats field_174837_as;
private static final String __OBFID = "CL_00001533";
+ /** 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 UUID persistentID;
+
+ protected java.util.HashMap<String, net.minecraftforge.common.IExtendedEntityProperties> extendedProperties = new java.util.HashMap<String, net.minecraftforge.common.IExtendedEntityProperties>();
+
public int func_145782_y()
{
return this.field_145783_c;
@@ -171,6 +179,8 @@
this.field_70180_af.func_75682_a(2, "");
this.field_70180_af.func_75682_a(4, Byte.valueOf((byte)0));
this.func_70088_a();
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.EntityEvent.EntityConstructing(this));
+ for (net.minecraftforge.common.IExtendedEntityProperties props : extendedProperties.values()) props.init(this, p_i1582_1_);
}
protected abstract void func_70088_a();
@@ -1010,10 +1020,7 @@
if (block.func_149688_o() == 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
{
@@ -1378,6 +1385,21 @@
p_70109_1_.func_74757_a("Silent", this.func_174814_R());
}
+ if (customEntityData != null) p_70109_1_.func_74782_a("ForgeData", customEntityData);
+ for (String identifier : this.extendedProperties.keySet())
+ {
+ try
+ {
+ net.minecraftforge.common.IExtendedEntityProperties props = this.extendedProperties.get(identifier);
+ props.saveNBTData(p_70109_1_);
+ }
+ catch (Throwable t)
+ {
+ net.minecraftforge.fml.common.FMLLog.severe("Failed to save extended properties for %s. This is a mod issue.", identifier);
+ t.printStackTrace();
+ }
+ }
+
this.func_70014_b(p_70109_1_);
if (this.field_70154_o != null)
@@ -1458,6 +1480,28 @@
this.func_174805_g(p_70020_1_.func_74767_n("CustomNameVisible"));
this.field_174837_as.func_179668_a(p_70020_1_);
this.func_174810_b(p_70020_1_.func_74767_n("Silent"));
+
+ if (p_70020_1_.func_74764_b("ForgeData")) customEntityData = p_70020_1_.func_74775_l("ForgeData");
+ for (String identifier : this.extendedProperties.keySet())
+ {
+ try
+ {
+ net.minecraftforge.common.IExtendedEntityProperties props = this.extendedProperties.get(identifier);
+ props.loadNBTData(p_70020_1_);
+ }
+ catch (Throwable t)
+ {
+ net.minecraftforge.fml.common.FMLLog.severe("Failed to load extended properties for %s. This is a mod issue.", identifier);
+ t.printStackTrace();
+ }
+ }
+
+ //Rawr, legacy code, Vanilla added a UUID, keep this so older maps will convert properly
+ if (p_70020_1_.func_74764_b("PersistentIDMSB") && p_70020_1_.func_74764_b("PersistentIDLSB"))
+ {
+ this.field_96093_i = new UUID(p_70020_1_.func_74763_f("PersistentIDMSB"), p_70020_1_.func_74763_f("PersistentIDLSB"));
+ }
+
this.func_70037_a(p_70020_1_);
if (this.func_142008_O())
@@ -1536,7 +1580,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;
}
else
@@ -1672,6 +1719,7 @@
public void func_70078_a(Entity p_70078_1_)
{
+ if(!(this instanceof EntityLivingBase) && !net.minecraftforge.event.ForgeEventFactory.canMountEntity(this, p_70078_1_, true)){ return; }
this.field_70149_e = 0.0D;
this.field_70147_f = 0.0D;
@@ -1810,7 +1858,7 @@
public boolean func_70115_ae()
{
- return this.field_70154_o != null;
+ return this.field_70154_o != null && field_70154_o.shouldRiderSit();
}
public boolean func_70093_af()
@@ -2103,7 +2151,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_.func_177963_a(0, func_70047_e(), 0), 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_)
@@ -2357,4 +2405,183 @@
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, Null if nothing should be added.
+ */
+ public ItemStack getPickedResult(MovingObjectPosition 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 == null)
+ {
+ 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(net.minecraft.init.Items.field_151124_az);
+ }
+ else if (this instanceof net.minecraft.entity.item.EntityArmorStand)
+ {
+ return new ItemStack(net.minecraft.init.Items.field_179565_cj);
+ }
+ else
+ {
+ int id = EntityList.func_75619_a(this);
+ if (id > 0 && EntityList.field_75627_a.containsKey(id))
+ {
+ return new ItemStack(net.minecraft.init.Items.field_151063_bx, 1, id);
+ }
+ String name = EntityList.func_75621_b(this);
+ if (name != null && net.minecraftforge.fml.common.registry.EntityRegistry.getEggs().containsKey(name))
+ {
+ ItemStack stack = new ItemStack(net.minecraft.init.Items.field_151063_bx);
+ stack.func_77983_a("entity_name", new net.minecraft.nbt.NBTTagString(name));
+ return stack;
+ }
+ }
+ return null;
+ }
+
+ 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)
+ {
+ return type.func_75598_a().isAssignableFrom(this.getClass());
+ }
+
+ /**
+ * Register the instance of IExtendedProperties into the entity's collection.
+ * @param identifier The identifier which you can use to retrieve these properties for the entity.
+ * @param properties The instanceof IExtendedProperties to register
+ * @return The identifier that was used to register the extended properties. Empty String indicates an error. If your requested key already existed, this will return a modified one that is unique.
+ */
+ public String registerExtendedProperties(String identifier, net.minecraftforge.common.IExtendedEntityProperties properties)
+ {
+ if (identifier == null)
+ {
+ net.minecraftforge.fml.common.FMLLog.warning("Someone is attempting to register extended properties using a null identifier. This is not allowed. Aborting. This may have caused instability.");
+ return "";
+ }
+ if (properties == null)
+ {
+ net.minecraftforge.fml.common.FMLLog.warning("Someone is attempting to register null extended properties. This is not allowed. Aborting. This may have caused instability.");
+ return "";
+ }
+
+ String baseIdentifier = identifier;
+ int identifierModCount = 1;
+ while (this.extendedProperties.containsKey(identifier))
+ {
+ identifier = String.format("%s%d", baseIdentifier, identifierModCount++);
+ }
+
+ if (baseIdentifier != identifier)
+ {
+ net.minecraftforge.fml.common.FMLLog.info("An attempt was made to register exended properties using an existing key. The duplicate identifier (%s) has been remapped to %s.", baseIdentifier, identifier);
+ }
+
+ this.extendedProperties.put(identifier, properties);
+ return identifier;
+ }
+
+ /**
+ * Gets the extended properties identified by the passed in key
+ * @param identifier The key that identifies the extended properties.
+ * @return The instance of IExtendedProperties that was found, or null.
+ */
+ public net.minecraftforge.common.IExtendedEntityProperties getExtendedProperties(String identifier)
+ {
+ return this.extendedProperties.get(identifier);
+ }
+
+ /**
+ * 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;
+ }
+ /* ================================== Forge End =====================================*/
}