#Copy item enchants to result

18 messages · Page 1 of 1 (latest)

prisma salmon
#

How to copy existing enchants to a new item in recipes server event? I'm curious copy nbt data isnt helps

autumn sphinxBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

golden slate
#

You can only do it for shaped/shapeless recipes

#

Although this is for 1.19.2, you should can adapt it to 1.18.2

ServerEvents.recipes(event => {
    let { kubejs } = event.recipes
    kubejs.shaped("iron_sword", ["SA"], {
        S: "iron_sword",
        A: "redstone"
    }).modifyResult((grid, item) => {
        let item = item.copy()
        return item.enchant("efficiency", 1)
    })
})
#

Or hmm whatever, I forgot what is the equivalent in 1.18.2

prisma salmon
golden slate
#

item.enchant will not remove any existing enchantment

prisma salmon
#

I want to do smth like that

`nbt2.merge({Enchantments: nbt1.get("StoredEnchantments")})

    let outputItem = result.withNBT(nbt2)`
golden slate
#

Unless the source code here is wrong or not as-is in 1.18.2

#

I mean, you can do whatever you like, that item.enchant is for demonstration that the nbt is copied

#

the nbt is copied when calling item.copy()

prisma salmon
#

but I want only copy enchantments

#

nbt2.merge({Enchantments: nbt1.get("StoredEnchantments")})

seems not to be work

golden slate
#

Hmmm, then do

modifyResult((grid, item) => {
        let item = item.copy()
        return Item.of(item.id, 1).enchant(item.enchantments)
    })
prisma salmon
#

does it apply to itemStack?

golden slate
#

It is called when the recipe tries to generate an output

#

And the return value is what the recipe will actually output

prisma salmon