1

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.

1
  • What entitys are getting the tags your using?
    – bco2135
    Commented Dec 10, 2022 at 22:28

1 Answer 1

1

It looks like you are using a data pack (otherwise how would you have those loot tables), so I would recommend using a random_chance predicate to make a 50-50 decision.

Such predicate would look like this:

{
  "condition": "minecraft:random_chance",
  "chance": 0.5
}

It would go at this file path:

/data/<namespace>/predicates/<predicate_name>.json

And you could call upon it like this, this would make the command run only 50% of the time:

execute if predicate <namespace>:<predicate_name> run ...

You must log in to answer this question.

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