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

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

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

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)

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

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.

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

  • Author

Also, a side note, is anyone aware of why the diamond sword is not getting its updated tooltip?

Here's my code:

1061556617_Screenshot(4).png.9dcdc7056f11a0210d5efbb8ac634435.png

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

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.