TurnBasedMinecraftMod/src/main/java/com/seodisparate/TurnBasedMinecraft/common/AttackEventHandler.java
Stephen Seo 5999808859 crash bug fixes, mod is playable at this point
Missing some features from the pre-rewrite version such as playing
battle music, using bow/arrows, limiting number of combatants in
battle...
2018-09-12 14:43:59 +09:00

35 lines
1.3 KiB
Java

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)
{
TurnBasedMinecraftMod.logger.debug("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))
{
TurnBasedMinecraftMod.logger.debug("Canceled LivingAttackEvent between " + TurnBasedMinecraftMod.attackingEntity + " and " + event.getEntity());
event.setCanceled(true);
}
else
{
TurnBasedMinecraftMod.logger.debug("Did not cancel attack");
}
if(TurnBasedMinecraftMod.attackingDamage < (int) event.getAmount())
{
TurnBasedMinecraftMod.attackingDamage = (int) event.getAmount();
}
}
}