Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-168457

Container's loot table `LootTable` loses entity context `this` when invoked via `loot` under a `minecraft:contents` entry



    • Type: Bug
    • Status: Open
    • Resolution: Unresolved
    • Affects Version/s: 1.15.1, 1.16.4
    • Fix Version/s: None
    • Labels:
    • Confirmation Status:
    • Category:


      When using the loot command to produce loot inside of a container via minecraft:contents, the block's "outer" loot table (see shulker_box.json) is aware of the acting entity. It can even distinguish between players vs mobs, as well as entity_scores, by using execute as to change the entity context.

      However, the "inner" loot table - defined by the container's LootTable (see table_with_scores.json), presumably invoked by minecraft:contents - loses all information about the acting entity despite it being the loot table to produce the final output.

      The expected behaviour is that the inner loot table would retain the same knowledge (such as the acting entity and its scores) as the outer loot table that invoked it.

      Steps to reproduce:

      # 1. Make sure to add the attached files as part of a datapack
      #     - `shulker_box.json` should replace the vanilla shulker box
      #     - `table_with_scores.json` can be in a custom namespace
      # 2. Set the shulker box with inner loot table and seed (for consistent/deterministic results)
      setblock ~2 ~ ~ minecraft:shulker_box{ LootTable: 'custom:table_with_scores', LootTableSeed: 1 }
      # 3. Run the `loot` command as a player to produce loot from mining the shulker box into a dummy container
      setblock ~1 ~ ~ minecraft:chest
      execute as @p run loot replace block ~1 ~ ~ container.0 mine ~2 ~ ~
      # 4. Summon and try it as a skeleton to confirm that the outer loot table is aware of the difference
      summon minecraft:skeleton ~ ~ ~ {NoAI: true, NoGravity: true}
      execute as @e[type=skeleton, sort=nearest, limit=1] run loot replace block ~1 ~ ~ container.0 mine ~ ~2 ~
      # 5. Create the dummy objective and assign various scores to the player.
      # Observe how the scores influence the outcome of the outer table, but not the inner table.
      scoreboard objectives add scratch.foo dummy
      scoreboard players set @p scratch.foo -1
      scoreboard players set @p scratch.foo 5
      scoreboard players set @p scratch.foo 100




            Unassigned Unassigned
            Arcensoth Arcensoth
            6 Vote for this issue
            1 Start watching this issue