Files
MinecraftForge/patches/minecraft/net/minecraft/entity/Entity.java.patch
T
2014-06-23 21:55:16 -07:00

373 lines
14 KiB
Diff

--- ../src-base/minecraft/net/minecraft/entity/Entity.java
+++ ../src-work/minecraft/net/minecraft/entity/Entity.java
@@ -1,7 +1,10 @@
package net.minecraft.entity;
+import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Random;
import java.util.UUID;
@@ -13,9 +16,14 @@
import net.minecraft.crash.CrashReportCategory;
import net.minecraft.enchantment.EnchantmentProtection;
import net.minecraft.entity.effect.EntityLightningBolt;
+import net.minecraft.entity.item.EntityBoat;
import net.minecraft.entity.item.EntityItem;
+import net.minecraft.entity.item.EntityItemFrame;
+import net.minecraft.entity.item.EntityMinecart;
+import net.minecraft.entity.item.EntityPainting;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
+import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -30,12 +38,17 @@
import net.minecraft.util.Direction;
import net.minecraft.util.IChatComponent;
import net.minecraft.util.MathHelper;
+import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.ReportedException;
import net.minecraft.util.StatCollector;
import net.minecraft.util.Vec3;
import net.minecraft.world.Explosion;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
+import net.minecraftforge.common.IExtendedEntityProperties;
+import net.minecraftforge.common.MinecraftForge;
+import net.minecraftforge.event.entity.EntityEvent;
+import net.minecraftforge.fluids.IFluidBlock;
public abstract class Entity
{
@@ -116,7 +129,14 @@
protected UUID field_96093_i;
public Entity.EnumEntitySize field_70168_am;
private static final String __OBFID = "CL_00001533";
+ /** Forge: Used to store custom data for each entity. */
+ private NBTTagCompound customEntityData;
+ public boolean captureDrops = false;
+ public ArrayList<EntityItem> capturedDrops = new ArrayList<EntityItem>();
+ private UUID persistentID;
+ protected HashMap<String, IExtendedEntityProperties> extendedProperties;
+
public int func_145782_y()
{
return this.field_145783_c;
@@ -153,6 +173,15 @@
this.field_70180_af.func_75682_a(0, Byte.valueOf((byte)0));
this.field_70180_af.func_75682_a(1, Short.valueOf((short)300));
this.func_70088_a();
+
+ extendedProperties = new HashMap<String, IExtendedEntityProperties>();
+
+ MinecraftForge.EVENT_BUS.post(new EntityEvent.EntityConstructing(this));
+
+ for (IExtendedEntityProperties props : this.extendedProperties.values())
+ {
+ props.init(this, p_i1582_1_);
+ }
}
protected abstract void func_70088_a();
@@ -991,9 +1020,22 @@
if (block.func_149688_o() == p_70055_1_)
{
- float f = BlockLiquid.func_149801_b(this.field_70170_p.func_72805_g(i, j, k)) - 0.11111111F;
- float f1 = (float)(j + 1) - f;
- return d0 < (double)f1;
+ double filled = 1.0f; //If it's not a liquid assume it's a solid block
+ if (block instanceof IFluidBlock)
+ {
+ filled = ((IFluidBlock)block).getFilledPercentage(field_70170_p, i, j, k);
+ }
+
+ if (filled < 0)
+ {
+ filled *= -1;
+ //filled -= 0.11111111F; //Why this is needed.. not sure...
+ return d0 > (double)(j + (1 - filled));
+ }
+ else
+ {
+ return d0 < (double)(j + filled);
+ }
}
else
{
@@ -1278,8 +1320,27 @@
p_70109_1_.func_74768_a("PortalCooldown", this.field_71088_bW);
p_70109_1_.func_74772_a("UUIDMost", this.func_110124_au().getMostSignificantBits());
p_70109_1_.func_74772_a("UUIDLeast", this.func_110124_au().getLeastSignificantBits());
- this.func_70014_b(p_70109_1_);
+ if (customEntityData != null)
+ {
+ p_70109_1_.func_74782_a("ForgeData", customEntityData);
+ }
+ for (String identifier : this.extendedProperties.keySet())
+ {
+ try
+ {
+ IExtendedEntityProperties props = this.extendedProperties.get(identifier);
+ props.saveNBTData(p_70109_1_);
+ }
+ catch (Throwable t)
+ {
+ 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)
{
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
@@ -1345,6 +1406,30 @@
this.func_70107_b(this.field_70165_t, this.field_70163_u, this.field_70161_v);
this.func_70101_b(this.field_70177_z, this.field_70125_A);
+ if (p_70020_1_.func_74764_b("ForgeData"))
+ {
+ customEntityData = p_70020_1_.func_74775_l("ForgeData");
+ }
+
+ for (String identifier : this.extendedProperties.keySet())
+ {
+ try
+ {
+ IExtendedEntityProperties props = this.extendedProperties.get(identifier);
+ props.loadNBTData(p_70020_1_);
+ }
+ catch (Throwable t)
+ {
+ 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())
@@ -1423,7 +1508,14 @@
{
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.field_145804_b = 10;
- this.field_70170_p.func_72838_d(entityitem);
+ if (captureDrops)
+ {
+ capturedDrops.add(entityitem);
+ }
+ else
+ {
+ this.field_70170_p.func_72838_d(entityitem);
+ }
return entityitem;
}
else
@@ -1687,7 +1779,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()
@@ -1988,7 +2080,7 @@
public float func_145772_a(Explosion p_145772_1_, World p_145772_2_, int p_145772_3_, int p_145772_4_, int p_145772_5_, Block p_145772_6_)
{
- return p_145772_6_.func_149638_a(this);
+ return p_145772_6_.getExplosionResistance(this, p_145772_2_, p_145772_3_, p_145772_4_, p_145772_5_, field_70165_t, field_70163_u + func_70047_e(), field_70161_v);
}
public boolean func_145774_a(Explosion p_145774_1_, World p_145774_2_, int p_145774_3_, int p_145774_4_, int p_145774_5_, Block p_145774_6_, float p_145774_7_)
@@ -2058,6 +2150,174 @@
public void func_145781_i(int p_145781_1_) {}
+ /* ================================== 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 EntityPainting)
+ {
+ return new ItemStack(Items.field_151159_an);
+ }
+ else if (this instanceof EntityLeashKnot)
+ {
+ return new ItemStack(Items.field_151058_ca);
+ }
+ else if (this instanceof EntityItemFrame)
+ {
+ ItemStack held = ((EntityItemFrame)this).func_82335_i();
+ if (held == null)
+ {
+ return new ItemStack(Items.field_151160_bD);
+ }
+ else
+ {
+ return held.func_77946_l();
+ }
+ }
+ else if (this instanceof EntityMinecart)
+ {
+ return ((EntityMinecart)this).getCartItem();
+ }
+ else if (this instanceof EntityBoat)
+ {
+ return new ItemStack(Items.field_151124_az);
+ }
+ else
+ {
+ int id = EntityList.func_75619_a(this);
+ if (id > 0 && EntityList.field_75627_a.containsKey(id))
+ {
+ return new ItemStack(Items.field_151063_bx, 1, id);
+ }
+ }
+ 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, IExtendedEntityProperties properties)
+ {
+ if (identifier == null)
+ {
+ 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)
+ {
+ 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)
+ {
+ 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 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 =====================================*/
+
public static enum EnumEntitySize
{
SIZE_1,