Result Extensions - WolfyScript/CustomCrafting-Wiki GitHub Wiki

Extensions can be executed on crafting, smelting, and more recipe types.

They need to be configured inside the config file of the recipe due to their complexity.

They are added to the extension array in the result options.

"result": {
    "items": [],
    "tags": [],
    "extensions": [
        { }, 
        { },
        ...
    ]
}

Each Extension has its unique NamespacedKey that identifies which one to use. You can have as many extensions with the same key as you need so that you can use the same extension with different settings. Common options that every extension has, are outer_radius and inner_radius. They are used to configure the affected area, like in which players are detected or where to spawn mobs for example. The implementation depends mainly on the extensions.

{
  "key": "namespace:key",
  "outer_radius": [0.0, 0.0, 0.0],
  "inner_radius": [0.0, 0.0, 0.0],
  ...
}

Included Extensions

There are three default extensions available: Commands, MythicMobs Mob, and Sound.

Command Extension

Allows executing commands when a craft is completed. You can run commands inside the console or let the player run the command.
If you have PlaceholderAPI installed you can use placeholders inside the commands too, else you only have the %player% placeholder.

{
    "key" : "customcrafting:command",
    "outer_radius" : [ 0.0, 0.0, 0.0 ],
    "inner_radius" : [ 0.0, 0.0, 0.0 ],
    "consoleCommands" : [ "say hi %player%", "effect give %player% minecraft:strength 100 100" ],
    "playerCommands" : [ ],
    "nearPlayer" : true,
    "nearWorkstation" : true
}

outer and inner radius: Configure the area where to look for players to run the command on. consoleCommands: Commands that are executed in the console. playerCommands: Commands that are executed by the player. nearPlayer: Runs the commands for all players in the configured area around the player that caused the execution. nearWorkstation: Runs the commands for all players in the configured area around the workstation (furnace, etc.) that caused the execution.

Sound Extension

Play sound on completion of the craft.

{
    "key" : "customcrafting:sound",
    "outer_radius" : [ 0.0, 0.0, 0.0 ],
    "inner_radius" : [ 0.0, 0.0, 0.0 ],
    "sound" : "BLOCK_ANVIL_USE",
    "volume" : 1.0,
    "pitch" : 1.0,
    "soundCategory" : "BLOCKS",
    "forPlayer" : false,
    "nearPlayer" : false,
    "nearWorkstation" : false,
    "onBlock" : true
}

outer/inner_radius: Configure the area where to look for players to play the sound for. sound: The Sound to play. volume: The volume of the sound. pitch: The pitch of the sound. soundCategory: In which category the sound belongs. forPlayer: Plays the sound for the player that caused the execution. nearPlayer: Plays the sound for all players in the area around the player that caused the execution. nearWorkstation: Plays the sound for all players in the area around the workstation (furnace, etc.) that caused the execution. onBlock: Plays the sound on the actual block.

MythicMobs (Mob) Extension

Spawn Mobs from MythicMobs on completetion of the craft.

{
    "key" : "customcrafting:mythicmobs/mob_spawn",
    "outer_radius" : [ 0.0, 0.0, 0.0 ],
    "inner_radius" : [ 0.0, 0.0, 0.0 ],
    "mobName" : "MobName",
    "mobLevel" : 10,
    "offset" : [ 0.5, 1.0, 0.5 ]
}

outer/inner_radius: Configure the range in which the mob can spawn (Position is randomly chosen).
mobName: The name of the mob in MythicMobs.
mobLevel: The level of the Mob.
offset: The offset added to the postition.

Advancement

(Available since v2.16.0.0-beta4)

Allows you to grant/revoke an advancement or advancement criteria for the included players.

{
    "key" : "customcrafting:advancement",
    "outer_radius" : [ 0.0, 0.0, 0.0 ],
    "inner_radius" : [ 0.0, 0.0, 0.0 ],
    "advancement" : "minecraft:husbandry/tactical_fishing",
    "revoke" : false,
    "criteria" : null,
    "nearPlayer" : false,
    "nearWorkstation" : false
}

outer/inner_radius: Configure the range in which to look for players to include.
advancement: The namespaced key of the advancement.
revoke: If it should revoke the advancement/criteria instead of granting it.
criteria: The criteria to grant/revoke. If it is null, it will grant/revoke all criteria of the advancement.
nearPlayer: Includes all players in the configured area around the player that caused the execution.
nearWorkstation: Includes all players in the configured area around the workstation (furnace, etc.), that caused the execution.

Custom Extensions

If you would like to create your own extension you can code one yourself and register it into CustomCrafting.

First you need to extend the ResultExtension abstract class:

import me.wolfyscript.customcrafting.utils.recipe_item.extension.ResultExtension;

An example Extension looks like that. It is serialized/deserialized using Jackson, so you need to use annotations like @JsonIgnore if you don't want specific variables to be serialized. It requires a default constructor. A copy constructor with a clone() method is recommended too.

public class ExampleResultExtension extends ResultExtension {

    private int testValue;

    public ExampleResultExtension () {
        super(new NamespacedKey("your_namespace", "example")); 
        //NamespacedKey must be unique! It is recommended to use your plugin name as the namespace (lowercase, underscores instead of spaces!).
    }

    public ExampleResultExtension (ExampleResultExtension extension) {
        super(extension);
        this.testValue = extension.testValue;
    }

    @Override
    public void onWorkstation(Block block, @Nullable Player player) {
        //Only called when a workstation block exists
    }

    @Override
    public void onLocation(Location location, @Nullable Player player) {
        //Called when a craft is completed by either a player or Workstation
    }

    @Override
    public void onPlayer(@NotNull Player player, Location location) {
        //Only called when a Player exists that caused the craft
    }

    @Override
    public ExampleResultExtension clone() {
        return new ExampleResultExtension(this);
    }

}

To register is you need to use the Registry of CustomCrafting.

import me.wolfyscript.customcrafting.Registry;

Then just register a new instance of your Extension in your plugins onLoad()!

@Override
public void onLoad() {
    getLogger().info("Registering Result Extension");
    Registry.RESULT_EXTENSIONS.register(new ExampleResultExtension());
}

After that you can use it in your recipes like any other Extension.