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

I want to increase the player's attack damage when using a chestplate, but I have no way to do it.

What I have done is just set to a number, not increase.

For example, I want to increase 3 attack damage when using, and I'm using a diamond sword which provides 7 damage. When I'm wearing the chestplate, it should be 10 attack damage.

My code:

package com.jerrylu086.createarsenal.items;

import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap;
import com.jerrylu086.createarsenal.CreateArsenal;
import net.minecraft.entity.Entity;
import net.minecraft.entity.ai.attributes.Attribute;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.ai.attributes.Attributes;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.*;
import net.minecraft.util.ResourceLocation;

import javax.annotation.Nullable;

public class ExoskeletonItem extends ArmorItem {

    private final float attackDamage;

    private final Multimap<Attribute, AttributeModifier> attributeModifiers;

    public ExoskeletonItem(IArmorMaterial materialIn, EquipmentSlotType slot, float attackDamageIn, Properties properties) {
        super(materialIn, slot, properties);
        this.attackDamage = attackDamageIn;
        ImmutableMultimap.Builder<Attribute, AttributeModifier> builder = ImmutableMultimap.builder();
        builder.put(Attributes.ATTACK_DAMAGE, new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Weapon modifier", (double)this.attackDamage, AttributeModifier.Operation.ADDITION));
        this.attributeModifiers = builder.build();
    }

    @Override
    @Nullable
    public String getArmorTexture(ItemStack stack, Entity entity, EquipmentSlotType slot, String type) {
        return new ResourceLocation(CreateArsenal.MOD_ID, "textures/models/armor/exoskeleton_layer_1.png").toString();
    }

    public Multimap<Attribute, AttributeModifier> getAttributeModifiers(EquipmentSlotType equipmentSlot) {
        return equipmentSlot == EquipmentSlotType.CHEST ? this.attributeModifiers : super.getAttributeModifiers(equipmentSlot);
    }

}package com.jerrylu086.createarsenal.items; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.Multimap; import com.jerrylu086.createarsenal.CreateArsenal; import net.minecraft.entity.Entity; import net.minecraft.entity.ai.attributes.Attribute; import net.minecraft.entity.ai.attributes.AttributeModifier; import net.minecraft.entity.ai.attributes.Attributes; import net.minecraft.inventory.EquipmentSlotType; import net.minecraft.item.*; import net.minecraft.util.ResourceLocation; import javax.annotation.Nullable; public class ExoskeletonItem extends ArmorItem { private final float attackDamage; private final Multimap<Attribute, AttributeModifier> attributeModifiers; public ExoskeletonItem(IArmorMaterial materialIn, EquipmentSlotType slot, float attackDamageIn, Properties properties) { super(materialIn, slot, properties); this.attackDamage = attackDamageIn; ImmutableMultimap.Builder<Attribute, AttributeModifier> builder = ImmutableMultimap.builder(); builder.put(Attributes.ATTACK_DAMAGE, new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Weapon modifier", (double)this.attackDamage, AttributeModifier.Operation.ADDITION)); this.attributeModifiers = builder.build(); } @Override @Nullable public String getArmorTexture(ItemStack stack, Entity entity, EquipmentSlotType slot, String type) { return new ResourceLocation(CreateArsenal.MOD_ID, "textures/models/armor/exoskeleton_layer_1.png").toString(); } public Multimap<Attribute, AttributeModifier> getAttributeModifiers(EquipmentSlotType equipmentSlot) { return equipmentSlot == EquipmentSlotType.CHEST ? this.attributeModifiers : super.getAttributeModifiers(equipmentSlot); } }

Edited by JerryLy086
code

19 minutes ago, JerryLy086 said:

I want to increase the player's attack damage when using a chestplate, but I have no way to do it.

What I have done is just set to a number, not increase.

For example, I want to increase 3 attack damage when using, and I'm using a diamond sword which provides 7 damage. When I'm wearing the chestplate, it should be 10 attack damage.

My code:

if I see that correctly you are trying to overwrite the armor item,
if you want to add the damage there then you should use the entityHurt method
but keep in mind you have to overwrite all ArmorItems

An easier way would be if you use the LivingDamageEvent,
check whether the attacker (DamageSource # getEntity) is holding an ArmorItem
and then set the new damage
check out the event for more info on how it works or when it is fired

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.