Stephen Seo
5999808859
Missing some features from the pre-rewrite version such as playing battle music, using bow/arrows, limiting number of combatants in battle...
35 lines
1.3 KiB
Java
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();
|
|
}
|
|
}
|
|
}
|