Elytra Like Repairable Tools Issue when attacking enemies

Started by Cosmiccube7 on

Topic category: Help with MCreator software

Last seen on 03:30, 8. Oct 2023
Joined Oct 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Elytra Like Repairable Tools Issue when attacking enemies

Recently I started making a mod that makes it so that netherite tools don't break and require repairing when they break similar to the elytra. Once the tool is broken you can not use it on blocks or entities. My problem here is that for some weird reason when I attack a mob with a tool with Damage 2030 which is one use away from breaking on all netherite tools and sword it they break.

Its strange because I use the tool break trigger which gives the itemstack of the item broken then i just add the tool back on the same tick that it was destroyed but with 0 durability which works for right clicking and left clicking on blocks. E.g. right clicking axe on wood and mining a block. But FOR SOME REASON not when left clicking enemies, which is weird. I put chat message blocks in my procedures with the triggers before entity attacked, entity attacked and tool breaks when its at 0 durability to see what order things happen but that didn't help. Tool break was the last one being called which makes sense. Its like the tool is being forced to break.

I tested using the set item in off hand to a tool after i use the tool in the main hand to attack an enemy and that works flawlessly but I want it were the main hand is and I tried delaying adding the item to the players hand but that stopped everything from working. I also want to do it on the same tick otherwise you see the item pick up animation in the hotbar, I don't want it to look like they picked up another netherite sword.

Example Video:
https://drive.google.com/file/d/1lm01zWsE7u0tKfy_9ARzKgGmE353GLf2/view?usp=sharing
 

Last seen on 21:55, 20. Feb 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
There isn't a great way to…
Tue, 10/03/2023 - 02:14

There isn't a great way to avoid the pickup animation, though you can shorten it a bit- any function that adds something to the player's inventory, even if it replaces an existing item, plays the animation.

For swapping out items like this, I recommend instead running a procedure on player tick update that checks if the tool in their main or off hand is very near breaking, (that is, its current damage almost equals its max damage), and, if it is, plays the break sound, and swaps out the item with the broken variant.

When swapping, you'll likely also want to take into account custom names and enchantments, especially for Netherite tools. There's not a good way to transfer the enchantment data, you pretty much just have to check for and apply each enchantment individually if the original item has it. Custom names are a bit more complicated, but also less time consuming; you set the display name of the new item to the display name of the old item, (which you can save as a local variable). You can also check that the display name of the old item doesn't equal its registry name, otherwise if the item still has its default name, the new name will be italicized.

(When swapping names, you'll also want to make sure to subtract square brackets, [ ], from the display name. Whenever you get the display name, the string it returns is the display name in square brackets, which can definitly cause issues if you don't account for it.)

Last seen on 03:30, 8. Oct 2023
Joined Oct 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Thank you, ill try and do…
Tue, 10/03/2023 - 02:48

Thank you, ill try and do that. Its just annoying because I want all uses on a tool to be available and the durability to be set to zero when a tool is broken. Its more an esthetic choice to have the durability to be 0 and to me makes more sense than 1 to me but I guess it will be more consistent with the Elytra which 'breaks' at 1. 

Last seen on 03:30, 8. Oct 2023
Joined Oct 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Also without the tool…
Tue, 10/03/2023 - 02:53

Also without the tool breaking it means i don't have to replace the tool as all I need to do is cancel left click block, right click and entity attack events when at a certain durability. Which removes the whole needing to copy over the names of items, etc,

Last seen on 03:30, 8. Oct 2023
Joined Oct 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
That's if i don't want a…
Tue, 10/03/2023 - 02:54

That's if i don't want a custom sprite for a broken tool.

Last seen on 21:55, 20. Feb 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Netherite tools have…
Tue, 10/03/2023 - 02:56

Netherite tools have somewhere around 2,000 durability, so the difference between 0 and 1 shouldn't be noticeable. I'd be cautious about trying to cancel left clicks as a means of preventing damage though, a lot of other gameplay elements rely on this.

Last seen on 03:30, 8. Oct 2023
Joined Oct 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How would I make it so that…
Tue, 10/03/2023 - 05:07

How would I make it so that if I repair the broken sword item in an anvil it becomes a normal netherite sword?

Originally instead of having two different items i thought of swapping the textures but I am unsure of how to do that or if its possible. I have used the CIT thing in Optifine to replace an items texture based on name and I believe nbt tag is possible as well but I don't want to have to use optifine with my mod.

Last seen on 21:55, 20. Feb 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Anvils only increase…
Tue, 10/03/2023 - 14:52

Anvils only increase durability, they can't change items/do recipes, but you could use the smithing table.

Unfortunately, you'll either have to figure out the CIT thing, or manually swap out the item. (You would shrink the itemstack, and replace it with the broken variant, using local variables to transfer custom names, enchantments, etc.