Skip to content

Conversation

@youke1686
Copy link

@youke1686 youke1686 commented Jan 1, 2026

I added the durability bar to tools to replace the original randomly-broken logic.
Earlier discussion is in issues/172

When I was playing Minecraft, I have a principle that only let one of my pickaxes has it's durability bar. in other words, keep the extra tools completely new. But if the tools even don't have the durability bar and just broken randomly, it really makes me uneasy. Sometimes, I even think I was playing Terraria! That's why I made this pull request.

In this pull request, I used the amount of tool (inventory_count field) to store the durability message. In Minecraft, the tools can only have one in each slot, which means the inventory_count field of a tool is always set to a meaningless number 1. I just made the number 1 means the full durability when the number 255 means the tool should broken. It causes no extra memory usage but preformed well.

Accordingly, I also made the following changes:

  • defined a list of tools which should have a durability and how many durabilities they should have.
  • updated the "S->C Set Container Slot" packet to make it able to send the durability message.
  • updated the "C->S Click Container" packet to prevent durability changes when moving tools in container slots

Since the inventory_count field only ranging from 0 to 255, it is not enough to store the exact durability. Considered that what I have added is just a durability bar rather than the number of the durability, I made the durability decreased randomly. While not pixel-perfect, it's statistically accurate. As long as you isn't boring enough to count how many blocks a pickaxe can break, It is completely same as the vanilla Minecraft.

This is my first github pull request. If my pull request is incorrect or has any issues, I’m happy to make corrections.
Thank you for creating and maintaining such an inspiring project. I’d be grateful if you could take a moment to review.

image image image

@uncreativeCultist
Copy link

it's probably just my odd use-case of a server, but your fork is failing to build due to "unknown type name 'bool'"
is it possible it's not defined or something?

@youke1686
Copy link
Author

youke1686 commented Jan 9, 2026

oh, I think it is my fault.
let me check it.

@youke1686
Copy link
Author

youke1686 commented Jan 9, 2026

I think it is hard to tell who was wrong.
it's seems that bool isn't supported on all versions of GCC.
for some reasons, it hasn't caluse an error on my environment, but it shouldn't being ignored.
I'll fix it soon by using defines like what you adviced.

@youke1686
Copy link
Author

@uncreativeCultist
I think I have already fixed the error.
you can try to bulid it again.
thanks for your feedback. it helps me a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants