1

Is it possible to create conditional loot tables based on an item? I'm trying to recreate the survival games with guns experience I played long ago on an old server and am trying to set up the system that spawns loot in all the chests using loot tables.

This is what I'm trying to achieve, a chest would spawn with the following:

  • Random Ammo type and count
  • One random gun that supports that ammo type
  • Other items (potions, armor, etc.)

So the idea is that the chest would first roll a random ammo type, but would then roll a random gun for that specific ammo type. I'm using https://misode.github.io/loot-table/, and have all of the weapons and ammo in separate loot tables. I thought I could use set_loot_table function for each ammo type and assign it the compatible guns, but that doesn't seem to work. I'm a noob regarding JSON, so I won't be able to implement pseudo code anyone has, but I'll try my best. For anyone who's wondering, I'm talking about the Timeless and Classics gun mod.

1 Answer 1

1

Here is an example of a loot table that might work. If it does, it'll need some extra steps. This loot table is able to match the ammo and guns together (or in this case, arrows with bows and fireworks with crossbows) by putting the decision into a scoreboard. To use this, first use /execute store result score target_name target_objective run random range 0..1 with the /random command (added in 1.20.2) to generate a random number within the range of different ammos you have. Then, the loot table will read this numbers and choose the first item that has the specific condition that matches the scoreboard. To add more items independent of the ammo and gun conditions, put them in a separate pool (not the first or second).

You can replace "target_name" and "target_objective" with whatever you want. To add more ammos or guns, just copy the previous items that use the value_check, but remember to increase the range in the random command or they won't be rolled.

{
  "pools": [
    {
      "rolls": 1,
      "entries": [
        {
          "type": "minecraft:alternatives",
          "children": [
            {
              "type": "minecraft:item",
              "name": "minecraft:arrow",
              "conditions": [
                {
                  "condition": "minecraft:value_check",
                  "value": {
                    "type": "minecraft:score",
                    "target": {
                      "type": "minecraft:fixed",
                      "name": "target_name"
                    },
                    "score": "target_objective"
                  },
                  "range": 0
                }
              ]
            },
            {
              "type": "minecraft:item",
              "name": "minecraft:firework_rocket",
              "conditions": [
                {
                  "condition": "minecraft:value_check",
                  "value": {
                    "type": "minecraft:score",
                    "target": {
                      "type": "minecraft:fixed",
                      "name": "target_name"
                    },
                    "score": "target_objective"
                  },
                  "range": 1
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "rolls": 1,
      "entries": [
        {
          "type": "minecraft:alternatives",
          "children": [
            {
              "type": "minecraft:item",
              "name": "minecraft:bow",
              "conditions": [
                {
                  "condition": "minecraft:value_check",
                  "value": {
                    "type": "minecraft:score",
                    "target": {
                      "type": "minecraft:fixed",
                      "name": "target_name"
                    },
                    "score": "target_objective"
                  },
                  "range": 0
                }
              ]
            },
            {
              "type": "minecraft:item",
              "name": "minecraft:crossbow",
              "conditions": [
                {
                  "condition": "minecraft:value_check",
                  "value": {
                    "type": "minecraft:score",
                    "target": {
                      "type": "minecraft:fixed",
                      "name": "target_name"
                    },
                    "score": "target_objective"
                  },
                  "range": 1
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "rolls": 1,
      "entries": [
        {
          "type": "minecraft:item",
          "name": "minecraft:stone"
        }
      ]
    }
  ]
}

You must log in to answer this question.

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