HomeCommandsExamplesGetting Started With ScriptsGlobal Keywords
BracketDumpersBracketHandlersBracketValidatorsResourceLocationBracketHandler

LootTable

Importing the class

If you need to reference this type directly, like when casting an Array, or as a parameter, you will need to import it. Simply add the import at the top of the file.

script.zs
import crafttweaker.api.loot.LootTable;

Description

A loot table is used to determine what is dropped when the game needs to drop loot.

Members

fill(container as Container, params as LootParams, seed as long = 0)
Fills the given container with loot rolled by this table.
script.zs
// LootTable.fill(container as Container, params as LootParams, seed as long = 0);
myLootTable.fill(container, myLootParams, myLong);

Parameters:

container Type: Container - The container to fill.
params Type: LootParams - The params that will be used to generate the loot.
seed (optional) Type: long - An Optional seed used to generate the loot, defaults to 0 if not supplied.

Default Value: 0

getRandomItems(context as LootContext, stackConsumer as function(t as IItemStack) as void)
Rolls this table and passes all the rolled items to the given Consumer<{@link 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 com.blamejared.crafttweaker.natives.loot.ExpandLootContextBuilder#copy(LootContext).

script.zs
// LootTable.getRandomItems(context as LootContext, stackConsumer as function(t as IItemStack) as void);
myLootTable.getRandomItems(new LootContextBuilder(level).withParameter<Vec3>(LootContextParams.origin(), player.position).withParameter<Entity>(LootContextParams.thisEntity(), player).create(LootContextParamSets.gift()), (stack) => {
println(stack.commandString);
});

Parameters:

context Type: LootContext - The context that will generate the loot.
stackConsumer Type: function(t as IItemStack) as void - A consumer to act on the rolled stacks.
getRandomItems(context as LootContext) as List<IItemStack>
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 com.blamejared.crafttweaker.natives.loot.ExpandLootContextBuilder#copy(LootContext).

Returns: A list containing all the rolled items.

script.zs
// LootTable.getRandomItems(context as LootContext) as List<IItemStack>;
myLootTable.getRandomItems(new LootContextBuilder(level).withParameter<Vec3>(LootContextParams.origin(), player.position).withParameter<Entity>(LootContextParams.thisEntity(), player).create(LootContextParamSets.gift()));

Parameters:

context Type: LootContext - The context that this loot was generated with.

Return Type: List<IItemStack>

getRandomItems(params as LootParams) as List<IItemStack>
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 com.blamejared.crafttweaker.natives.loot.ExpandLootContextBuilder#copy(LootContext).

Returns: A list containing all the rolled items.

script.zs
// LootTable.getRandomItems(params as LootParams) as List<IItemStack>;
myLootTable.getRandomItems(myLootParams);

Parameters:

params Type: LootParams - The params that this loot was generated with.

Return Type: List<IItemStack>

getRandomItemsRaw(context as LootContext, stackConsumer as function(t as IItemStack) as void)
Rolls this table and passes all the rolled items to the given Consumer<{@link 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 com.blamejared.crafttweaker.natives.loot.ExpandLootContextBuilder#copy(LootContext).

script.zs
// LootTable.getRandomItemsRaw(context as LootContext, stackConsumer as function(t as IItemStack) as void);
myLootTable.getRandomItemsRaw(new LootContextBuilder(level).withParameter<Vec3>(LootContextParams.origin(), player.position).withParameter<Entity>(LootContextParams.thisEntity(), player).create(LootContextParamSets.gift()), (stack) => {
println(stack.commandString);
});

Parameters:

context Type: LootContext - The context that will generate the loot.
stackConsumer Type: function(t as IItemStack) as void - A consumer to act on the rolled stacks.
Getter
Gets the ID of this loot table.
script.zs
// LootTable.id as ResourceLocation
myLootTable.id

Return Type: ResourceLocation

id() as ResourceLocation
Gets the ID of this loot table.

Returns: The ID of this loot table.

script.zs
// LootTable.id() as ResourceLocation;
myLootTable.id();

Return Type: ResourceLocation

Getter
Gets the param set that this table uses.
script.zs
// LootTable.paramSet as LootContextParamSet
myLootTable.paramSet

Return Type: LootContextParamSet

paramSet() as LootContextParamSet
Gets the param set that this table uses.

Returns: The param set that this table uses.

script.zs
// LootTable.paramSet() as LootContextParamSet;
myLootTable.paramSet();

Return Type: LootContextParamSet