-
Notifications
You must be signed in to change notification settings - Fork 12
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
Add getItemEnchantmentLevel() function, to easily see if an item has an enchantment and at what level. #110
Conversation
This seems unnecessary when you can do this in one line already with .find item.enchants.find(e => e.name === 'efficiency')?.level |
In this case You can get a dict yourself with |
Ah, one thing I did realize with the current implementation is that it has a enchants setter (these are bad), so to edit the enchants, you have to const enchants = item.enchants
enchants.find(ench => enc.name === 'efficiency').level = 3
item.enchants = enchants IMO all the get/set inside prismarine-item should be removed for non-obvious usage patterns like this. |
I made this commit because I am translating large parts of the java source code to mineflayer to implement more clicking tyoes, so having identically named functions is a big help. Also in my opinion both setters and getters should not be a thing, they are both stupid and serve no purpose. I would choose |
@@ -158,6 +158,14 @@ function loader (registryOrVersion) { | |||
throw new Error("Don't know how to deserialize for this mc version ") | |||
} | |||
|
|||
getItemEnchantmentLevel (enchantName) { | |||
if (!this.enchants) return 0 | |||
for (const enchant of this.enchants) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enchants should be a dict if you want that
@@ -24,6 +24,7 @@ export class Item { | |||
get blocksCanDestroy(): [string][]; | |||
set blocksCanDestroy(blockNames: string[]); | |||
repairCost: number; | |||
getItemEnchantmentLevel(enchantName: string): number |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you update the doc
old, please re open to finish |
title