How to save item damage ?

Started by zorualeloupsolitaire on

Topic category: Help with Minecraft modding (Java Edition)

Joined Nov 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to save item damage ?

Hello,

In my mod, players can put on armor to be stronger and get effects. But when they remove their armor using the R key, the armor is removed and they receive a box containing their armor instead.

The problem is that when they right-click on the ground, the box disappears and the armor comes back on their body, but is repaired as if it were new armor.

I'd like to know if there's a way of preserving the armor damage received in battle. 

Here's a picture of my procedure from the box

Joined Jun 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Oh, oh, I know this one, I'm…
Sun, 01/19/2025 - 12:41

Oh, oh, I know this one, I'm creating a superhero mod, where Iron Man stores all of it's armors in suitcases like that one from the second movie. 

 

So the procedure goes like that: 

Create an itemstack representing the item that stores the armor. 

First, you will set the itemstack local variable to the item containing the armor. 

Second: you will set the an variable of that item (something you may call uses or durability) to: rounded up(damage of the chest armor / durability multiplicator of the chest). You can make some changes on this formula to better suit what you are trying to do, you could also create four item variables on that item to store the armor of each part which will result this to being more accurate to the actual damage of the items, but if you want the item containing the armor to eventually break or be repaired, I think using only one variable it's easier to handle. 

Lastly, you will add that itemstack variable to the player inventory. 

 

Now, on the procedure of activating the armor, you will do the inverse process, add the parts to the player inventory and set their durabilitys to (the variable stored on the armor container * each part durability multiplyer.

 

So, to sum up what was done here, you will aproximate the damage took by the armor taking the damage of the chest as an basis, converting that on a "unified armor damage" that will be stored on the armor container. And once you activate the armor again, it will take that unified damage and aproximate them to what it represent to each part of the armor. So, that's it. Sorry for the bad english tho, it ain't my first language.