{{Infobox command
|name=loot
|oplevel=
* 2 {{only|java|short=1}}
* 1 {{only|bedrock|short=1}}
|others=[[Options|Cheats]] only{{only|bedrock|short=1}}
}}
Drops the given [[loot table]] into the specified inventory or into the world.
==Syntax==
* '''Java Edition'''
: loot <''TARGET''> <''SOURCE''>
::In which:
::<''TARGET''>
is:
::: give
:::: Distributes items to players, ignoring empty item stacks.
::: insert
:::: Distributes items to a container block, ignoring empty item stacks.
::: spawn
:::: Spawns item entities. Empty item stacks are also spawned, but disappears instantly.
::: replace block
::: replace entity
:::: Replaces item stacks into some consecutive [[slot]]s in order. An empty item stack generated by the <''SOURCE''> clears a slot.
::: replace block
::: replace entity
:::: Clears some consecutive [[slot]]s, and then places item stacks into them in order. Empty item stacks are also placed. If the number of item stacks generated by the <''SOURCE''> exceeds the specified slot number, excess item stacks are ignored.
::<''SOURCE''>
is:
::: fish [|mainhand|offhand]
:::: Simulates [[fishing]] with a specified tool at a specified position.
::: loot
:::: Invokes a [[loot table]] directly.
::: kill
:::: Simulates killing a specified entity.
::: mine [|mainhand|offhand]
:::: Simulates mining a block at a specified position with a specified tool.
::[[Loot context]] provided by each <''SOURCE''>
is:
:::{|class="wikitable collapsible collapsed
! <''SOURCE''> !! Supplied loot context parameters
|-
| fish
|
* '''{{cd|this}} entity:''' (If the executor is an entity) The command executor entity.
* '''Origin:''' The center of the block at the specified position.
* '''Tool:''' The specified item.
|-
| kill
|
* '''{{cd|this}} entity:''' The specified entity.
* '''Origin:''' The command execution position.
* '''Damage source:''' The magic
[[damage type]]
* '''{{cd|attacker}} entity:''' (If the executor is an entity) The command executor entity.
* '''{{cd|direct_attacker}} entity:''' (If the executor is an entity) The command executor entity.
* '''{{cd|attacking_player}} entity:''' (If the executor is a player) The command executor player.
|-
| loot
|
* '''{{cd|this}} entity:''' (If the executor is an entity) The command executor entity.
* '''Origin:''' The command execution position.
|-
| mine
|
* '''{{cd|this}} entity:''' (If the executor is an entity) The command executor entity.
* '''Origin:''' The center of the block at the specified position.
* '''Tool:''' The specified item.
* '''Block state:''' The specified block.
* '''Block entity:''' (If the block is a block entity.) Block entity data of the block.
|}
* '''Bedrock Edition'''
: loot <''TARGET''> <''SOURCE''>
::In which:
::<''TARGET''>
is:
::: give
:::: Gives items to players, ignoring empty item stacks.
::: insert
:::: Distributes items to a container block, ignoring empty item stacks.
::: spawn
:::: Spawns item entities, ignoring empty item stacks.
::: replace block slot.container
:::replace entity
:::: Replaces item stacks into some consecutive [[slot]]s in order. An empty item stack generated by the <''SOURCE''> clears a slot.
::: replace block slot.container [count: int]
:::replace entity [count: int]
:::: Clears some consecutive [[slot]]s, and then places item stacks into them in order. Empty item stacks are also placed. If the number of item stacks generated by the <''SOURCE''> exceeds the specified slot number, excess item stacks are ignored. An entity or a container must have all the specified consecutive slots in order to clear and place items in it.
::<''SOURCE''>
is:
:::kill ["|mainhand|offhand": string]
:::: Simulates killing a specified entity with a specified tool.
:::loot ["|mainhand|offhand": string]
:::: Invokes a [[loot table]] with a specified tool.
==Arguments==
{{el|je|short=1}}: {{argument|loot_table|loot_table}}
{{el|be|short=1}}: {{argument|loot_table: string|basic_string|be=1}}
:Specifies which loot table to use.
:{{IN|java}}, {{lcfirst:{{arg desc|je=loot_table}}}}
:{{IN|bedrock}}, {{lcfirst:{{arg desc|be=string}}}} And it refers to a loot table with the path of "loot_tables/loot_table: string
.json".
{{el|je|short=1}}: {{argument|tool|item_stack}}
:Specifies a tool to simulatively mine or fish.
:{{arg desc|je=item_stack}}
{{el|be|short=1}}: {{argument|be=1|"{{!}}mainhand{{!}}offhand": string|basic_string}}
:Specifies a tool to be used to simulatively kill or loot.
:{{arg desc|be=string}} Can be mainhand
and offhand
, otherwise it represents an item id.
{{argument|target|entity|entity: target|CommandSelector}} (in kill
source)
: Specifies one entity to kill simulatively.
:{{arg desc|je=entity|amount=single|type=entities|actor}}
{{argument|players|entity|player: target|CommandSelector}}
:Specifies one or more players to give.
:{{arg desc|je=entity|amount=multiple|type=players|be=CommandSelector}}
{{el|je|short=1}}: {{argument|pos|block_pos}} and {{argument|targetPos|block_pos}} (in replace block
and insert
mode)
{{el|be|short=1}}: {{argument|be=1|position: x y z|CommandPositionFloat}} (in replace block
and insert
mode)
:Specifies the position of a block.
:{{IN|java}}: {{lcfirst:{{arg desc|je=block_pos}}}}
:{{IN|bedrock}}: {{lcfirst:{{arg desc|be=CommandPositionFloat}}}}
{{argument|targetPos|block_pos|position: x y z|CommandPositionFloat}} (in spawn
mode)
:Specifies the location where item entities drop.
:{{arg desc|je=vec3|be=CommandPositionFloat}}
{{argument|entities|entity|entity: target|CommandSelector}}
:Specifies one or more entities to modify.
:{{arg desc|je=entity|amount=multiple|type=entities|be=actor}}
{{argument|count|integer|count: int|int}}
:Specifies the number of consecutive slots to be cleared.
:{{arg desc|je=integer|min=0|be=int}}
{{el|je|short=1}}: {{argument|slot|item_slot}}
{{el|be|short=1}}: {{argument|be=1|slotType: EntityEquipmentSlot|enum}}, slot.container
, and {{argument|be=1|slotId: int|int}}
:Specifies the inventory slot to be modified.
:{{arg desc|je=item_slot|be=enum}}
==Result==
{{Result table}}
{{Result table|The command is incomplete, or any argument is not specified correctly.|unparseable|unparseable}}
{{Result table|cmd=/... fish ...
/... mine ...|
or position: x y z
is unloaded or out of the world.|fail|fail}}
{{Result table|cmd=/... mainhand
/... offhand|The executor is not a living entity.||N/A}}
{{Result table|The executor is not an entity.||fail}}
{{Result table|cmd=/... kill ...|
or entity: target
fails to resolve to a single entity (named player must be online).}}
{{Result table|The target is not a living entity.||N/A}}
{{Result table|The target has no loot table.|N/A|fail}}
{{Result table|cmd=/... loot ...|The loot_table: string
is not a valid loot table.}}
{{Result table|cmd=/loot replace entity ...|
or entity: target
fails to resolve to one or more entities (named player must be online).|fail}}
{{Result table|cmd=/loot replace entity <''SOURCE''>
/loot replace entity ... <''SOURCE''>|One or more item stacks are got, and all the targeted entities do not have the specified slot.|success}}
{{Result table|cmd=-{}-/loot replace entity <''SOURCE''>
/loot replace entity ... <''SOURCE''>|One or more item stacks are got, and all the targeted entities do not have all the specified consecutive slots.}}
{{Result table|cmd=/loot give ...|
or player: target
fails to resolve to one or more online players.|fail}}
{{Result table|cmd=/loot insert ...
/loot replace block ...|
or position: x y z
is unloaded or out of the world.}}
{{Result table|The block at
or position: x y z
is not a container.}}
{{Result table|cmd=/loot replace block ...|The block does not have the specified slot.}}
{{Result table|cmd=/loot replace block <''SOURCE''>
/loot replace block ... <''SOURCE''>|The number of item stacks got from the source plus the
id is bigger than the number of all slots in the specified container.|exception|success}}
{{Result table|cmd=/loot replace block <''SOURCE''>
/loot replace block ... <''SOURCE''>|The
plus the
id is bigger than the number of all slots in the specified container.||fail}}
{{Result table|cmd=|success}}
{{Result table}}
==Output==
{{Output table}}
{{Output table|edition=je|On fail|0|0|0}}
{{Output table|cmd=/loot spawn ...|On success|1|1|the number of item stacks got from loot}}
{{Output table|cmd=/loot give ...|On success|1|1|the total number of item stacks successfully allocated to each player}}
{{Output table|cmd=/loot insert ...|On success|1|1|the number of item stacks successfully distributed to the container}}
{{Output table|cmd=/loot replace block ...|On success|1|1|the number of item stacks successfully distributed to the container}}
{{Output table|On error|0|unchanged|unchanged}}
{{Output table|cmd=/loot replace entity ...|On success|1|1|the total number of item stacks successfully allocated to each entity}}
{{Output table|On error|0|unchanged|unchanged}}
{{Output table|edition=be|cmd=|On fail|0}}
{{Output table|cmd=loot give ...|On success|{{needs testing}}}}
{{Output table|cmd=loot spawn ...
loot insert ...|On success|1}}
{{Output table|cmd=-{}-/loot replace entity ... <''SOURCE''>|On success|When zero item stack is got, outputs 1.
Otherwise, outputs the number of targeted entities that have the specified slot}}
{{Output table|cmd=-{}-/loot replace entity ... <''SOURCE''>|On success|When zero item stack is got, outputs 1.
Otherwise, outputs the number of targeted entities that have all the specified consecutive slots}}
{{Output table}}
==History==
{{HistoryTable
|{{HistoryLine|java}}
|{{HistoryLine||1.14|dev=18w43a|Added {{cmd|drop|link=none}}.}}
|{{HistoryLine|||dev=18w45a|Renamed {{cmd|drop|link=none}} to {{cmd|loot|link=none}}.
|{{cmd|loot|link=none}} got reworked.}}
|{{HistoryLine||1.20.5|dev=24w12a|{{cmd|loot|link=none}} now also accepts an inline SNBT-formatted loot table definition for the {{argument|loot_table|loot_table}} argument.}}
|{{HistoryLine|bedrock}}
|{{HistoryLine||1.18|dev=beta 1.18.0.21|Added {{cmd|loot spawn ... loot ...|link=none}}.}}
|{{HistoryLine||1.18|dev=beta 1.18.0.22|Removed {{cmd|loot|link=none}}.}}
|{{HistoryLine||1.18.10|dev=beta 1.18.10.21|Re-added {{cmd|loot|link=none}}.}}
|{{HistoryLine||1.18.10|dev=beta 1.18.10.24|Added {{cmd|loot spawn ... kill ...|link=none}}}}
|{{HistoryLine||1.18.30|dev=beta 1.18.20.21|Added {{cmd|loot give ...|link=none}}}}
|{{HistoryLine|||dev=beta 1.18.30.20|Added {{cmd|loot insert ...|link=none}}}}
|{{HistoryLine||1.19.0|dev=beta 1.19.0.30|Added {{cmd|loot replace entity ...|link=none}}}}
|{{HistoryLine||1.19.40|dev=Preview 1.19.40.20|Added {{cmd|loot replace block ...|link=none}}}}
}}
== See also==
*{{cmd|give}} — give specific items to players without specifying a loot table
*{{cmd|item}}{{only|je}} — modify specific item slots of entities or container
*{{cmd|replaceitem}}{{only|be}} — modify specific item slots of entities or container
== Navigation ==
{{Navbox commands}}
[[de:Befehl/loot]]
[[ja:コマンド/loot]]
[[pt:Comandos/loot]]
[[ru:Команды консоли/loot]]
[[uk:Команди консолі/loot]]
[[zh:命令/loot]]