본문으로 건너뛰기

루트 테이블 레퍼런스 (1/7)

MS Learn(MicrosoftDocs/minecraft-creator a9fd1c0, CC BY 4.0)의 레퍼런스를 발췌한 쪽이다. 원문의 상대 링크는 제거했다.

(출처: ms-learn, creator/Documents/IntroductionToLootTables.md)

Introduction to Loot and Trade Tables​

When you do something fun and get rewarded with loot in Minecraft, or trade with a villager, then behind the scenes there was—yes—a JSON file or two: specifically, a loot table or a trade table. The mechanisms of the two aren't identical, but they overlap.

Loot tables​

:::image type="content" source="Media/IntroToLootTables/Loot-and-Trading-Tables.jpg" alt-text="Image showing Steve opening a chest to find glowing loot.":::

The five categories of loot tables in Vanilla Minecraft are blocks, chests, entities, equipment, and gameplay (such as fishing, milking a mooshroom, or watching your sniffer find seeds).

Loot table files live in a directory (cleverly named loot_tables) at the root level of a behavior pack. If you have more than one type of loot table in your behavior pack, you can put each type in its own subfolder, but that's not required.

:::image type="content" source="Media/IntroToLootTables/loot-behavior-pack-structure.png" alt-text="Image of the structure of a behavior pack showing that the example block loot file can go into a blocks subfolder or directly in the loot_tables folder.":::

Think of a numbered list of items. Each list lets you, the player, roll a set of dice one or more times to get a number, and that number corresponds to an item in the list. As an example, here is the loot table for gifts a pet cat can bring you in the morning:

Die RollLoot Result
1Rabbit Hide
2Rabbit Foot
3Chicken
4Feather
5Rotten Flesh
6String
7Phantom Membrane

And here's the corresponding JSON file for that table:

{
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "item",
"name": "minecraft:rabbit_hide",
"weight": 10
},
{
"type": "item",
"name": "minecraft:rabbit_foot",
"weight": 10
},
{
"type": "item",
"name": "minecraft:chicken",
"weight": 10
},
{
"type": "item",
"name": "minecraft:feather",
"weight": 10
},
{
"type": "item",
"name": "minecraft:rotten_flesh",
"weight": 10
},
{
"type": "item",
"name": "minecraft:string",
"weight": 10
},
{
"type": "item",
"name": "minecraft:phantom_membrane",
"weight": 2
}
]
}
]
}

The top-level pools key contains one or more loot tables. As a creator, you might want to have different pools so you can drop different loot to your players if they satisfy different loot table conditions. Each pool has these properties:

  • rolls: how many times the pool will be rolled to select an entry. This can be a single integer (how many times to roll), or a range like {"min": 1, "max": 3}, which randomly selects 1 to 3 rolls.
  • entries: the actual list of objects the game selects from.
    • type can be item, but can also be loot_table to select from another loot table or empty to give a chance of no loot on a roll.
    • name is the name of the item or the loot table.
    • weight is a relative chance for how often this result will come up. An entry with a weight of 2 is twice as likely to come up as an entry with a weight of 1, but one-fifth as likely to come up with a weight of 10. (As you can see, getting a phantom membrane is rarer than getting a bit of string or a chicken. Imagine a cat bringing down a phantom! Now you know why they avoid cats.)
    • functions are optional operations that can modify an entry's result in different ways, such as setting an item's lore or putting content into a book. See Loot and Trade Table Functions for more information.
  • conditions are optional requirements that must be met for the pool to be rolled. See Loot Table Conditions for more information about conditions.

Trade tables​

Like a loot table, a trade table is, at its heart, a list of items—but it's a list of item pairs, what a villager wants and what they'll give you in exchange. For instance, a butcher might have this trade table:

WantsGives
PorkchopEmerald
ChickenEmerald
EmeraldCooked Porkchop
EmeraldCooked Chicken

In practice, trade tables are considerably more complicated than loot tables. They can specify individual trades or trade groups (similar to loot table pools), tiers (sets of trade or trade groups unlocked based on the trader's—not the player's—experience levels, how many times a trade can be made before the trader has to resupply, and much more.

Trade tables can be stored in any subfolder in a behavior pack, but the convention is to use a trading directory at the behavior pack's top level. For an in-depth dive into trade tables, read Creating a Trade Table.

What's next?​

We suggest taking a look at loot and trade table functions next, which are mostly shared between the two. Then, jump into one of the tutorials and create your own loot or trade table!

  • Loot and Trade Table Functions
  • Loot Table Conditions
  • Loot Table Overloads
  • Creating a Loot Table
  • Creating a Trade Table

(출처: ms-learn, creator/Documents/CreateLootTable.md)

Creating a Loot Table​

If you're making mobs, ruins, or sunken treasure ships, you're going to need to make loot tables! Now that you've read through the Introduction, you're ready to take the step of creating your own. This tutorial will guide you through making progressively more complex tables, getting you closer to creating the Minecraft world of your dreams.

You should be familiar with these concepts before starting this tutorial:

  • Introduction to Behavior Packs
  • Introduction to Loot and Trade Tables
  • Loot and Trade Table Functions

Basic loot tables​

To begin, let's create something fairly simple: A loot table that returns a single diamond when it's called.

{
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "item",
"name": "minecraft:diamond"
}
]
}
]
}

We defined a single pool that rolls once and contains a single diamond on every roll. If you combined this with the minecraft:loot component inside an entity's behavior file, the entity would drop that diamond on death. If the loot table above belonged to a new entity you'd created—say, an Evil Clown—then we'd put the table in behavior_pack/loot_tables/entities/evil_clown.json, and refer to it from the entity's definition file at behavior_pack/entities/evil_clown.json:

{
"format_version": "1.21.90",
"minecraft:entity": {
"description": {
"identifier": "my_mob:evil_clown",
"spawn_category": "monster",
"is_spawnable": true,
},
"components": {
"minecraft:loot": {
"table": "loot_tables/entities/evil_clown.json"
}
// other components
}
}
}

Now, let's get a little more complicated. What if you wanted the evil clown to drop one of tow different items? What if we wanted to return a diamond or a piece of coal? We can just add a second value to the entries object:

{
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "item",
"name": "minecraft:diamond"
},
{
"type": "item",
"name": "minecraft:coal"
}
]
}
]
}

Neat! But, right now a diamond is just as likely to drop as a piece of coal. We can change that by adding a weight to each entry. By default, the weight of an entry is 1; if you don't specify any weights, all entries have an equal chance of being selected. Since the clown is, after all, evil, let's make coal four times as likely as a diamond.

{
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "item",
"name": "minecraft:diamond",
"weight": 1
},
{
"type": "item",
"name": "minecraft:coal",
"weight": 4
}
]
}
]
}

Great! Now, let's give the evil clowns another variation: some only have one loot item, while others have two or three. We can change the rolls entry to have a range rather than a single value; when the loot is dropped, Minecraft will roll from min to max times:

{
"pools": [
{
"rolls": { "min": 1, "max": 3 },
"entries": [
{
"type": "item",
"name": "minecraft:diamond",
"weight": 1
},
{
"type": "item",
"name": "minecraft:coal",
"weight": 4
}
]
}
]
}

In this example, the game will roll the entries one to three times, resulting in a minimum of one item and a maximum of three every time this loot table is called.

More complex loot tables​

Functions and conditions​

For this example, we're going to switch to show you one of the actual Vanilla files, the loot table for the cave spider:

{
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "item",
"name": "minecraft:string",
"weight": 1,
"functions": [
{
"function": "set_count",
"count": {"min": 0, "max": 2}
},
{
"function": "looting_enchant",
"count": {"min": 0, "max": 1}
}
]
}
]
},
{
"rolls": 1,
"entries": [
{
"type": "item",
"name": "minecraft:spider_eye",
"weight": 1,
"functions": [
{
"function": "set_count",
"count": {"min": 0, "max": 1}
},
{
"function": "looting_enchant",
"count": {"min": 0, "max": 1}
}
]
}
],
"conditions": [
{
"condition": "killed_by_player"
}
]
}
]
}

This loot table only has two one-item pools, but the count of the items returned is driven by functions:

  • The string uses set_count to drop 0 to 2 strings when the spider is killed.
  • The spider_eye uses set_count to return either 0 or 1 spider eyes.
  • Both of them use looting_enchant to randomly add another string or another spider eye if the spider was killed by an item with the looting enchantment.

In addition, there's a condition of killed_by_player placed on the spider eye: the cave spider must be killed by the player for an eye to be dropped as loot.

While set_count and looting_enchant are the most common functions to use, there are others available for interesting effects. For instance, if you've ever killed a chicken with a flaming sword, you might find you get a cooked chicken out of it. How does that happen? With the furnace_smelt function. That pool from the chicken's loot table looks like this:

{
"rolls": 1,
"entries": [
{
"type": "item",
"name": "minecraft:chicken",
"weight": 1,
"functions": [
{
"function": "furnace_smelt",
"conditions": [
{
"condition": "entity_properties",
"entity": "this",
"properties": {
"on_fire": true
}
}
]
},
{
"function": "looting_enchant",
"count": {"min": 0, "max": 1}
}
]
}
]
}

This also shows a condition not on the item, but on the item's function. The furnace_smelt function turns the chicken into a cooked chicken, but it's only called if the entity the chicken was killed with has the on_fire property.

Referenced loot tables​

Sometimes, your entities or containers are "subclasses" of one another: a village armorer, a village tanner, and a village cartographer are all villagers. Those entities/containers might share a common pool of loot, while adding a few extra bits of loot that are specific to armor, tannery, or mapmaking. To handle this case, entries in a pool can be of type loot_table rather than type item, and have a reference to another loot table. When that item comes up in a roll on that pool, the game will make another roll on the referenced loot table and return its result.

The Vanilla loot table for a village tannery looks in part like this. (The [full table[(https://github.com/Mojang/bedrock-samples/blob/main/behavior_pack/loot_tables/chests/village/village_tannery.json) has more entries in the first pool, with functions and assigned weights.)

{
"pools": [
{
"rolls": {"min": 1, "max": 5},
"entries": [
{
"type": "item",
"name": "minecraft:leather_chestplate"
},
{
"type": "item",
"name": "minecraft:leather_boots"
},
{
"type": "item",
"name": "minecraft:leather_helmet"
}
]
},
{
"rolls": 1,
"entries": [
{
"type": "loot_table",
"name": "loot_tables/chests/village/village_bundle.json"
}
]
}
]
}

When the second pool is called, it returns a value from the village_bundle.json loot table, which is referred to by several other village chests. The village bundle loot table has a two in three chance of returning nothing (an item of type empty with a weight of 2, and a one in three chance of returning a bundle.

[!IMPORTANT]

Don't make recursive loot tables! A loot table cannot refer to itself in any way. If a roll results in a recursive loot table, nothing will be returned.

Loot overloads​

We haven't explicitly talked about Loot Overloads, as they're not part of creating loot tables in behavior packs. You should familiarize yourself with those commands, however, as they let you, among other tasks, give entities items from loot tables, or fill containers from them.

Next steps​

By now, you should be familiar with loot tables, conditions, functions, and overloads. Your next steps from here are creating your own tables for your own creations!

출처
id출처라이선스커밋접근일
ms-learnMinecraft Creator 문서 (Microsoft Learn)CC BY 4.0 (문서), MIT (코드)a9fd1c02026-11-13