|
|
|
|
@ -13,17 +13,16 @@ import lotr.common.enchant.LOTREnchantmentHelper;
|
|
|
|
|
import lotr.common.item.*;
|
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
|
import net.minecraft.item.ItemBow;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
import net.minecraft.item.ItemSword;
|
|
|
|
|
import net.minecraft.item.*;
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
|
import net.minecraft.nbt.NBTTagList;
|
|
|
|
|
import net.minecraft.nbt.NBTTagString;
|
|
|
|
|
import net.minecraft.potion.Potion;
|
|
|
|
|
import net.minecraft.potion.PotionEffect;
|
|
|
|
|
import net.minecraft.util.ChatComponentText;
|
|
|
|
|
import net.minecraft.util.DamageSource;
|
|
|
|
|
import net.minecraft.util.EnumChatFormatting;
|
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
|
|
|
@ -87,12 +86,75 @@ public class CinderEventHandler implements IFuelHandler {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SubscribeEvent(priority = EventPriority.HIGH)
|
|
|
|
|
@SubscribeEvent
|
|
|
|
|
public void onLivingHurt(LivingHurtEvent event) {
|
|
|
|
|
EntityLivingBase entity = event.entityLiving;
|
|
|
|
|
EntityLivingBase attacker = event.source.getEntity() instanceof EntityLivingBase ? (EntityLivingBase) event.source.getEntity() : null;
|
|
|
|
|
World world = entity.worldObj;
|
|
|
|
|
DamageSource source = event.source;
|
|
|
|
|
if (event.entity instanceof EntityPlayer && !source.isUnblockable()) {
|
|
|
|
|
EntityPlayerMP player = (EntityPlayerMP) event.entity;
|
|
|
|
|
ItemStack sword = player.getHeldItem();
|
|
|
|
|
|
|
|
|
|
player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Player Yaw " + player.getRotationYawHead()));
|
|
|
|
|
player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Attacker Yaw " + attacker.getRotationYawHead()));
|
|
|
|
|
|
|
|
|
|
float playerYaw = player.getRotationYawHead();
|
|
|
|
|
float attackerYaw = attacker.getRotationYawHead();
|
|
|
|
|
|
|
|
|
|
// Normalize both angles to be within 0 - 360
|
|
|
|
|
playerYaw = (playerYaw + 360) % 360;
|
|
|
|
|
attackerYaw = (attackerYaw + 360) % 360;
|
|
|
|
|
|
|
|
|
|
// Calculate the angle difference
|
|
|
|
|
float angleDifference = Math.abs(playerYaw - attackerYaw);
|
|
|
|
|
player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Player Yaw " + playerYaw));
|
|
|
|
|
player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Attacker Yaw " + attackerYaw));
|
|
|
|
|
player.addChatMessage(new ChatComponentText(EnumChatFormatting.GOLD + "Angle Difference " + angleDifference));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (angleDifference > 180) {
|
|
|
|
|
angleDifference = 360 - angleDifference;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "DEBUG: Initial Damage: " + event.ammount));
|
|
|
|
|
ItemStack weapon = attacker.getHeldItem();
|
|
|
|
|
if (weapon != null) {
|
|
|
|
|
if (player.isBlocking() && angleDifference >= 135 && angleDifference <=225) {
|
|
|
|
|
|
|
|
|
|
float additionalDamage = 0.0f;
|
|
|
|
|
if (weapon.getItem() instanceof ItemAxe || weapon.getItem() instanceof LOTRItemAxe || weapon.getItem() instanceof LOTRItemBattleaxe) {
|
|
|
|
|
sword.damageItem((int) event.ammount, player);
|
|
|
|
|
world.playSoundAtEntity(player, "random.anvil_land", 1F, 2F);
|
|
|
|
|
additionalDamage = 0.75f;
|
|
|
|
|
} else if (weapon.getItem() instanceof LOTRItemHammer) {
|
|
|
|
|
sword.damageItem((int) event.ammount, player);
|
|
|
|
|
world.playSoundAtEntity(player, "random.anvil_land", 1F, 2F);
|
|
|
|
|
additionalDamage = 0.5f; // 20% more damage per piece
|
|
|
|
|
} else {
|
|
|
|
|
additionalDamage = 0.0f;
|
|
|
|
|
sword.damageItem((int) event.ammount, player);
|
|
|
|
|
world.playSoundAtEntity(player, "random.anvil_land", 1F, 2F);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float newDamage = event.ammount * (additionalDamage); // Calculate new damage
|
|
|
|
|
float newHealth = player.getHealth() - (newDamage - event.ammount); // Calculate health after applying extra damage
|
|
|
|
|
|
|
|
|
|
if (newHealth > 0) {
|
|
|
|
|
player.setHealth(newHealth);
|
|
|
|
|
event.setCanceled(true);
|
|
|
|
|
} else {
|
|
|
|
|
event.ammount = player.getHealth(); // Ensure player dies if health reaches 0 or below
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "DEBUG: Total Additional Damage: " + newDamage));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Negative Arrow Protection Handler
|
|
|
|
|
if (!event.entityLiving.worldObj.isRemote && event.source.isProjectile() && event.entityLiving instanceof EntityPlayerMP player) {
|
|
|
|
|
|