1

I'm trying to make a custom crafting system where you put the ingredients in a barrel, right-click with a carrot on a stick, and then boom! crafting! but when one of the ingredients, say a sword, has an enchantment on it, the product does not. How would I do this? It would be better if I could copy the entire NBT data and put it on the product, considering I do a lot with tags and such.

Here is my code:

execute if block ~ ~ ~-1 minecraft:barrel{CustomName:'{"text":"CraftingDSword"}'} run item replace block ~ ~ ~-1 container.0 with minecraft:netherite_sword{diamondriteSword:1b,display:{Name:'[{"text":"Diamondrite Sword","italic":false}]',Lore:['[{"text":"An extremely powerful sword.","italic":false,"bold":true,"color":"dark_red"}]']},Enchantments:[{}],AttributeModifiers:[{AttributeName:"generic.attack_damage",Amount:10,Slot:"mainhand",Name:"generic.attack_damage",UUID:[I;-12308,22523,182623,-45048]}]} 1
execute if block ~ ~ ~-1 minecraft:barrel{CustomName:'{"text":"CraftingDSword"}'} run data modify block ~ ~ ~-1 Items[0] append from block ~ ~ ~-1 Items[22]
execute if block ~ ~ ~-1 minecraft:barrel{CustomName:'{"text":"CraftingDSword"}'} run data remove block ~ ~ ~-1 Items[4]
execute if block ~ ~ ~-1 minecraft:barrel{CustomName:'{"text":"CraftingDSword"}'} run data remove block ~ ~ ~-1 Items[13]
execute if block ~ ~ ~-1 minecraft:barrel{CustomName:'{"text":"CraftingDSword"}'} run data merge block ~ ~ ~-1 {CustomName:"\"Barrel\""}

The first line puts the product into the barrel, the second line is supposed to put the NBT data from slot 22 into slot 0 (the product), the next two lines delete the materials used for the item, and the last line turns the name back to Barrel (I use custom container names to detect what crafting recipe the player is using.)

1 Answer 1

1

You're close. The issue is that Items[22] doesn't mean "take the item in the 22 slot" but it means "take the 23rd item in the list" (because it starts counting at 0).

Luckily there is a solution that lets you select a specific slot:

Items[{Slot:22b}]

The other issue is that you're trying to append the data. append only works on lists, not on objects. what you're looking for is merge, which combines two objects. You probably also don't want to merge the entire thing, because otherwise it will also overwrite the item itself. So all you want to copy is the tag part.

So your second command needs to look like this:

execute if block ~ ~ ~-1 minecraft:barrel{CustomName:'{"text":"CraftingDSword"}'} run data modify block ~ ~ ~-1 Items[{Slot:0b}].tag merge from block ~ ~ ~-1 Items[{Slot:22b}].tag

Be aware that this might have some unintended side effects, for example if the input item has a name it will probably overwrite the name of the netherite sword.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .