Jump to content

Increase attack damage instead of set it


JerryLy086

Recommended Posts

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
Link to comment
Share on other sites

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

  • Like 1
Link to comment
Share on other sites

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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