Skip to content

Instantly share code, notes, and snippets.

@Dinnerbone
Created October 19, 2015 16:59
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Dinnerbone/16a5543bb6bea24af227 to your computer and use it in GitHub Desktop.
Save Dinnerbone/16a5543bb6bea24af227 to your computer and use it in GitHub Desktop.
This is an example of the current spawn bonus chest loot table in Minecraft, in the (possibly) new loot table data format.
[
{
"item": "minecraft:stick",
"weight": 10,
"functions": [
{
"function": "minecraft:set_count",
"min": 1,
"max": 3
}
]
},
{
"item": "minecraft:planks",
"weight": 10,
"functions": [
{
"function": "minecraft:set_count",
"min": 1,
"max": 3
}
]
},
{
"item": "minecraft:log",
"weight": 10,
"functions": [
{
"function": "minecraft:set_count",
"min": 1,
"max": 3
}
]
},
{
"item": "minecraft:stone_axe",
"weight": 3
},
{
"item": "minecraft:wooden_axe",
"weight": 5
},
{
"item": "minecraft:stone_pickaxe",
"weight": 3
},
{
"item": "minecraft:wooden_pickaxe",
"weight": 5
},
{
"item": "minecraft:apple",
"weight": 5,
"functions": [
{
"function": "minecraft:set_count",
"min": 2,
"max": 3
}
]
},
{
"item": "minecraft:bread",
"weight": 3,
"functions": [
{
"function": "minecraft:set_count",
"min": 2,
"max": 3
}
]
},
{
"item": "minecraft:log2",
"weight": 10,
"functions": [
{
"function": "minecraft:set_count",
"min": 1,
"max": 3
}
]
}
]
@Nulcheck
Copy link

hi

@BitMonster1010
Copy link

Hi dinnerbone! Can you add vertical slabs to minecraft? And slab linking! #hugs #pls

@Fishrock123
Copy link

This looks fairly sound.

A weight between 0 and 1 may be more easily understood though. (Where 0 is never and 1 is always)

@goosewoman
Copy link

@Fishrock123

I disagree, with an integer weight I can easily divide the whole table in hundred, or thousand. Then I can just pretend it's percentages or per mils. It's all about how it's explained to the end user.

@ljfa-ag
Copy link

ljfa-ag commented Oct 19, 2015

Except that it doesn't really work (or is equally as unintuitive) when the weights don't add up to 1.

@manuelgu
Copy link

Looks cool. Will add a new level of Map Making to the game. Especially Dungeon / Explore Maps can be improved quite a lot with that!

@Rubisk
Copy link

Rubisk commented Oct 19, 2015

Weight is very intuitive - if you want to add one item with an equal chance, just add it and you don't have to go and change the percentage of all other items ;-)

If you find it confusing - just make all weight add up to 100?

@Arcensoth
Copy link

Using integer weights is the superior method. It allows you to seamlessly add items, remove items, and change existing items, without having to update anything else in the table. Anyone who has dealt with MobSpawners should understand. (In contrast, having weights between 0 and 1 that all add to 1 will potentially require you to go through and fix the entire table whenever a change is made.) As for intuition - @Rubisk is exactly right.

Anyway, awesome! I'm definitely looking forward to this feature, Dinnerbone. I was just about to start working on a randomized chest system using MobSpawners - but maybe I should hold back for the next few snapshots!

@caseif
Copy link

caseif commented Oct 19, 2015

@XxMoNsTeR Time and a place buddy. This is neither the time nor the place.

@koosemose
Copy link

Looks good.

And this is definitely the best way to do weighted chance, it's the only method I've seen of doing weights, if it's floats that add up to 1 it's not weights, it's percentage chance. Though I rather hope the weights are floats rather than ints, so if someone, for example, wanted to go back in and add extremely rare loot they could do so without having to change all the weights (with this table as a basis, just add an item with a weight of .1 rather than having to multiply all current weights by 10 and adding an item with weight 1 for the same end result).

I am also assuming that it will be possible to include items with NBT data, since that would be required to have things like enchanted books that are currently in loot chests.

It would also be nice to have some form of sub tables, such that if I for example wanted an option to have enchanted swords with some combination of sharpness, unbreakable, and looting I could instead tell it to have a sword, with whatever base data I want on it, and then have it add between 0 and 3 (with varying weights) enchantments out of those 3, rather than needing to list separately all combinations of those 3 enchantments.

And a fine request/suggestion/hope, the ability to set certain items to be mutually exclusive, such that I could have a loot table that could give you either a sword or an ax but not both along with a completely random assortment of other items. Though now that I think of it that could probably be achieved with sub-tables, if one of the possible entries is 1 result from a subtable that has either a sword or an axe as options, that would achieve the desired result.

@HenryLoenwind
Copy link

Please be kind to us modders and add a method to register additional tables to be merged with with the in-memory table from the beginning.

@riddle
Copy link

riddle commented Oct 20, 2015

@Dinnerbone When we were writing our own plugins, we created a loot table format much more versatile than this. I understand you wanna do JSON, but maybe look at what could be possible:

https://github.com/CoreNetwork/Mantle/wiki/Loot-table-format

Example of actual loot tables

@Wombosvideo
Copy link

gistcomment-1599786 totally with you

@mhmd223
Copy link

mhmd223 commented Oct 20, 2015

hi

@towerofnix
Copy link

Looking awesome!

Do we have a list of functions somewhere? Can they also be edited?

@towerofnix
Copy link

I hacked around a little and have found this code, for anybody who wants to see.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment