#can't enchant custom items?

1 messages ยท Page 1 of 1 (latest)

naive hearth
#

I made a script to randomly enchant any weapon tool or armor item (and if they have enchants to remove those and random enchant again)

But custom items are not working. Not sure what I need to do to allow custom items to enchant as it seems to think they don't have enchantment component. But they do I think my code has an issue somewhere I can't seem to find rn

#

              // Get enchantments
              let enchantsComponent = item.getComponent("minecraft:enchantments");
              if (enchantsComponent) {
                  let enchantments = Array.from(enchantsComponent.enchantments);
                  if (enchantments.length > 0) {
                      //console.warn("Enchantments:");
                      enchantments.forEach(enchant => {
                          //console.warn("- " + JSON.stringify(enchant.type) + " (Level: " + enchant.level + ")");
                      });
                  } else {
                      sender.sendMessage("No enchantments on this item.");
                  }
              } else {
                  sender.sendMessage("This item cannot have enchantments.");
              }

          } catch (e) {
              //console.warn("Error executing command: ", e + e.stack);
          }
      });
  }
});
#

Just a snippet

gusty hamlet
#

send json of the item

naive hearth
naive hearth
#

Mainly custom swords, armor, tools

gusty hamlet
naive hearth
#

Lol okay I'll try to find one I've used

naive hearth
gusty hamlet
#

but anyways

naive hearth
#

Oh sorry

gusty hamlet
#

bcz i think u didnt

naive hearth
#

Too big for me to paste I need nitro ๐Ÿ˜ข