[SOLVED] HELP Sword getAttributeModifiers crash (1.16.5 36.2.26 Forge)

Started by Kuri_Pa on Mon, 05/23/2022 - 08:05

Topic category: Help with modding (Java Edition)

Last seen on 14:11, 23. Jun 2022
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
[SOLVED] HELP Sword getAttributeModifiers crash (1.16.5 36.2.26 Forge)
Fri, 05/27/2022 - 06:35 (edited)

I want my sword to have +50% attack damage, but it crashes when I start the game

I added these codes manually in 

public void initElements() {

        elements.items.add(() -> new SwordItem(new IItemTier() {

			@Override
			public Multimap<Attribute, AttributeModifier> getAttributeModifiers(EquipmentSlotType slot,	ItemStack stack) {
				Multimap<Attribute, AttributeModifier> sword_attack = super.getAttributeModifiers(slot, stack);
				if ( slot == EquipmentSlotType.MAINHAND){
				sword_attack.put(Attributes.ATTACK_DAMAGE, new AttributeModifier(UUID.randomUUID(),"Weapon modifier", (double)0.5, AttributeModifier.Operation.MULTIPLY_BASE));
				}
				return sword_attack;
			}

I don't know what's wrong, seems is sword_attack.put

what should I do?


I refer to botania's code and found the solution

			@Override
			public Multimap<Attribute, AttributeModifier> getAttributeModifiers(EquipmentSlotType slot,	ItemStack stack) {
				Multimap<Attribute, AttributeModifier> sword_attack =LinkedHashMultimap.create();
				if ( slot == EquipmentSlotType.MAINHAND){
				sword_attack.put(Attributes.ATTACK_DAMAGE, new AttributeModifier(ATTACK_DAMAGE_MODIFIER,"Weapon modifier", getAttackDamage(), AttributeModifier.Operation.ADDITION));
				sword_attack.put(Attributes.ATTACK_SPEED, new AttributeModifier(ATTACK_SPEED_MODIFIER,"Weapon modifier", -3.2 , AttributeModifier.Operation.ADDITION));
				sword_attack.put(ForgeMod.REACH_DISTANCE.get(), new AttributeModifier(UUID.randomUUID(),"Weapon modifier",2, AttributeModifier.Operation.ADDITION));
				sword_attack.put(Attributes.ATTACK_DAMAGE, new AttributeModifier(UUID.randomUUID(),"Weapon modifier",0.5, AttributeModifier.Operation.MULTIPLY_BASE));
				return sword_attack;
			}

Change super.getAttributeModifiers(slot, stack); to LinkedHashMultimap.create();

 

Edited by Kuri_Pa on Fri, 05/27/2022 - 06:35
Last seen on 16:02, 17. Jun 2022
Joined Apr 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
So there are 2 solutions, If…
Mon, 05/23/2022 - 16:38

So there are 2 solutions, If I'm reading this correctly.

#1 - Just give your sword a attack boost in It's base damage. Example your sword has base 6 damage +50% would make it 9 Damage.

 

#2 - Create a procedure that /give 's the sword with +50% damage boost via item attributes like so

/give @p YOUR_MOD_NAME:YOUR_SWORD_NAME{AttributeModifiers:[{AttributeName:"generic.attack_damage",Amount:"0.5",Slot:mainhand,Operation:1,Name:"generic.attack_damage",UUID:[I;-122423,24530,92129,-49060]}]} 1

change YOUR_MOD_NAME to your mods internal name (Example "My Cool Mod - my_cool_mod")

change YOUR_SWORD_NAME to your sword's internal name (Example "Longsword of Doom - longsword_of_doom")

Since this uses math Operation 1 , which is multiply, 0.5 = 50%

 

If neither of these is what you are looking for then sorry I'm not sure what it is your trying to do.

Last seen on 14:11, 23. Jun 2022
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
I want my sword to have 20…
Tue, 05/24/2022 - 02:12

I want my sword to have

20 attack damage

0.8 attack speed

+50% attack damage

I found the solution

			public Multimap<Attribute, AttributeModifier> getAttributeModifiers(EquipmentSlotType slot,	ItemStack stack) {
				Multimap<Attribute, AttributeModifier> sword_attack = LinkedHashMultimap.create();
				if ( slot == EquipmentSlotType.MAINHAND){
				sword_attack.put(Attributes.ATTACK_DAMAGE, new AttributeModifier(ATTACK_DAMAGE_MODIFIER,"Weapon modifier", (double)19, AttributeModifier.Operation.ADDITION));
				sword_attack.put(Attributes.ATTACK_SPEED, new AttributeModifier(ATTACK_SPEED_MODIFIER,"Weapon modifier", (double)-3.2, AttributeModifier.Operation.ADDITION));
				sword_attack.put(Attributes.ATTACK_DAMAGE, new AttributeModifier(UUID.randomUUID(),"Weapon modifier", (double)0.5, AttributeModifier.Operation.MULTIPLY_BASE));
				}
				return sword_attack;
			}

This should also work for max health or movement speed when held in the main hand
 

			public Multimap<Attribute, AttributeModifier> getAttributeModifiers(EquipmentSlotType slot,	ItemStack stack) {
				Multimap<Attribute, AttributeModifier> sword_attack = LinkedHashMultimap.create();
				if ( slot == EquipmentSlotType.MAINHAND){
				sword_attack.put(Attributes.ATTACK_DAMAGE, new AttributeModifier(ATTACK_DAMAGE_MODIFIER,"Weapon modifier", (double)19, AttributeModifier.Operation.ADDITION));
				sword_attack.put(Attributes.ATTACK_SPEED, new AttributeModifier(ATTACK_SPEED_MODIFIER,"Weapon modifier", (double)-3.2, AttributeModifier.Operation.ADDITION));
				sword_attack.put(Attributes.MOVEMENT_SPEED, new AttributeModifier(UUID.randomUUID(),"Weapon modifier", (double)0.5, AttributeModifier.Operation.MULTIPLY_BASE));
				sword_attack.put(Attributes.MAX_HEALTH, new AttributeModifier(UUID.randomUUID(),"Weapon modifier", (double)0.5, AttributeModifier.Operation.MULTIPLY_BASE));
				}
				return sword_attack;
			}