#Help with getting enchantment type and level

1 messages · Page 1 of 1 (latest)

wooden echo
#

I had this: enchantments.includes( "fortune" )?.level ?? 0 But it always returns 0 since I think 1.20.50. Is there a different method we need to use or is there no way?

Here is the enchantments variable:

const enchantments = item.getComponent("minecraft:enchantable").getEnchantments().map((e) => e.id);```
rancid hamlet
#

Try with e.level

bleak trellis
#
JSON.stringify(enchantable.getEnchantments())
wooden echo
#

Log this?

bleak trellis
#

ye...

wooden echo
#

I get issues with these too

 const level = enchantmentsLevel ?? 0;
            const drop = drops.drops[level];
            const amount = Math.random() * (drop.max - drop.min) + drop.min;```
bleak trellis
#

not beta...

#

welp that's how it looks then

wooden echo
#

So there is no way to get level of an enchantment?

#
const enchantmentsLevel = item.getComponent("minecraft:enchantable").getEnchantments().map((e) => e.level);``` I log this and it returns `[3, 1]`
bleak trellis
#

strange

wooden echo
#

I think because of this, the drops tries to check for both in the min and max values

#

I think I need that [0] (idk what's the term) to only return the first value

rancid hamlet
#

But I think it should return only the current value, right?

wooden echo
#

Oh.. it returns all enchanted levles

rancid hamlet
#

Lollllllll

wooden echo
#

Darn... I don't know how to get level of fortune then

rancid hamlet
#

Remember has code for that

#

I think

bleak trellis
#

item components are null in non-beta stable

wooden echo
#

I use beta apis

bleak trellis
wooden echo
bleak trellis
#

[].map(e => e.type.id)

wooden echo
#

Yea my peanut brain is not functioning right now

bleak trellis
#

always have visuals, i tell ya

rancid hamlet
#

Wait, do you want just the fortune enchantment?

wooden echo
#

Yea

bleak trellis
#

.getEnchantment...

wooden echo
#

I need to pass fortune's enchantment levels into drops to calculate how many items to drop based on fortune's level

wooden echo
rancid hamlet
#

Why don't use getEnchantment("fortune")

bleak trellis
wooden echo
#
 const level = enchantments.getEnchantment( "fortune" )?.level ?? 0;```
bleak trellis
#

;-;

rancid hamlet
#

item.getComponent("enchantable").getEnchantment("fortune")

wooden echo
#
item.getComponent("minecraft:enchantable").getEnchantment( "fortune" )?.level ?? 0```

This worked 😔 I hate when it tells me it won't work and then it decided to work
bleak trellis
#

let the brain cook smh