LootTable
Link to loottable
A loot table is used to determine what is dropped when the game needs to drop loot.
Importing the class
Link to importing-the-class
It might be required for you to import the package if you encounter any issues (like casting an Array), so better be safe than sorry and add the import at the very top of the file.
ZenScript Copyimport crafttweaker.api.loot.LootTable;
Methods
Link to methods
Name: fill
Fills the given container with loot rolled by this table.
ZenScript CopyLootTable.fill(container as Container, params as LootParams, seed as long)
Parameter | Type | Description | Optional | Default Value |
---|---|---|---|---|
Parameter container | Type Container | Description The container to fill. | Optional false | Default Value |
Parameter params | Type LootParams | Description The params that will be used to generate the loot. | Optional false | Default Value |
Parameter seed | Type long | Description An Optional seed used to generate the loot, defaults to 0 if not supplied. | Optional true | Default Value 0 |
Name: getId
Gets the ID of this loot table.
Returns: The ID of this loot table.
Return Type: ResourceLocation
ZenScript Copy// LootTable.getId() as ResourceLocation
lootTables.getTable(<resource:minecraft:gameplay/cat_morning_gift>).getId();
Name: getParamSet
Gets the param set that this table uses.
Returns: The param set that this table uses.
Return Type: LootContextParamSet
ZenScript Copy// LootTable.getParamSet() as LootContextParamSet
lootTables.getTable(<resource:minecraft:gameplay/cat_morning_gift>).getParamSet();
Name: getRandomItems
Rolls this table and returns the rolled items in a list.
NOTE: The provided LootContext should not be reused from a loot modifier, if you want to reuse a context, look at invalid#copy(LootContext).
Returns: A list containing all the rolled items.
Return Type: stdlib.List<IItemStack>
ZenScript Copy// LootTable.getRandomItems(context as LootContext) as stdlib.List<IItemStack>
lootTables.getTable(<resource:minecraft:gameplay/cat_morning_gift>).getRandomItems(LootContextBuilder.create(LootParamsBuilder.create(level).withParameter<Vec3>(LootContextParams.origin(), player.position).withParameter<Entity>(LootContextParams.thisEntity(), player).build(LootContextParamSets.gift())).create());
Parameter | Type | Description |
---|---|---|
Parameter context | Type LootContext | Description The context that this loot was generated with. |
Name: getRandomItems
Rolls this table and returns the rolled items in a list.
NOTE: The provided LootContext should not be reused from a loot modifier, if you want to reuse a context, look at invalid#copy(LootContext).
Returns: A list containing all the rolled items.
Return Type: stdlib.List<IItemStack>
ZenScript CopyLootTable.getRandomItems(params as LootParams) as stdlib.List<IItemStack>
Parameter | Type | Description |
---|---|---|
Parameter params | Type LootParams | Description The params that this loot was generated with. |
Name: getRandomItems
Rolls this table and passes all the rolled items to the given Consumer<[IItemStack](/vanilla/api/item/IItemStack)>
NOTE: This method does respect max stack sizes NOTE: The provided LootContext should not be reused from a loot modifier, if you want to reuse a context, look at invalid#copy(LootContext).
ZenScript Copy// LootTable.getRandomItems(context as LootContext, stackConsumer as Consumer<IItemStack>)
lootTables.getTable(<resource:minecraft:gameplay/cat_morning_gift>).getRandomItems(LootContextBuilder.create(LootParamsBuilder.create(level).withParameter<Vec3>(LootContextParams.origin(), player.position).withParameter<Entity>(LootContextParams.thisEntity(), player).build(LootContextParamSets.gift())).create(), (stack) => {
println(stack.commandString);
});
Parameter | Type | Description |
---|---|---|
Parameter context | Type LootContext | Description The context that will generate the loot. |
Parameter stackConsumer | Type Consumer<IItemStack> | Description A consumer to act on the rolled stacks. |
Name: getRandomItemsRaw
Rolls this table and passes all the rolled items to the given Consumer<[IItemStack](/vanilla/api/item/IItemStack)>
NOTE: This method does not respect max stack sizes! NOTE: The provided LootContext should not be reused from a loot modifier, if you want to reuse a context, look at invalid#copy(LootContext).
ZenScript Copy// LootTable.getRandomItemsRaw(context as LootContext, stackConsumer as Consumer<IItemStack>)
lootTables.getTable(<resource:minecraft:gameplay/cat_morning_gift>).getRandomItemsRaw(LootContextBuilder.create(LootParamsBuilder.create(level).withParameter<Vec3>(LootContextParams.origin(), player.position).withParameter<Entity>(LootContextParams.thisEntity(), player).build(LootContextParamSets.gift())).create(), (stack) => {
println(stack.commandString);
});
Parameter | Type | Description |
---|---|---|
Parameter context | Type LootContext | Description The context that will generate the loot. |
Parameter stackConsumer | Type Consumer<IItemStack> | Description A consumer to act on the rolled stacks. |
Properties
Link to properties
Name | Type | Has Getter | Has Setter | Description |
---|---|---|---|---|
Name id | Type ResourceLocation | Has Getter true | Has Setter false | Description Gets the ID of this loot table. |
Name paramSet | Type LootContextParamSet | Has Getter true | Has Setter false | Description Gets the param set that this table uses. |