Files
MinecraftForge/patches/minecraft/net/minecraft/entity/Entity.java.patch
T
VikeStep 026d179c0d Add EntityTravelToDimensionEvent
Resolve Merge Conflict

Move event call inside conditional
2016-01-25 17:57:52 +10:00

361 lines
15 KiB
Diff

--- ../src-base/minecraft/net/minecraft/entity/Entity.java
+++ ../src-work/minecraft/net/minecraft/entity/Entity.java
@@ -49,7 +49,7 @@
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
-public abstract class Entity implements ICommandSender
+public abstract class Entity implements ICommandSender, net.minecraftforge.common.capabilities.ICapabilitySerializable<NBTTagCompound>
{
private static final AxisAlignedBB field_174836_a = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D);
private static int field_70152_a;
@@ -129,6 +129,15 @@
protected UUID field_96093_i;
private final CommandResultStats field_174837_as;
+ /** 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>();
+
+ @Deprecated //ToDo: Move to Capabilities?
+ protected java.util.HashMap<String, net.minecraftforge.common.IExtendedEntityProperties> extendedProperties = new java.util.HashMap<String, net.minecraftforge.common.IExtendedEntityProperties>();
+ private net.minecraftforge.common.capabilities.CapabilityDispatcher capabilities;
+
public int func_145782_y()
{
return this.field_145783_c;
@@ -172,6 +181,9 @@
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_);
+ capabilities = net.minecraftforge.event.ForgeEventFactory.gatherCapabilities(this);
}
protected abstract void func_70088_a();
@@ -998,10 +1010,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
{
@@ -1356,6 +1365,23 @@
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();
+ }
+ }
+
+ if (this.capabilities != null) p_70109_1_.func_74782_a("ForgeCaps", this.capabilities.serializeNBT());
+
this.func_70014_b(p_70109_1_);
if (this.field_70154_o != null)
@@ -1438,6 +1464,30 @@
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 TODO: Remove in 1.9
+ 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"));
+ }
+
+ if (this.capabilities != null && p_70020_1_.func_74764_b("ForgeCaps")) this.capabilities.deserializeNBT(p_70020_1_.func_74775_l("ForgeCaps"));
+
this.func_70037_a(p_70020_1_);
if (this.func_142008_O())
@@ -1512,7 +1562,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
@@ -1655,6 +1708,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;
@@ -1789,7 +1843,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()
@@ -2049,6 +2103,7 @@
{
if (!this.field_70170_p.field_72995_K && !this.field_70128_L)
{
+ if (!net.minecraftforge.common.ForgeHooks.onTravelToDimension(this, p_71027_1_)) return;
this.field_70170_p.field_72984_F.func_76320_a("changeDimension");
MinecraftServer minecraftserver = MinecraftServer.func_71276_C();
int i = this.field_71093_bK;
@@ -2092,7 +2147,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_)
@@ -2353,4 +2408,209 @@
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)
+ {
+ if (forSpawnCount && (this instanceof EntityLiving) && ((EntityLiving)this).func_104002_bU()) return false;
+ 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;
+ }
+
+ public boolean hasCapability(net.minecraftforge.common.capabilities.Capability<?> capability, net.minecraft.util.EnumFacing facing)
+ {
+ if (getCapability(capability, facing) != null)
+ return true;
+ return capabilities == null ? false : capabilities.hasCapability(capability, facing);
+ }
+
+ public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, 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());
+ this.func_70109_d(ret);
+ return ret;
+ }
+ /* ================================== Forge End =====================================*/
}