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

Doesn't seem to get the item.durabilityUsed correctly since 1.20.5 #121

Closed
imharvol opened this issue Jan 11, 2025 · 3 comments · Fixed by #123
Closed

Doesn't seem to get the item.durabilityUsed correctly since 1.20.5 #121

imharvol opened this issue Jan 11, 2025 · 3 comments · Fixed by #123

Comments

@imharvol
Copy link

imharvol commented Jan 11, 2025

To recreate:

/give bot minecraft:golden_pickaxe[damage=15] 1

If you print the inventory it will return:

    {
      "type": 830,
      "count": 1,
      "metadata": 0,
      "nbt": {
        "type": "compound",
        "name": "",
        "value": {
          "Damage": {
            "type": "int",
            "value": 0
          }
        }
      },
      "components": [
        {
          "type": "damage",
          "data": 15
        }
      ],
      "removedComponents": [],
      "stackId": null,
      "name": "golden_pickaxe",
      "displayName": "Golden Pickaxe",
      "stackSize": 1,
      "maxDurability": 32,
      "slot": 36
    }

And item.durabilityUsed returns 0

@extremeheat
Copy link
Member

Yes, we don't yet support item components. You can read the component data yourself in meantime under the components array

rom1504 added a commit that referenced this issue 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](https://copilot-workspace.githubnext.com/PrismarineJS/prismarine-item/issues/121?shareId=XXXX-XXXX-XXXX-XXXX).
@rom1504
Copy link
Member

rom1504 commented Jan 11, 2025

#123 AI implemented a fix

@imharvol do you feel like trying this fixes your issue?

@imharvol
Copy link
Author

@rom1504 yes it does! Thank you

rom1504 added a commit that referenced this issue Jan 11, 2025
* Fix durabilityUsed for items with components

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).

* Update `durabilityUsed` getter to check `components` array for `damage` 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

* Update test case for `durabilityUsed` with 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

* Check components is defined

* Fix test
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 a pull request may close this issue.

3 participants