Jump to content

Recommended Posts

Posted (edited)

I want to be able to change how much damage the diamond sword does in my mod. I know that I need to use reflections to accomplish this, but I'm not sure exactly how, and I've been trying for hours. Can someone possibly tell me how to write a reflection that can do this? I'm aware that this is not a Java school but this is my last resort.

Edited by notdeadbro
Posted
9 hours ago, notdeadbro said:

I want to be able to change how much damage the diamond sword does in my mod. I know that I need to use reflections to accomplish this, but I'm not sure exactly how, and I've been trying for hours. Can someone possibly tell me how to write a reflection that can do this? I'm aware that this is not a Java school but this is my last resort.

the reflection would be an idea, but it would be easier to use an event and check whether the attacker is using a diamond sword

tip: use the LivingDamageEvent you get the attacker from the DamageSource

Posted
13 hours ago, Luis_ST said:

the reflection would be an idea, but it would be easier to use an event and check whether the attacker is using a diamond sword

tip: use the LivingDamageEvent you get the attacker from the DamageSource

Would this change the damage value of the sword that is displayed in the tooltip as well? Like this:

Minecraft_1-16-5.png.1d14cfff7c6f02c791fee3850a7f3f0d.png

I want to literally be able to change its attack damage value.

Posted
9 hours ago, notdeadbro said:

Would this change the damage value of the sword that is displayed in the tooltip as well? Like this:

No, because with an event you can only change the damage currently caused
but you could also change this with the RenderToolTipEvent

if you don't want to do this, it would be better to overwrite the item (register it with the vanilla name and the mod id)

Posted
On 3/25/2021 at 4:09 AM, diesieben07 said:

You can use ItemAttributeModifierEvent to modify the attribute modifiers of any item.

Sorry for late reply, but is there a way to specifically set the item's attack damage with this? I see that you can use addAttributeModifier but that is not as practical, especially for my case.

Posted
16 minutes ago, notdeadbro said:

but that is not as practical, especially for my case.

Why

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
5 hours ago, Draco18s said:

Why

Well, I'm not sure if I'm being stupid, but the ItemAttributeModifierEvent is obviously an event executed every tick, so it just adds the attribute modifier over and over again.

Posted
8 hours ago, diesieben07 said:

It's not executed every tick, but it is executed every time attribute modifiers are computed.

However the map in the event is created from scratch every time, so modifiers should not persist. Show your ItemAttributeModifierEvent handler.

public void itemAttributeModifier(ItemAttributeModifierEvent event) {
		ItemStack stack = event.getItemStack();
		Item item = stack.getItem();
		
		if (item == Items.DIAMOND_SWORD) {
			stack.addAttributeModifier(Attributes.ATTACK_DAMAGE, new AttributeModifier("damage", 1.0D, AttributeModifier.Operation.MULTIPLY_BASE), EquipmentSlotType.MAINHAND);
		}
}

It continues to call the addAttributeModifier infinitely. In game, the tooltip ends up just overflowing with attribute modifiers.

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.