mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 11:59:25 +00:00
269 lines
11 KiB
Diff
269 lines
11 KiB
Diff
--- ../src-base/minecraft/net/minecraft/entity/Entity.java
|
|
+++ ../src-work/minecraft/net/minecraft/entity/Entity.java
|
|
@@ -76,7 +76,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 AxisAlignedBB ZERO_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D);
|
|
@@ -195,8 +195,16 @@
|
|
this.dataWatcher.func_187214_a(field_184242_az, "");
|
|
this.dataWatcher.func_187214_a(field_184234_aB, Boolean.valueOf(false));
|
|
this.entityInit();
|
|
+ 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 getEntityId()
|
|
{
|
|
return this.entityId;
|
|
@@ -1134,12 +1142,12 @@
|
|
BlockPos blockpos = new BlockPos(this.posX, d0, this.posZ);
|
|
IBlockState iblockstate = this.worldObj.getBlockState(blockpos);
|
|
|
|
+ Boolean result = iblockstate.getBlock().isEntityInsideMaterial(iblockstate, this.worldObj, blockpos, iblockstate, this, d0, materialIn, true);
|
|
+ if (result != null) return result;
|
|
+
|
|
if (iblockstate.func_185904_a() == materialIn)
|
|
{
|
|
- float f = BlockLiquid.getLiquidHeightPercent(iblockstate.getBlock().getMetaFromState(iblockstate)) - 0.11111111F;
|
|
- float f1 = (float)(blockpos.getY() + 1) - f;
|
|
- boolean flag = d0 < (double)f1;
|
|
- return !flag && this instanceof EntityPlayer ? false : flag;
|
|
+ return net.minecraftforge.common.ForgeHooks.isInsideOfMaterial(materialIn, this, blockpos);
|
|
}
|
|
else
|
|
{
|
|
@@ -1534,6 +1542,9 @@
|
|
tagCompund.setTag("Tags", nbttaglist);
|
|
}
|
|
|
|
+ if (customEntityData != null) tagCompund.setTag("ForgeData", customEntityData);
|
|
+ if (this.capabilities != null) tagCompund.setTag("ForgeCaps", this.capabilities.serializeNBT());
|
|
+
|
|
this.writeEntityToNBT(tagCompund);
|
|
|
|
if (this.func_184207_aI())
|
|
@@ -1629,6 +1640,9 @@
|
|
this.setSilent(tagCompund.getBoolean("Silent"));
|
|
this.func_184195_f(tagCompund.getBoolean("Glowing"));
|
|
|
|
+ if (tagCompund.hasKey("ForgeData")) customEntityData = tagCompund.getCompoundTag("ForgeData");
|
|
+ if (this.capabilities != null && tagCompund.hasKey("ForgeCaps")) this.capabilities.deserializeNBT(tagCompund.getCompoundTag("ForgeCaps"));
|
|
+
|
|
if (tagCompund.hasKey("Tags", 9))
|
|
{
|
|
this.field_184236_aF.clear();
|
|
@@ -1715,7 +1729,10 @@
|
|
{
|
|
EntityItem entityitem = new EntityItem(this.worldObj, this.posX, this.posY + (double)offsetY, this.posZ, itemStackIn);
|
|
entityitem.setDefaultPickupDelay();
|
|
- this.worldObj.spawnEntityInWorld(entityitem);
|
|
+ if (captureDrops)
|
|
+ this.capturedDrops.add(entityitem);
|
|
+ else
|
|
+ this.worldObj.spawnEntityInWorld(entityitem);
|
|
return entityitem;
|
|
}
|
|
else
|
|
@@ -1824,6 +1841,7 @@
|
|
|
|
public boolean func_184205_a(Entity p_184205_1_, boolean p_184205_2_)
|
|
{
|
|
+ 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())
|
|
@@ -2279,6 +2297,7 @@
|
|
{
|
|
if (!this.worldObj.isRemote && !this.isDead)
|
|
{
|
|
+ if (!net.minecraftforge.common.ForgeHooks.onTravelToDimension(this, p_184204_1_)) return null;
|
|
this.worldObj.theProfiler.startSection("changeDimension");
|
|
MinecraftServer minecraftserver = this.func_184102_h();
|
|
int i = this.dimension;
|
|
@@ -2372,7 +2391,7 @@
|
|
|
|
public float getExplosionResistance(Explosion explosionIn, World worldIn, BlockPos pos, IBlockState blockStateIn)
|
|
{
|
|
- return blockStateIn.getBlock().getExplosionResistance(this);
|
|
+ return blockStateIn.getBlock().getExplosionResistance(worldIn, pos, this, explosionIn);
|
|
}
|
|
|
|
public boolean verifyExplosion(Explosion explosionIn, World worldIn, BlockPos pos, IBlockState blockStateIn, float p_174816_5_)
|
|
@@ -2662,6 +2681,165 @@
|
|
EnchantmentHelper.applyArthropodEnchantments(entityLivingBaseIn, entityIn);
|
|
}
|
|
|
|
+ /* ================================== 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(RayTraceResult target)
|
|
+ {
|
|
+ if (this instanceof net.minecraft.entity.item.EntityPainting)
|
|
+ {
|
|
+ return new ItemStack(net.minecraft.init.Items.painting);
|
|
+ }
|
|
+ else if (this instanceof EntityLeashKnot)
|
|
+ {
|
|
+ return new ItemStack(net.minecraft.init.Items.lead);
|
|
+ }
|
|
+ else if (this instanceof net.minecraft.entity.item.EntityItemFrame)
|
|
+ {
|
|
+ ItemStack held = ((net.minecraft.entity.item.EntityItemFrame)this).getDisplayedItem();
|
|
+ if (held == null)
|
|
+ {
|
|
+ return new ItemStack(net.minecraft.init.Items.item_frame);
|
|
+ }
|
|
+ else
|
|
+ {
|
|
+ return held.copy();
|
|
+ }
|
|
+ }
|
|
+ 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.armor_stand);
|
|
+ }
|
|
+ else if (this instanceof net.minecraft.entity.item.EntityEnderCrystal)
|
|
+ {
|
|
+ return new ItemStack(net.minecraft.init.Items.field_185158_cP);
|
|
+ }
|
|
+ else
|
|
+ {
|
|
+ String name = EntityList.getEntityString(this);
|
|
+ if (EntityList.entityEggs.containsKey(name))
|
|
+ {
|
|
+ ItemStack stack = new ItemStack(net.minecraft.init.Items.spawn_egg);
|
|
+ net.minecraft.item.ItemMonsterPlacer.func_185078_a(stack, name);
|
|
+ return stack;
|
|
+ }
|
|
+ }
|
|
+ return null;
|
|
+ }
|
|
+
|
|
+ public UUID getPersistentID()
|
|
+ {
|
|
+ return entityUniqueID;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Reset the entity ID to a new value. Not to be used from Mod code
|
|
+ */
|
|
+ public final void resetEntityId()
|
|
+ {
|
|
+ this.entityId = nextEntityID++;
|
|
+ }
|
|
+
|
|
+ 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).isNoDespawnRequired()) return false;
|
|
+ return type.getCreatureClass().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;
|
|
+ }
|
|
+
|
|
+ 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.readFromNBT(nbt);
|
|
+ }
|
|
+
|
|
+ public NBTTagCompound serializeNBT()
|
|
+ {
|
|
+ NBTTagCompound ret = new NBTTagCompound();
|
|
+ ret.setString("id", this.getEntityString());
|
|
+ this.writeToNBT(ret);
|
|
+ return ret;
|
|
+ }
|
|
+ /* ================================== Forge End =====================================*/
|
|
+
|
|
public void func_184178_b(EntityPlayerMP p_184178_1_)
|
|
{
|
|
}
|