diff --git a/patches/minecraft/net/minecraft/entity/EntityLiving.java.patch b/patches/minecraft/net/minecraft/entity/EntityLiving.java.patch index daa60531f..b7bb24556 100644 --- a/patches/minecraft/net/minecraft/entity/EntityLiving.java.patch +++ b/patches/minecraft/net/minecraft/entity/EntityLiving.java.patch @@ -49,15 +49,15 @@ } protected EntityBodyHelper func_184650_s() -@@ -171,6 +170,7 @@ +@@ -170,7 +169,7 @@ public void func_70624_b(@Nullable EntityLivingBase p_70624_1_) { - this.field_70696_bz = p_70624_1_; -+ net.minecraftforge.common.ForgeHooks.onLivingSetAttackTarget(this, p_70624_1_); +- this.field_70696_bz = p_70624_1_; ++ this.field_70696_bz = net.minecraftforge.common.ForgeHooks.onLivingSetAttackTarget(this, p_70624_1_); } public boolean func_70686_a(Class p_70686_1_) -@@ -182,11 +182,10 @@ +@@ -182,11 +181,10 @@ { } @@ -70,7 +70,7 @@ } public int func_70627_aG() -@@ -204,7 +203,6 @@ +@@ -204,7 +202,6 @@ } } @@ -78,7 +78,7 @@ public void func_70030_z() { super.func_70030_z(); -@@ -219,7 +217,6 @@ +@@ -219,7 +216,6 @@ this.field_70170_p.field_72984_F.func_76319_b(); } @@ -86,7 +86,7 @@ protected void func_184581_c(DamageSource p_184581_1_) { this.func_175456_n(); -@@ -231,24 +228,23 @@ +@@ -231,24 +227,23 @@ this.field_70757_a = -this.func_70627_aG(); } @@ -115,7 +115,7 @@ { i += 1 + this.field_70146_Z.nextInt(3); } -@@ -266,22 +262,13 @@ +@@ -266,22 +261,13 @@ { if (this.field_70170_p.field_72995_K) { @@ -144,7 +144,7 @@ } } else -@@ -291,7 +278,6 @@ +@@ -291,7 +277,6 @@ } @SideOnly(Side.CLIENT) @@ -152,7 +152,7 @@ public void func_70103_a(byte p_70103_1_) { if (p_70103_1_ == 20) -@@ -304,7 +290,6 @@ +@@ -304,7 +289,6 @@ } } @@ -160,7 +160,7 @@ public void func_70071_h_() { super.func_70071_h_(); -@@ -324,7 +309,6 @@ +@@ -324,7 +308,6 @@ } } @@ -168,7 +168,7 @@ protected float func_110146_f(float p_110146_1_, float p_110146_2_) { this.field_70762_j.func_75664_a(); -@@ -343,7 +327,6 @@ +@@ -343,7 +326,6 @@ return null; } @@ -176,7 +176,7 @@ protected void func_70628_a(boolean p_70628_1_, int p_70628_2_) { Item item = this.func_146068_u(); -@@ -357,7 +340,7 @@ +@@ -357,7 +339,7 @@ i += this.field_70146_Z.nextInt(p_70628_2_ + 1); } @@ -185,7 +185,7 @@ { this.func_145779_a(item, 1); } -@@ -366,10 +349,9 @@ +@@ -366,10 +348,9 @@ public static void func_189752_a(DataFixer p_189752_0_, Class p_189752_1_) { @@ -197,7 +197,7 @@ public void func_70014_b(NBTTagCompound p_70014_1_) { super.func_70014_b(p_70014_1_); -@@ -461,7 +443,6 @@ +@@ -461,7 +442,6 @@ } } @@ -205,7 +205,7 @@ public void func_70037_a(NBTTagCompound p_70037_1_) { super.func_70037_a(p_70037_1_); -@@ -477,7 +458,7 @@ +@@ -477,7 +457,7 @@ { NBTTagList nbttaglist = p_70037_1_.func_150295_c("ArmorItems", 10); @@ -214,7 +214,7 @@ { this.field_184657_bw.set(i, new ItemStack(nbttaglist.func_150305_b(i))); } -@@ -487,7 +468,7 @@ +@@ -487,7 +467,7 @@ { NBTTagList nbttaglist1 = p_70037_1_.func_150295_c("HandItems", 10); @@ -223,7 +223,7 @@ { this.field_184656_bv.set(j, new ItemStack(nbttaglist1.func_150305_b(j))); } -@@ -497,7 +478,7 @@ +@@ -497,7 +477,7 @@ { NBTTagList nbttaglist2 = p_70037_1_.func_150295_c("ArmorDropChances", 5); @@ -232,7 +232,7 @@ { this.field_184655_bs[k] = nbttaglist2.func_150308_e(k); } -@@ -507,7 +488,7 @@ +@@ -507,7 +487,7 @@ { NBTTagList nbttaglist3 = p_70037_1_.func_150295_c("HandDropChances", 5); @@ -241,7 +241,7 @@ { this.field_82174_bp[l] = nbttaglist3.func_150308_e(l); } -@@ -537,7 +518,6 @@ +@@ -537,7 +517,6 @@ return null; } @@ -249,7 +249,7 @@ protected void func_184610_a(boolean p_184610_1_, int p_184610_2_, DamageSource p_184610_3_) { ResourceLocation resourcelocation = this.field_184659_bA; -@@ -551,16 +531,14 @@ +@@ -551,16 +530,14 @@ { LootTable loottable = this.field_70170_p.func_184146_ak().func_186521_a(resourcelocation); this.field_184659_bA = null; @@ -268,7 +268,7 @@ { this.func_70099_a(itemstack, 0.0F); } -@@ -588,22 +566,20 @@ +@@ -588,22 +565,20 @@ this.field_70702_br = p_184646_1_; } @@ -293,7 +293,7 @@ { if (!entityitem.field_70128_L && !entityitem.func_92059_d().func_190926_b() && !entityitem.func_174874_s()) { -@@ -657,9 +633,7 @@ +@@ -657,9 +632,7 @@ { flag = true; } @@ -304,7 +304,7 @@ { ItemArmor itemarmor = (ItemArmor)itemstack.func_77973_b(); ItemArmor itemarmor1 = (ItemArmor)itemstack1.func_77973_b(); -@@ -692,7 +666,7 @@ +@@ -692,7 +665,7 @@ d0 = (double)this.field_184655_bs[entityequipmentslot.func_188454_b()]; break; default: @@ -313,7 +313,7 @@ } if (!itemstack1.func_190926_b() && (double)(this.field_70146_Z.nextFloat() - 0.1F) < d0) -@@ -729,13 +703,25 @@ +@@ -729,13 +702,25 @@ protected void func_70623_bb() { @@ -340,7 +340,7 @@ if (entity != null) { -@@ -744,16 +730,16 @@ +@@ -744,16 +729,16 @@ double d2 = entity.field_70161_v - this.field_70161_v; double d3 = d0 * d0 + d1 * d1 + d2 * d2; @@ -360,7 +360,7 @@ { this.field_70708_bq = 0; } -@@ -761,10 +747,9 @@ +@@ -761,10 +746,9 @@ } } @@ -381,7 +381,7 @@ entityliving.func_70605_aq().func_188487_a(this.func_70605_aq()); } -@@ -829,13 +814,12 @@ +@@ -829,13 +813,12 @@ } else { @@ -398,7 +398,7 @@ this.field_70125_A = this.func_70663_b(this.field_70125_A, f1, p_70625_3_); this.field_70177_z = this.func_70663_b(this.field_70177_z, f, p_70625_2_); } -@@ -859,18 +843,15 @@ +@@ -859,18 +842,15 @@ public boolean func_70601_bi() { @@ -419,7 +419,7 @@ public float func_70603_bj() { return 1.0F; -@@ -881,7 +862,6 @@ +@@ -881,7 +861,6 @@ return 4; } @@ -427,7 +427,7 @@ public int func_82143_as() { if (this.func_70638_az() == null) -@@ -891,7 +871,7 @@ +@@ -891,7 +870,7 @@ else { int i = (int)(this.func_110143_aJ() - this.func_110138_aP() * 0.33F); @@ -436,7 +436,7 @@ if (i < 0) { -@@ -902,19 +882,16 @@ +@@ -902,19 +881,16 @@ } } @@ -456,7 +456,7 @@ public ItemStack func_184582_a(EntityEquipmentSlot p_184582_1_) { switch (p_184582_1_.func_188453_a()) -@@ -928,7 +905,6 @@ +@@ -928,7 +904,6 @@ } } @@ -464,7 +464,7 @@ public void func_184201_a(EntityEquipmentSlot p_184201_1_, ItemStack p_184201_2_) { switch (p_184201_1_.func_188453_a()) -@@ -941,7 +917,6 @@ +@@ -941,7 +916,6 @@ } } @@ -472,7 +472,7 @@ protected void func_82160_b(boolean p_82160_1_, int p_82160_2_) { for (EntityEquipmentSlot entityequipmentslot : EntityEquipmentSlot.values()) -@@ -958,21 +933,16 @@ +@@ -958,21 +932,16 @@ d0 = (double)this.field_184655_bs[entityequipmentslot.func_188454_b()]; break; default: @@ -498,7 +498,7 @@ } this.func_70099_a(itemstack, 0.0F); -@@ -989,17 +959,17 @@ +@@ -989,17 +958,17 @@ if (this.field_70146_Z.nextFloat() < 0.095F) { @@ -527,7 +527,7 @@ } boolean flag = true; -@@ -1033,22 +1003,27 @@ +@@ -1033,22 +1002,27 @@ public static EntityEquipmentSlot func_184640_d(ItemStack p_184640_0_) { @@ -568,7 +568,7 @@ } @Nullable -@@ -1159,10 +1134,7 @@ +@@ -1159,10 +1133,7 @@ if (!this.func_184614_ca().func_190926_b() && this.field_70146_Z.nextFloat() < 0.25F * f) { @@ -580,7 +580,7 @@ } for (EntityEquipmentSlot entityequipmentslot : EntityEquipmentSlot.values()) -@@ -1173,10 +1145,7 @@ +@@ -1173,10 +1144,7 @@ if (!itemstack.func_190926_b() && this.field_70146_Z.nextFloat() < 0.5F * f) { @@ -592,7 +592,7 @@ } } } -@@ -1185,8 +1154,7 @@ +@@ -1185,8 +1153,7 @@ @Nullable public IEntityLivingData func_180482_a(DifficultyInstance p_180482_1_, @Nullable IEntityLivingData p_180482_2_) { @@ -602,7 +602,7 @@ if (this.field_70146_Z.nextFloat() < 0.05F) { -@@ -1237,7 +1205,6 @@ +@@ -1237,7 +1204,6 @@ return this.field_82179_bU; } @@ -610,7 +610,7 @@ public final boolean func_184230_a(EntityPlayer p_184230_1_, EnumHand p_184230_2_) { if (this.func_110167_bD() && this.func_110166_bE() == p_184230_1_) -@@ -1302,7 +1269,7 @@ +@@ -1302,7 +1268,7 @@ if (!this.field_70170_p.field_72995_K && p_110160_1_ && this.field_70170_p instanceof WorldServer) { @@ -619,7 +619,7 @@ } } } -@@ -1338,7 +1305,6 @@ +@@ -1338,7 +1304,6 @@ } } @@ -627,7 +627,7 @@ public boolean func_184205_a(Entity p_184205_1_, boolean p_184205_2_) { boolean flag = super.func_184205_a(p_184205_1_, p_184205_2_); -@@ -1359,7 +1325,7 @@ +@@ -1359,7 +1324,7 @@ { UUID uuid = this.field_110170_bx.func_186857_a("UUID"); @@ -636,7 +636,7 @@ { if (entitylivingbase.func_110124_au().equals(uuid)) { -@@ -1370,9 +1336,7 @@ +@@ -1370,9 +1335,7 @@ } else if (this.field_110170_bx.func_150297_b("X", 99) && this.field_110170_bx.func_150297_b("Y", 99) && this.field_110170_bx.func_150297_b("Z", 99)) { @@ -647,7 +647,7 @@ EntityLeashKnot entityleashknot = EntityLeashKnot.func_174863_b(this.field_70170_p, blockpos); if (entityleashknot == null) -@@ -1391,7 +1355,6 @@ +@@ -1391,7 +1354,6 @@ this.field_110170_bx = null; } @@ -655,7 +655,7 @@ public boolean func_174820_d(int p_174820_1_, ItemStack p_174820_2_) { EntityEquipmentSlot entityequipmentslot; -@@ -1437,7 +1400,6 @@ +@@ -1437,7 +1399,6 @@ } } @@ -663,7 +663,7 @@ public boolean func_184186_bw() { return this.func_82171_bF() && super.func_184186_bw(); -@@ -1446,12 +1408,9 @@ +@@ -1446,12 +1407,9 @@ public static boolean func_184648_b(EntityEquipmentSlot p_184648_0_, ItemStack p_184648_1_) { EntityEquipmentSlot entityequipmentslot = func_184640_d(p_184648_1_); @@ -677,7 +677,7 @@ public boolean func_70613_aW() { return super.func_70613_aW() && !this.func_175446_cd(); -@@ -1459,27 +1418,26 @@ +@@ -1459,27 +1417,26 @@ public void func_94061_f(boolean p_94061_1_) { @@ -711,7 +711,7 @@ public EnumHandSide func_184591_cq() { return this.func_184638_cS() ? EnumHandSide.LEFT : EnumHandSide.RIGHT; -@@ -1490,5 +1448,19 @@ +@@ -1490,5 +1447,19 @@ ON_GROUND, IN_AIR, IN_WATER; diff --git a/src/main/java/net/minecraftforge/common/ForgeHooks.java b/src/main/java/net/minecraftforge/common/ForgeHooks.java index 3aaf57048..dab8d19f7 100644 --- a/src/main/java/net/minecraftforge/common/ForgeHooks.java +++ b/src/main/java/net/minecraftforge/common/ForgeHooks.java @@ -56,6 +56,7 @@ import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.item.EntityMinecartContainer; @@ -576,11 +577,20 @@ public static void onDifficultyChange(EnumDifficulty difficulty, EnumDifficulty //Optifine Helper Functions u.u, these are here specifically for Optifine //Note: When using Optifine, these methods are invoked using reflection, which //incurs a major performance penalty. + @Deprecated(since = "15.24.0.3026") public static void onLivingSetAttackTarget(EntityLivingBase entity, EntityLivingBase target) { MinecraftForge.EVENT_BUS.post(new LivingSetAttackTargetEvent(entity, target)); } + public static EntityLivingBase onLivingSetAttackTarget(EntityLiving living, EntityLivingBase target) + { + LivingSetAttackTargetEvent event = new LivingSetAttackTargetEvent(living, target); + if (MinecraftForge.EVENT_BUS.post(event)){ + return living.getAttackTarget(); + }else return event.getTarget(); + } + public static boolean onLivingUpdate(EntityLivingBase entity) { return MinecraftForge.EVENT_BUS.post(new LivingUpdateEvent(entity)); diff --git a/src/main/java/net/minecraftforge/event/entity/living/LivingSetAttackTargetEvent.java b/src/main/java/net/minecraftforge/event/entity/living/LivingSetAttackTargetEvent.java index afa99c516..e2d61aa02 100644 --- a/src/main/java/net/minecraftforge/event/entity/living/LivingSetAttackTargetEvent.java +++ b/src/main/java/net/minecraftforge/event/entity/living/LivingSetAttackTargetEvent.java @@ -30,28 +30,59 @@ * This event is fired whenever an Entity sets a target to attack in * {@link EntityLiving#setAttackTarget(EntityLivingBase)}.
*
- * This event is fired via the {@link ForgeHooks#onLivingSetAttackTarget(EntityLivingBase, EntityLivingBase)}.
+ * This event is fired via the {@link ForgeHooks#onLivingSetAttackTarget(EntityLiving, EntityLivingBase)}.
*
- * {@link #target} contains the newly targeted Entity.
+ * {@link #originalTarget} contains the newly targeted Entity.
*
- * This event is not {@link Cancelable}.
+ * {@link #redirectedTarget} contains the redirected Targeted Entity.
+ *
+ * This event is {@link Cancelable}.
*
* This event does not have a result. {@link HasResult}
*
* This event is fired on the {@link MinecraftForge#EVENT_BUS}. **/ -public class LivingSetAttackTargetEvent extends LivingEvent -{ - - private final EntityLivingBase target; +@Cancelable +public class LivingSetAttackTargetEvent extends LivingEvent{ + private final EntityLivingBase originalTarget; + private EntityLivingBase redirectedTarget; + private boolean isModified; + public LivingSetAttackTargetEvent(EntityLivingBase entity, EntityLivingBase target) { super(entity); - this.target = target; + this.originalTarget = target; + this.redirectedTarget = null; + this.isModified = false; } + /** + * Get the target that will be actually applied + **/ public EntityLivingBase getTarget() { - return target; + return isModified ? redirectedTarget : originalTarget; + } + + /** + * return the original attack target + **/ + public EntityLivingBase getOriginalTarget(){ + return originalTarget; + } + + /** + * Set the attack target of the living's + **/ + public void setTarget(EntityLivingBase living){ + this.redirectedTarget = living; + this.isModified = true; + } + + /** + * Is the attack target is modified + **/ + public boolean isModified(){ + return this.isModified; } }