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

200 lines
6.9 KiB
Diff

--- ../src_base/minecraft/net/minecraft/entity/Entity.java
+++ ../src_work/minecraft/net/minecraft/entity/Entity.java
@@ -2,6 +2,7 @@
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
+import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.UUID;
@@ -13,8 +14,13 @@
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.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagDouble;
@@ -25,6 +31,7 @@
import net.minecraft.util.DamageSource;
import net.minecraft.util.Direction;
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;
@@ -225,6 +232,11 @@
private boolean invulnerable;
private UUID field_96093_i;
public EnumEntitySize myEntitySize;
+ /** 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;
public Entity(World par1World)
{
@@ -547,7 +559,7 @@
if (!this.worldObj.isRemote)
{
this.setFlag(0, this.fire > 0);
- this.setFlag(2, this.ridingEntity != null);
+ this.setFlag(2, this.ridingEntity != null && ridingEntity.shouldRiderSit());
}
this.firstUpdate = false;
@@ -1527,6 +1539,10 @@
par1NBTTagCompound.setInteger("PortalCooldown", this.timeUntilPortal);
par1NBTTagCompound.setLong("UUIDMost", this.field_96093_i.getMostSignificantBits());
par1NBTTagCompound.setLong("UUIDLeast", this.field_96093_i.getLeastSignificantBits());
+ if (customEntityData != null)
+ {
+ par1NBTTagCompound.setCompoundTag("ForgeData", customEntityData);
+ }
this.writeEntityToNBT(par1NBTTagCompound);
if (this.ridingEntity != null)
@@ -1597,6 +1613,15 @@
this.setPosition(this.posX, this.posY, this.posZ);
this.setRotation(this.rotationYaw, this.rotationPitch);
+ if (par1NBTTagCompound.hasKey("ForgeData"))
+ {
+ customEntityData = par1NBTTagCompound.getCompoundTag("ForgeData");
+ }
+ //Rawr, legacy code, Vanilla added a UUID, keep this so older maps will convert properly
+ if (par1NBTTagCompound.hasKey("PersistentIDMSB") && par1NBTTagCompound.hasKey("PersistentIDLSB"))
+ {
+ this.field_96093_i = new UUID(par1NBTTagCompound.getLong("PersistentIDMSB"), par1NBTTagCompound.getLong("PersistentIDLSB"));
+ }
this.readEntityFromNBT(par1NBTTagCompound);
}
catch (Throwable throwable)
@@ -1691,7 +1716,14 @@
{
EntityItem entityitem = new EntityItem(this.worldObj, this.posX, this.posY + (double)par2, this.posZ, par1ItemStack);
entityitem.delayBeforeCanPickup = 10;
- this.worldObj.spawnEntityInWorld(entityitem);
+ if (captureDrops)
+ {
+ capturedDrops.add(entityitem);
+ }
+ else
+ {
+ this.worldObj.spawnEntityInWorld(entityitem);
+ }
return entityitem;
}
@@ -2049,7 +2081,7 @@
*/
public boolean isRiding()
{
- return this.ridingEntity != null || this.getFlag(2);
+ return (this.ridingEntity != null && ridingEntity.shouldRiderSit()) || this.getFlag(2);
}
/**
@@ -2393,7 +2425,7 @@
public float func_82146_a(Explosion par1Explosion, World par2World, int par3, int par4, int par5, Block par6Block)
{
- return par6Block.getExplosionResistance(this);
+ return par6Block.getExplosionResistance(this, par2World, par3, par4, par5, posX, posY + (double)getEyeHeight(), posZ);
}
public boolean func_96091_a(Explosion par1Explosion, World par2World, int par3, int par4, int par5, int par6, float par7)
@@ -2448,4 +2480,84 @@
{
return this.getEntityName();
}
+
+ /* ================================== 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(Item.painting);
+ }
+ else if (this instanceof EntityMinecart)
+ {
+ return ((EntityMinecart)this).getCartItem();
+ }
+ else if (this instanceof EntityBoat)
+ {
+ return new ItemStack(Item.boat);
+ }
+ else if (this instanceof EntityItemFrame)
+ {
+ ItemStack held = ((EntityItemFrame)this).getDisplayedItem();
+ if (held == null)
+ {
+ return new ItemStack(Item.itemFrame);
+ }
+ else
+ {
+ return held.copy();
+ }
+ }
+ else
+ {
+ int id = EntityList.getEntityID(this);
+ if (id > 0 && EntityList.entityEggs.containsKey(id))
+ {
+ return new ItemStack(Item.monsterPlacer, 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.entityId = nextEntityID++;
+ }
}