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

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?

  • 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.

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.