#Copy item enchants to result
18 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
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
I see there you have provided exact enchant, not copy from existing item
item.enchant will not remove any existing enchantment
I want to do smth like that
`nbt2.merge({Enchantments: nbt1.get("StoredEnchantments")})
let outputItem = result.withNBT(nbt2)`
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()
but I want only copy enchantments
nbt2.merge({Enchantments: nbt1.get("StoredEnchantments")})
seems not to be work
Hmmm, then do
modifyResult((grid, item) => {
let item = item.copy()
return Item.of(item.id, 1).enchant(item.enchantments)
})
does it apply to itemStack?
It is called when the recipe tries to generate an output
And the return value is what the recipe will actually output
Works like a charm, thank you.