Json

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.

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.

import crafttweaker.api.loot.conditions.crafttweaker.Json;

Implemented Interfaces

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

Methods

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

Json.create(type as MCResourceLocation, json as IData) as ILootCondition
ParameterTypeDescription
typeUbicación MCResourceA MCResourceLocation identifying the type of the loot condition to create.
jsonIDataThe JSON data, according to the given constraints.
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

Json.create(type as string, json as IData) as ILootCondition
ParameterTypeDescription
typestringA string in resource location format identifying the type of the loot condition to create.
jsonIDataThe JSON data, according to the given constraints.

Methods

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.

Return Type: Json

Json.withJson(type as MCResourceLocation, json as IData) as Json
ParameterTypeDescription
typeUbicación MCResourceA MCResourceLocation identifying the type of the loot condition.
jsonIDataThe JSON data, according to the given constraints.
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.

Return Type: Json

Json.withJson(type as string, json as IData) as Json
ParameterTypeDescription
typestringA string in resource location format identifying the type of the loot condition.
jsonIDataThe JSON data, according to the given constraints.