Prevent EntityPlayer.attackEntityFrom from firing LivingAttackEvent twice (#4661)

This commit is contained in:
coolsquid authored and LexManos committed 2018-04-01 01:12:46 -07:00
1 parent e099aa32d4
commit f5c0b894bf
5 files changed
+41 -3

No files matched your search

@@ -4,7 +4,7 @@
public boolean func_70097_a(DamageSource p_70097_1_, float p_70097_2_)
{
+ net.minecraftforge.common.ForgeHooks.onLivingAttack(this, p_70097_1_, p_70097_2_);
+ net.minecraftforge.common.ForgeHooks.onPlayerAttack(this, p_70097_1_, p_70097_2_);
return true;
}
@@ -4,7 +4,7 @@
public boolean func_70097_a(DamageSource p_70097_1_, float p_70097_2_)
{
+ net.minecraftforge.common.ForgeHooks.onLivingAttack(this, p_70097_1_, p_70097_2_);
+ net.minecraftforge.common.ForgeHooks.onPlayerAttack(this, p_70097_1_, p_70097_2_);
return false;
}
@@ -202,7 +202,7 @@
public boolean func_70097_a(DamageSource p_70097_1_, float p_70097_2_)
{
+ if (!net.minecraftforge.common.ForgeHooks.onLivingAttack(this, p_70097_1_, p_70097_2_)) return false;
+ if (!net.minecraftforge.common.ForgeHooks.onPlayerAttack(this, p_70097_1_, p_70097_2_)) return false;
if (this.func_180431_b(p_70097_1_))
{
return false;
@@ -567,6 +567,11 @@ public class ForgeHooks
}
public static boolean onLivingAttack(EntityLivingBase entity, DamageSource src, float amount)
{
return entity instanceof EntityPlayer || !MinecraftForge.EVENT_BUS.post(new LivingAttackEvent(entity, src, amount));
}
public static boolean onPlayerAttack(EntityLivingBase entity, DamageSource src, float amount)
{
return !MinecraftForge.EVENT_BUS.post(new LivingAttackEvent(entity, src, amount));
}
@@ -0,0 +1,33 @@
package net.minecraftforge.debug;
import net.minecraft.util.DamageSource;
import net.minecraftforge.event.entity.living.LivingAttackEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@Mod(modid = LivingAttackEventTest.MODID, name = LivingAttackEventTest.NAME, version = "1.0.0", acceptableRemoteVersions = "*")
public class LivingAttackEventTest
{
public static final String MODID = "livingattackeventtest";
public static final String NAME = "LivingAttackEventTest";
private static final Logger LOGGER = LogManager.getLogger(NAME);
@EventBusSubscriber
public static class LivingAttackEventHandler
{
@SubscribeEvent
public static void onLivingAttack(LivingAttackEvent event)
{
if (event.getSource() == DamageSource.ANVIL)
{
LOGGER.info("{} was hit by an anvil!", event.getEntityLiving().getName());
}
}
}
}