Home Commands Examples Getting Started With Scripts Global Keywords
BracketDumpers BracketHandlers BracketValidators ResourceLocationBracketHandler

LootContextBuilder

Creates a new LootContext using a builder style pattern.

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.

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

Static Methods

Return Type: LootContextBuilder

script.zs
LootContextBuilder.copy(context as LootContext) as LootContextBuilder
ParameterType
Parameter
context
Type
LootContext

Creates a new builder with the given level.

Returns: A new builder.
Return Type: LootContextBuilder

script.zs
LootContextBuilder.create(level as ServerLevel) as LootContextBuilder
ParameterTypeDescription
Parameter
level
Type
ServerLevel
Description
The level the loot will be rolled in.

Methods

Creates a new LootContext with the given LootContextParamSet.

The given LootContextParamSet is used to determine what values are required for the context to be used.

Returns: a new LootContext
Return Type: LootContext

script.zs
// LootContextBuilder.build(contextParamSet as LootContextParamSet) as LootContext
new LootContextBuilder(level).build(LootContextParamSets.gift());
ParameterTypeDescription
Parameter
contextParamSet
Type
LootContextParamSet
Description
The LootContextParamSet to use.
Deprecated
Use this#build(LootContext.Builder, LootContextParamSet) instead to work around a bug in the ZenCode compiler.

Creates a new LootContext with the given LootContextParamSet.

The given LootContextParamSet is used to determine what values are required for the context to be used.

Returns: a new LootContext
Return Type: LootContext

script.zs
// LootContextBuilder.create(contextParamSet as LootContextParamSet) as LootContext
new LootContextBuilder(level).create(LootContextParamSets.gift());
ParameterTypeDescription
Parameter
contextParamSet
Type
LootContextParamSet
Description
The LootContextParamSet to use.

Gets the level that this builder uses.

Returns: The level that this builder uses.
Return Type: ServerLevel

script.zs
// LootContextBuilder.getLevel() as ServerLevel
new LootContextBuilder(level).getLevel();

Gets the provided value of the optional parameter.

Returns: The value if found, null otherwise.
Return Type: @org.openzen.zencode.java.ZenCodeType.Nullable T

script.zs
LootContextBuilder.getOptionalParameter<T : Object>(contextParam as LootContextParam<T>) as @org.openzen.zencode.java.ZenCodeType.Nullable T
ParameterTypeDescription
Parameter
contextParam
Type
LootContextParam<T>
Description
The LootContextParam<T> to get the value of.
Parameter
T
Type
Object
Description
The type that the LootContextParam<T> uses

Gets the provided value of the parameter.

Returns: The found value.
Return Type: T

script.zs
LootContextBuilder.getParameter<T : Object>(contextParam as LootContextParam<T>) as T
ParameterTypeDescription
Parameter
contextParam
Type
LootContextParam<T>
Description
The LootContextParam<T> to get the value of.
Parameter
T
Type
Object
Description
The type that the LootContextParam<T> uses

Provides the given luck value to the context.

Returns: This builder for chaining purposes.
Return Type: LootContextBuilder

script.zs
// LootContextBuilder.withLuck(luck as float) as LootContextBuilder
new LootContextBuilder(level).withLuck(0.5);
ParameterTypeDescription
Parameter
luck
Type
float
Description
The luck value to use.

Provides an optional parameter to this builder.

Returns: This builder for chaining purposes.
Return Type: LootContextBuilder

script.zs
LootContextBuilder.withOptionalParameter<T : Object>(contextParam as LootContextParam<T>, actor as @org.openzen.zencode.java.ZenCodeType.Nullable T) as LootContextBuilder
ParameterTypeDescription
Parameter
contextParam
Type
LootContextParam<T>
Description
The param to add.
Parameter
actor
Type
@org.openzen.zencode.java.ZenCodeType.Nullable T
Description
The optional actor used by the param.
Parameter
T
Type
Object
Description
The type of actor that the param uses.

Supplies a seed to be passed into a new Random.

Returns: This builder for chaining purposes.
Return Type: LootContextBuilder

script.zs
// LootContextBuilder.withOptionalRandomSeed(seed as long) as LootContextBuilder
new LootContextBuilder(level).withOptionalRandomSeed(0);
ParameterTypeDescription
Parameter
seed
Type
long
Description
The seed to use.

Supplies either a seed to be passed into a new Random or if the seed is 0 use the given Random

Returns: This builder for chaining purposes.
Return Type: LootContextBuilder

script.zs
// LootContextBuilder.withOptionalRandomSeed(seed as long, random as RandomSource) as LootContextBuilder
new LootContextBuilder(level).withOptionalRandomSeed(1, level.random);
ParameterTypeDescription
Parameter
seed
Type
long
Description
The seed to use.
Parameter
random
Type
RandomSource
Description
The random source to provide.

Provides a parameter to this builder.

Returns: This builder for chaining purposes.
Return Type: LootContextBuilder

script.zs
LootContextBuilder.withParameter<T : Object>(contextParam as LootContextParam<T>, actor as T) as LootContextBuilder
ParameterTypeDescription
Parameter
contextParam
Type
LootContextParam<T>
Description
The param to add.
Parameter
actor
Type
T
Description
The actor used by the param.
Parameter
T
Type
Object
Description
The type of actor that the param uses.

Supplies a Random source to the built context.

Returns: This builder for chaining purposes.
Return Type: LootContextBuilder

script.zs
// LootContextBuilder.withRandom(random as RandomSource) as LootContextBuilder
new LootContextBuilder(level).withRandom(level.random);
ParameterTypeDescription
Parameter
random
Type
RandomSource
Description
The random source to provide.

Properties

NameTypeHas GetterHas SetterDescription
Name
level
Type
ServerLevel
Has Getter
true
Has Setter
false
Description
Gets the level that this builder uses.