Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix durabilityUsed for items with components #123

Merged
merged 5 commits into from
Jan 11, 2025

Conversation

rom1504
Copy link
Member

@rom1504 rom1504 commented Jan 11, 2025

Fixes #121

Update durabilityUsed getter to support items with components.

  • Modify durabilityUsed getter in index.js to check the components array for the damage component.
  • Use the damage component value for durabilityUsed if found.
  • Fall back to checking the Damage field in nbt or metadata if the damage component is not found.
  • Add test cases in test/basic.test.js to verify durabilityUsed returns the correct value for items with and without the damage component.

For more details, open the Copilot Workspace session.

Fixes #121

Update `durabilityUsed` getter to support items with components.

* Modify `durabilityUsed` getter in `index.js` to check the `components` array for the `damage` component.
* Use the `damage` component value for `durabilityUsed` if found.
* Fall back to checking the `Damage` field in `nbt` or `metadata` if the `damage` component is not found.
* Add test cases in `test/basic.test.js` to verify `durabilityUsed` returns the correct value for items with and without the `damage` component.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/PrismarineJS/prismarine-item/issues/121?shareId=XXXX-XXXX-XXXX-XXXX).
@rom1504
Copy link
Member Author

rom1504 commented Jan 11, 2025

Can you review it too @extremeheat ? The issue author says it fixes. I think it looks correct

Copy link
Member

@extremeheat extremeheat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There could be a component map so no need to constantly search but otherwise LGTM

…e` component

* Add a component map to avoid constantly searching the `components` array
* Use the `damage` component value for `durabilityUsed` if found
* Fall back to checking the `Damage` field in `nbt` or `metadata` if `damage` component is not found
* Add test cases to verify `durabilityUsed` returns correct value for items with and without the `damage` component
* Use `fromNotch` method to create the item
* Add `components` array with `damage` component to the item
* Verify `durabilityUsed` returns correct value for items with and without `damage` component
@rom1504
Copy link
Member Author

rom1504 commented Jan 11, 2025

oh well it broke it, will fix later

@rom1504
Copy link
Member Author

rom1504 commented Jan 11, 2025

ah no got it, there is no nbt

@rom1504 rom1504 merged commit 70fc068 into master Jan 11, 2025
3 checks passed
@rom1504
Copy link
Member Author

rom1504 commented Jan 11, 2025

/makerelease

@rom1504bot rom1504bot mentioned this pull request Jan 11, 2025
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.

Doesn't seem to get the item.durabilityUsed correctly since 1.20.5
2 participants