I have encountered a problem while trying to make a simple function that restocks chests in a map.
My Current code:
execute at @e[tag=t1_1] run loot replace block ~ ~ ~ container.0 27 loot minecraft:empty
execute at @e[tag=t1_1] run setblock ~ ~ ~ air
execute at @e[tag=t1_1] run setblock ~ ~ ~ chest{LootTable:"house:chests/t1"}
execute at @e[tag=t2_1] run loot replace block ~ ~ ~ container.0 27 loot minecraft:empty
execute at @e[tag=t2_1] run setblock ~ ~ ~ air
execute at @e[tag=t2_1] run setblock ~ ~ ~ chest{LootTable:"house:chests/t2"}
execute at @e[tag=t3_1] run loot replace block ~ ~ ~ container.0 27 loot minecraft:empty
execute at @e[tag=t3_1] run setblock ~ ~ ~ air
execute at @e[tag=t3_1] run setblock ~ ~ ~ chest{LootTable:"house:chests/t3"}
I'm trying to make not place all chests and remove some of them. I couldnt figure out if this was possible with loot tables, and the normal way doesnt really work because of how its currently coded. Is there any way someone can help?
Update: I modified the loot table to sometimes spawn a stone in it, and if it does the chest gets removed. Code:
execute as @e[tag=t3_1] run execute at @s if block ~ ~ ~ minecraft:chest{Items:[{id:"minecraft:stone"}]} run setblock ~ ~ ~ air
One major problem is that it just straight will not work in a function. It works in a command block and in in-game chat, and if the function is called manually by a player. But it wont work if its in the function mentioned above. I'm confused.