Builder to create an arbitrary loot condition through a JSON-based structure.

This builder allows to create arbitrary JSON structures, which can reference other mod-added loot conditions that do not provide native CraftTweaker support. The given JSON structure needs to be a valid JSON-object representation, meaning it needs to be an instance of MapData. The JSON may or may not specify the type. If the type is specified then it must match the one given in the builder; otherwise the type is automatically added.

The JSON structure along with the condition type is mandatory.

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
Copy
import crafttweaker.api.loot.conditions.crafttweaker.Json;

已实现的接口

Link to 已实现的接口

Json implements the following interfaces. That means all methods defined in these interfaces are also available in Json

Name: create

Creates an ILootCondition of the given type parsing the given json.

The JSON must respect the constraints specified in the class documentation. It is suggested to use this method
sparingly, preferring to instead create JSON conditions as needed from within a LootConditionBuilder.

If no valid condition is found, or the JSON is invalid, an error gets thrown.

This method is equivalent to makeJson in LootConditionBuilder.

Returns: An ILootCondition instance built according to the given data, if possible.
Return Type: ILootCondition

ZenScript
Copy
Json.create(type as MCResourceLocation, json as IData) as ILootCondition
参数类型描述
参数
类型
类型
MCResourceLocation
描述
A MCResourceLocation identifying the type of the loot condition to create.
参数
json
类型
IData #数据
描述
The JSON data, according to the given constraints.

Name: create

Creates an ILootCondition of the given type parsing the given json.

The name is treated as a MCResourceLocation, lacking the type safety of the bracket handler. For this
reason, it's suggested to prefer the method with a MCResourceLocation as parameter.

The JSON must respect the constraints specified in the class documentation. It is suggested to use this method
sparingly, preferring to instead create JSON conditions as needed from within a LootConditionBuilder.

If no valid condition is found, or the JSON is invalid, an error gets thrown.

This method is equivalent to makeJson in LootConditionBuilder.

Returns: An ILootCondition instance built according to the given data, if possible.
Return Type: ILootCondition

ZenScript
Copy
Json.create(type as string, json as IData) as ILootCondition
参数类型描述
参数
类型
类型
string
描述
A string in resource location format identifying the type of the loot condition to create.
参数
json
类型
IData #数据
描述
The JSON data, according to the given constraints.

Name: withJson

Sets the type of the condition that will be built along with the JSON representation that will be parsed.

The JSON must respect the constraints specified in the class documentation.

Returns: This builder for chaining.
Return Type: Json

ZenScript
Copy
Json.withJson(type as MCResourceLocation, json as IData) as Json
参数类型描述
参数
类型
类型
MCResourceLocation
描述
A MCResourceLocation identifying the type of the loot condition.
参数
json
类型
IData #数据
描述
The JSON data, according to the given constraints.

Name: withJson

Sets the type of the condition that will be built along with the JSON representation that will be parsed.

The name is treated as a MCResourceLocation, lacking the type safety of the bracket handler. For this reason, it's suggested to prefer the method with a MCResourceLocation as parameter.

The JSON must respect the constraints specified in the class documentation.

Returns: This builder for chaining.
Return Type: Json

ZenScript
Copy
Json.withJson(type as string, json as IData) as Json
参数类型描述
参数
类型
类型
string
描述
A string in resource location format identifying the type of the loot condition.
参数
json
类型
IData #数据
描述
The JSON data, according to the given constraints.