From c9fe5ded9b817d6d96b9af25fe55ad1bf6c89f43 Mon Sep 17 00:00:00 2001 From: Lex Manos Date: Sun, 7 Dec 2014 02:35:07 -0800 Subject: [PATCH] Add LivingHealEvent called from EntityLivingBase.heal() Closes #1282 --- .../entity/EntityLivingBase.java.patch | 37 ++++++++++++------- .../event/ForgeEventFactory.java | 7 ++++ .../event/entity/living/LivingHealEvent.java | 30 +++++++++++++++ 3 files changed, 60 insertions(+), 14 deletions(-) create mode 100644 src/main/java/net/minecraftforge/event/entity/living/LivingHealEvent.java diff --git a/patches/minecraft/net/minecraft/entity/EntityLivingBase.java.patch b/patches/minecraft/net/minecraft/entity/EntityLivingBase.java.patch index 570364755f..49586bcefe 100644 --- a/patches/minecraft/net/minecraft/entity/EntityLivingBase.java.patch +++ b/patches/minecraft/net/minecraft/entity/EntityLivingBase.java.patch @@ -41,7 +41,16 @@ public void func_70618_n(int p_70618_1_) { this.field_70713_bf.remove(Integer.valueOf(p_70618_1_)); -@@ -730,6 +732,7 @@ +@@ -710,6 +712,8 @@ + + public void func_70691_i(float p_70691_1_) + { ++ p_70691_1_ = net.minecraftforge.event.ForgeEventFactory.onLivingHeal(this, p_70691_1_); ++ if (p_70691_1_ <= 0) return; + float f1 = this.func_110143_aJ(); + + if (f1 > 0.0F) +@@ -730,6 +734,7 @@ public boolean func_70097_a(DamageSource p_70097_1_, float p_70097_2_) { @@ -49,7 +58,7 @@ if (this.func_85032_ar()) { return false; -@@ -796,9 +799,9 @@ +@@ -796,9 +801,9 @@ this.field_70718_bc = 100; this.field_70717_bb = (EntityPlayer)entity; } @@ -61,7 +70,7 @@ if (entitywolf.func_70909_n()) { -@@ -883,6 +886,7 @@ +@@ -883,6 +888,7 @@ public void func_70645_a(DamageSource p_70645_1_) { @@ -69,7 +78,7 @@ Entity entity = p_70645_1_.func_76346_g(); EntityLivingBase entitylivingbase = this.func_94060_bK(); -@@ -908,6 +912,10 @@ +@@ -908,6 +914,10 @@ i = EnchantmentHelper.func_77519_f((EntityLivingBase)entity); } @@ -80,7 +89,7 @@ if (this.func_146066_aG() && this.field_70170_p.func_82736_K().func_82766_b("doMobLoot")) { this.func_70628_a(this.field_70718_bc > 0, i); -@@ -915,7 +923,7 @@ +@@ -915,7 +925,7 @@ if (this.field_70718_bc > 0) { @@ -89,7 +98,7 @@ if (j < 5) { -@@ -923,6 +931,16 @@ +@@ -923,6 +933,16 @@ } } } @@ -106,7 +115,7 @@ } this.field_70170_p.func_72960_a(this, (byte)3); -@@ -971,7 +989,7 @@ +@@ -971,7 +991,7 @@ int j = MathHelper.func_76128_c(this.field_70121_D.field_72338_b); int k = MathHelper.func_76128_c(this.field_70161_v); Block block = this.field_70170_p.func_147439_a(i, j, k); @@ -115,7 +124,7 @@ } public boolean func_70089_S() -@@ -981,6 +999,8 @@ +@@ -981,6 +1001,8 @@ protected void func_70069_a(float p_70069_1_) { @@ -124,7 +133,7 @@ super.func_70069_a(p_70069_1_); PotionEffect potioneffect = this.func_70660_b(Potion.field_76430_j); float f1 = potioneffect != null ? (float)(potioneffect.func_76458_c() + 1) : 0.0F; -@@ -1060,7 +1080,7 @@ +@@ -1060,7 +1082,7 @@ { if (this instanceof EntityZombie) { @@ -133,7 +142,7 @@ } int i; -@@ -1104,6 +1124,8 @@ +@@ -1104,6 +1126,8 @@ { if (!this.func_85032_ar()) { @@ -142,7 +151,7 @@ p_70665_2_ = this.func_70655_b(p_70665_1_, p_70665_2_); p_70665_2_ = this.func_70672_c(p_70665_1_, p_70665_2_); float f1 = p_70665_2_; -@@ -1152,6 +1174,17 @@ +@@ -1152,6 +1176,17 @@ public void func_71038_i() { @@ -160,7 +169,7 @@ if (!this.field_82175_bq || this.field_110158_av >= this.func_82166_i() / 2 || this.field_110158_av < 0) { this.field_110158_av = -1; -@@ -1347,6 +1380,7 @@ +@@ -1347,6 +1382,7 @@ } this.field_70160_al = true; @@ -168,7 +177,7 @@ } public void func_70612_e(float p_70612_1_, float p_70612_2_) -@@ -1521,6 +1555,7 @@ +@@ -1521,6 +1557,7 @@ public void func_70071_h_() { @@ -176,7 +185,7 @@ super.func_70071_h_(); if (!this.field_70170_p.field_72995_K) -@@ -2007,6 +2042,44 @@ +@@ -2007,6 +2044,44 @@ return this.func_96124_cp() != null ? this.func_96124_cp().func_142054_a(p_142012_1_) : false; } diff --git a/src/main/java/net/minecraftforge/event/ForgeEventFactory.java b/src/main/java/net/minecraftforge/event/ForgeEventFactory.java index c6ff9fba36..8dad798eb4 100644 --- a/src/main/java/net/minecraftforge/event/ForgeEventFactory.java +++ b/src/main/java/net/minecraftforge/event/ForgeEventFactory.java @@ -29,6 +29,7 @@ import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.util.BlockSnapshot; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.event.entity.EntityStruckByLightningEvent; +import net.minecraftforge.event.entity.living.LivingHealEvent; import net.minecraftforge.event.entity.living.LivingPackSizeEvent; import net.minecraftforge.event.entity.living.LivingSpawnEvent; import net.minecraftforge.event.entity.living.LivingSpawnEvent.AllowDespawn; @@ -246,4 +247,10 @@ public class ForgeEventFactory { return MinecraftForge.EVENT_BUS.post(new WorldEvent.CreateSpawnPosition(world, settings)); } + + public static float onLivingHeal(EntityLivingBase entity, float amount) + { + LivingHealEvent event = new LivingHealEvent(entity, amount); + return (MinecraftForge.EVENT_BUS.post(event) ? 0 : event.amount); + } } diff --git a/src/main/java/net/minecraftforge/event/entity/living/LivingHealEvent.java b/src/main/java/net/minecraftforge/event/entity/living/LivingHealEvent.java new file mode 100644 index 0000000000..d7801771df --- /dev/null +++ b/src/main/java/net/minecraftforge/event/entity/living/LivingHealEvent.java @@ -0,0 +1,30 @@ +package net.minecraftforge.event.entity.living; + +import cpw.mods.fml.common.eventhandler.Cancelable; +import net.minecraft.entity.EntityLivingBase; + +/** + * LivingHealEvent is fired when an Entity is set to be healed.
+ * This event is fired whenever an Entity is healed in EntityLivingBase#heal(float)
+ *
+ * This event is fired via the {@link ForgeHooks#onLivingHeal(EntityLivingBase, float)}.
+ *
+ * {@link #amount} contains the amount of healing done to the Entity that was healed.
+ *
+ * This event is {@link Cancelable}.
+ * If this event is canceled, the Entity is not healed.
+ *
+ * This event does not have a result. {@link HasResult}
+ *
+ * This event is fired on the {@link MinecraftForge#EVENT_BUS}. + **/ +@Cancelable +public class LivingHealEvent extends LivingEvent +{ + public float amount; + public LivingHealEvent(EntityLivingBase entity, float amount) + { + super(entity); + this.amount = amount; + } +} \ No newline at end of file