TUTORIAL - How to make loot tables affected by weather and time

Started by Mariano Argüello on

Topic category: User side tutorials

Joined Feb 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
TUTORIAL - How to make loot tables affected by weather and time
Tue, 11/01/2022 - 19:24 (edited)

This tutorial will teach you how to incorporate conditions to loot tables that define if an item should or shouldn't generate in your container, based on the time of the day and if it's raining, thundering or clear. This is my first tutorial and it's very simple, but as i figured how this works, i thinked that not so many people knows about these conditions and how to use them properly, so here we go:

1) - Create an empty loot table

For this to work, we will need to edit our json file containing the code of the table, so the first step for that is to create a table with wherever properties you need (chest table, gameplay table, modifying the base game or for your mod, it doesn't matter). We just need the base table (you can also add this to an existing one). For this tutorial i'm gonna make one from scratch, you can then copy the formula and apply it wherever you want

2) - Save your table and then start editing the Code of it

Save your loot table, then click on "Edit code of selected mod element" on the workspace editor. You will end with something like this:

> After that, i'm gonna explain the 2 conditions we're going to use for this tutorial, they are the Time Check condition, which as its name says is going to check for the time of the day, and if the specificed range of time is met, the item under the condition will succesfully generate. Here's the code of a stick that only generates if is daytime in the provided world:

{
"type": "minecraft:chest",
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "minecraft:item",
"name": "minecraft:stick",
"conditions": [
{
"condition": "minecraft:time_check",
"value": {
"min": 0,
"max": 12500
},
"period": 24000
}
]
}
]
}
]
}

Note: You can experiment using the "period" entry. In this case, using 24000 seems to repeat the time check range over and over. So if you are on your day 4 for example, the time check will get the time relative to your current day. If someone knows how this elements works and can explain it better, please leave a comment

> And also the Weather Check condition, which will allow to spawn items only if is raining or thundering in your world. Here's an example of a bone that spawns when raining and a diamond that spawns only if thundering. If the time is clear the chest would be empty

{
"type": "minecraft:chest",
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "minecraft:item",
"name": "minecraft:diamond",
"conditions": [
{
"condition": "minecraft:weather_check",
"raining": false,
"thundering": true
}
]
},
{
"type": "minecraft:item",
"name": "minecraft:bone",
"conditions": [
{
"condition": "minecraft:weather_check",
"raining": true,
"thundering": false
}
]
}
]
}
]
}

3) - Choose your condition and build on top of it

You now only need to copy this code and change some things, like the item it spawns, its weight (you can add a count function to expand the stack size of that item) and more if you need to.

4) - Test your table in-game

Finally, enter your test world and spawn a chest with your loot (or simply use the /loot command) and verify if the table works according to your needs. If you followed this tutorial right, you should be able to get items on night/day or on rain/thunder. I hope this tutorial helped some of you out there, if you have any questions feel free to ask them in the comments, i'll try to help if i can!

Edited by Mariano Argüello on Tue, 11/01/2022 - 19:24