Posted May 11, 20214 yr 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 May 11, 20214 yr by JerryLy086 code
May 11, 20214 yr 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.