2018-09-12 05:43:59 +00:00
|
|
|
package com.seodisparate.TurnBasedMinecraft.common;
|
|
|
|
|
|
|
|
import net.minecraftforge.event.entity.living.LivingAttackEvent;
|
|
|
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
|
|
|
|
|
|
|
public class AttackEventHandler
|
|
|
|
{
|
|
|
|
@SubscribeEvent
|
|
|
|
public void entityAttacked(LivingAttackEvent event)
|
|
|
|
{
|
|
|
|
if(event.getEntity().world.isRemote)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if(TurnBasedMinecraftMod.battleManager == null)
|
|
|
|
{
|
|
|
|
TurnBasedMinecraftMod.battleManager = new BattleManager(TurnBasedMinecraftMod.logger);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!(event.getSource().getTrueSource() == null || event.getSource().getTrueSource().equals(TurnBasedMinecraftMod.attackingEntity)) && TurnBasedMinecraftMod.battleManager.checkAttack(event))
|
|
|
|
{
|
2018-09-13 05:12:04 +00:00
|
|
|
// TurnBasedMinecraftMod.logger.debug("Canceled LivingAttackEvent between " + TurnBasedMinecraftMod.attackingEntity + " and " + event.getEntity());
|
2018-09-12 05:43:59 +00:00
|
|
|
event.setCanceled(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-09-13 05:12:04 +00:00
|
|
|
// TurnBasedMinecraftMod.logger.debug("Did not cancel attack");
|
2018-09-12 05:43:59 +00:00
|
|
|
}
|
|
|
|
if(TurnBasedMinecraftMod.attackingDamage < (int) event.getAmount())
|
|
|
|
{
|
|
|
|
TurnBasedMinecraftMod.attackingDamage = (int) event.getAmount();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|