Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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;
            }
            */

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.