So I'm new to the community, and I've been modding with 1.11.2 for a bit. I have looked on the forums for answers but most of the pages on it were outdated.
Here is my question: How do I detect damage dealt be a player wearing armor and effect the player with life boost based on the damage value?
Here is my current code:
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.DamageSource;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.event.entity.player.AttackEntityEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
public class ItemAncientArmor extends ItemArmor
{
public final String name;
public ItemAncientArmor(ArmorMaterial material, int renderIndex, EntityEquipmentSlot armorType, String name) {
super(material, renderIndex, armorType);
this.name = name;
this.setUnlocalizedName(BaseMod.MODID + "_" + name);
this.setCreativeTab(CreativeTabs.COMBAT);
}
public String getArmorTexture(ItemStack stack, Entity entity, EntityEquipmentSlot slot,
String type) {
if(slot == EntityEquipmentSlot.LEGS){
return "examplemod:textures/models/armor/ancientarmor2.png";
}
return "examplemod:textures/models/armor/ancientarmor1.png";
}
public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack)
{
if (itemStack.getItem() == ItemMod.ancientHelmet || itemStack.getItem() == ItemMod.ancientChestplate ||
itemStack.getItem() == ItemMod.ancientLeggings || itemStack.getItem() == ItemMod.ancientBoots)
{
if (player.isAirBorne)
{
player.addPotionEffect(new PotionEffect(Potion.getPotionFromResourceLocation("resistance"), 1, 5));
player.addPotionEffect(new PotionEffect(Potion.getPotionFromResourceLocation("strength"), 1, 5));
}
/*
public LivingHurtEvent(EntityLivingBase entity, DamageSource source, float amount)
{
super(entity);
this.source = source;
this.amount = amount;
// TODO make player get health boost based on damage output
//LivingHurtEvent float damage? player.addPotionEffect... boost"), 5, damage));?
}
*/
/* TODO make player get health boost based on damage output
new AttackEntityEvent(player, player)
{
super(player);
this.target = target;
}
*/