Posted May 24, 20214 yr Here's my code: package com.jerrylu086.createarsenal.items; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Iterables; import com.google.common.collect.Multimap; import com.jerrylu086.createarsenal.CreateArsenal; import com.jerrylu086.createarsenal.registry.ModItems; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.ai.attributes.Attribute; import net.minecraft.entity.ai.attributes.AttributeModifier; import net.minecraft.inventory.EquipmentSlotType; import net.minecraft.item.*; import net.minecraft.util.DamageSource; import net.minecraftforge.event.entity.living.LivingDamageEvent; import net.minecraftforge.event.entity.living.LivingHurtEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; import javax.annotation.Nonnull; @EventBusSubscriber(modid = CreateArsenal.MOD_ID) public class ExoframeItem extends ArmorItem { private Multimap<Attribute, AttributeModifier> attributeModifiers = ArrayListMultimap.create(); public ExoframeItem(IArmorMaterial materialIn, EquipmentSlotType slot, Properties properties) { super(materialIn, slot, properties); } /*@Override public boolean hitEntity(@Nonnull ItemStack stack, @Nonnull LivingEntity target, @Nonnull LivingEntity attacker) { stack.damageItem(1, attacker, (entity) -> { entity.sendBreakAnimation(EquipmentSlotType.CHEST); }); return true; }*/ @SubscribeEvent public void onDamageDealt (LivingDamageEvent event) { Entity trueSource = event.getSource().getTrueSource(); for (ItemStack stack : trueSource.getArmorInventoryList()) { if (isExo(stack)) { float damage = event.getAmount() + 5; event.setAmount(damage); } } } public boolean isExo(ItemStack stack) { if (stack == null || stack.getItem() == null) { return false; } Item item = stack.getItem(); return item == ModItems.EXOFRAME.get(); } } What I want to do is when this event detects an attacker of LivingDamageEvent is wearing the Exoframe item will increase the attack damage by 5 (can be reduced so use LivingDamageEvent instead of LivingHurtEvent). But I tested it, it does not do anything when I'm wearing the item. How I fix it?
May 24, 20214 yr Author 8 hours ago, diesieben07 said: @EventBusSubscriber registers the Class to the event bus, which checks static methods only. Why is this not just an attack damage attribute modifier on your item? Then you don't need the event handler at all. This is exactly what attribute modifiers are for... I used the AttributeModifer before, but what I want is increase the attack damage. Like if I'm using melee damage and wearing the chestplate, I will deal 6 damage. And if I'm using netherite sword, which has 8 attack damage, I will deal 13 damage. As far as I know what I can do with AttributeModifer is only *set* the attack damage, like if I'm wearing the chestplate, I will always deal 5 damage, even I'm using the weapons with high attack damage.
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.