0

Usually, this wouldn't be an issue. But there's a problem with my code running. I want to have a custom crafting recipe for Netherite Boots. It works fine, but the problem arises when you have more than one barrel around you. (My datapack has it so when you right click with a carrot on a stick and there's a barrel with the correct ingredients in the correct spots in it, it crafts the item.)

If there's just one barrel, then it works perfectly, no bugs. But if you have more than one barrel around you, the final product will be copied into every barrel around you. Here is my code.

execute unless data block ~1 ~ ~ Items[7] run data remove block ~1 ~ ~ Items
execute unless data block ~1 ~ ~ Items[7] run item replace block ~1 ~ ~ container.0 with minecraft:netherite_boots{display:{Name:'[{"text":"Diamondrite Boots","italic":false}]',Lore:['[{"text":"B O O T S.","italic":false,"bold":true,"color":"dark_red"}]']},Enchantments:[{}],AttributeModifiers:[{AttributeName:"generic.armor",Amount:5,Slot:feet,Name:"generic.armor",UUID:[I;-12307,2572,184118,-5144]},{AttributeName:"generic.armor_toughness",Amount:5,Name:"generic.armor_toughness",UUID:[I;-12307,30262,19112,-60524],Slot:"feet"},{AttributeName:"generic.knockback_resistance",Amount:0.2,Name:"generic.knockback_resistance",UUID:[I;-12307,30362,19112,-60724],Slot:"feet"},{AttributeName:"generic.movement_speed",Amount:0.4,Slot:feet,Operation:1,Name:"generic.movement_speed",UUID:[I;-12307,31662,19112,-63324]}]} 1
execute unless data block ~-1 ~ ~ Items[7] run data remove block ~-1 ~ ~ Items
execute unless data block ~-1 ~ ~ Items[7] run item replace block ~-1 ~ ~ container.0 with minecraft:netherite_boots{display:{Name:'[{"text":"Diamondrite Boots","italic":false}]',Lore:['[{"text":"Extremely tough boots.","italic":false,"bold":true,"color":"dark_red"}]']},Enchantments:[{}],AttributeModifiers:[{AttributeName:"generic.armor",Amount:5,Slot:feet,Name:"generic.armor",UUID:[I;-12307,2572,184118,-5144]},{AttributeName:"generic.armor_toughness",Amount:5,Name:"generic.armor_toughness",UUID:[I;-12307,30262,19112,-60524],Slot:"feet"},{AttributeName:"generic.knockback_resistance",Amount:0.2,Name:"generic.knockback_resistance",UUID:[I;-12307,30362,19112,-60724],Slot:"feet"},{AttributeName:"generic.movement_speed",Amount:0.4,Slot:feet,Operation:1,Name:"generic.movement_speed",UUID:[I;-12307,31662,19112,-63324]}]} 1
execute unless data block ~ ~ ~1 Items[7] run data remove block ~ ~ ~1 Items
execute unless data block ~ ~ ~1 Items[7] run item replace block ~ ~ ~1 container.0 with minecraft:netherite_boots{display:{Name:'[{"text":"Diamondrite Boots","italic":false}]',Lore:['[{"text":"Extremely tough boots.","italic":false,"bold":true,"color":"dark_red"}]']},Enchantments:[{}],AttributeModifiers:[{AttributeName:"generic.armor",Amount:5,Slot:feet,Name:"generic.armor",UUID:[I;-12307,2572,184118,-5144]},{AttributeName:"generic.armor_toughness",Amount:5,Name:"generic.armor_toughness",UUID:[I;-12307,30262,19112,-60524],Slot:"feet"},{AttributeName:"generic.knockback_resistance",Amount:0.2,Name:"generic.knockback_resistance",UUID:[I;-12307,30362,19112,-60724],Slot:"feet"},{AttributeName:"generic.movement_speed",Amount:0.4,Slot:feet,Operation:1,Name:"generic.movement_speed",UUID:[I;-12307,31662,19112,-63324]}]} 1
execute unless data block ~ ~ ~-1 Items[7] run data remove block ~ ~ ~-1 Items
execute unless data block ~ ~ ~-1 Items[7] run item replace block ~ ~ ~-1 container.0 with minecraft:netherite_boots{display:{Name:'[{"text":"Diamondrite Boots","italic":false}]',Lore:['[{"text":"Extremely tough boots.","italic":false,"bold":true,"color":"dark_red"}]']},Enchantments:[{}],AttributeModifiers:[{AttributeName:"generic.armor",Amount:5,Slot:feet,Name:"generic.armor",UUID:[I;-12307,2572,184118,-5144]},{AttributeName:"generic.armor_toughness",Amount:5,Name:"generic.armor_toughness",UUID:[I;-12307,30262,19112,-60524],Slot:"feet"},{AttributeName:"generic.knockback_resistance",Amount:0.2,Name:"generic.knockback_resistance",UUID:[I;-12307,30362,19112,-60724],Slot:"feet"},{AttributeName:"generic.movement_speed",Amount:0.4,Slot:feet,Operation:1,Name:"generic.movement_speed",UUID:[I;-12307,31662,19112,-63324]}]} 1
2
  • You could specify the correct barrel by changing it's name or some other property of the barrel, since it is a block entity. If you don't need any custom items in the crafting recipe, you could also just create a custom recipe that crafts a knowledge book, check for that with an advancement, and give players the custom item with a function. Commented Jan 8, 2023 at 23:20
  • 1
    Wouldn't it be a lot more intuitive for the players if not every barrel around them would craft the thing, but the barrel that they are looking at instead? Though there the carrot on a stick rightclick might not work in favor of opening the barrel, which means you'd need to detect the opening of the barrel (while holding a specific item?) instead. Would that be a good solution?
    – Plagiatus
    Commented Jan 31, 2023 at 7:40

1 Answer 1

1

Perhaps summon an armor stand in the first barrel found that has the ingredients, then merge block data relative to that.

So even if there are multiple barrels, and even if they have the right ingredients, only execute on the first barrel found.

If youre wondering how to do this, perhaps tag the player as "crafting".

so:

-if player is not tagged as already crafting check barrel North, if it has the ingredients summon armor stand, tag player, merge barrel data

-if player is not tagged as already crafting check barrel east, if it has the ingredients summon armor stand, tag player, merge barrel data

etc etc then remove "crafting" tag at the end

also note that merging data relative to an armor stand instead of the player prevents the slight possibility of the player moving at just the right time, executing the first command and losing their items but not gaining the boots.

You must log in to answer this question.

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