Posted March 23, 20214 yr 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 March 23, 20214 yr by notdeadbro
March 24, 20214 yr 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
March 24, 20214 yr 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: I want to literally be able to change its attack damage value.
March 25, 20214 yr 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)
March 29, 20214 yr 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.
March 29, 20214 yr 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.
March 30, 20214 yr 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.
March 30, 20214 yr Author Also, a side note, is anyone aware of why the diamond sword is not getting its updated tooltip? Here's my code:
March 30, 20214 yr 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.