Skip to content

Result Extensions

WolfyScript edited this page Jul 18, 2023 · 8 revisions

Extensions run actions when a recipe is completed or a result is collected.

A player is not required for actions to execute.
Which means they can be executed by

  • Crafting,
  • Cooking/Smelting,
  • Smithing,
  • Anvil,
  • Brewing,
  • and Cauldron recipes

The recipes that do not support extensions are Stonecutter and Campfire recipes.

Settings

result {
  items: [ ],
  tags: [ ],
  target { },
  extensions : [
    {   
      //The type of the extension
      key: "<namespace>:<key>", 
      outer_radius: [0.0, 0.0, 0.0],
      inner_radius: [0.0, 0.0, 0.0],
      executionType: ONCE
      //...other type specific settings
    },
    //more extensions
  ],
  //Other result settings
}

Each Extension has its unique NamespacedKey (key) that specifies the type.
It is possible to have multiple entries of the same type in the extensions array.

Properties

  • key :

    The type of the extension to use.
    required

  • outer_radius :

    Specifies the outer range of the extension, in blocks [x, y, z].
    They are used to specify the area around the location, where the recipe was executed.
    That area can be used to find players, spawn mobs, etc.
    The implementation depends solely on the type of extension.
    Usually used for workstations without a specific player interaction, e.g. Furnaces
    default: [0.0, 0.0, 0.0]

  • inner_radius :

    Specifies the inner range of the extension, in blocks [x, y, z], where it should not look for players.
    Can be used in combination with outer_range to specify an torus like area, where it looks for players.
    Usually used for workstations without a specific player interaction, e.g. Furnaces
    default: [0.0, 0.0, 0.0]

  • executionType :

    Specifies how often the extension should run if a recipe is completed.
    ONCE = Runs the extension only once.
    BULK = Runs the extension for each single recipe when bulk crafting.
    default: ONCE

Included Extensions


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.

| Home

  • Editions
  • Installation

| General

  • Performance
  • Terminology

| Recipes

Types

  • From 1.6.5.x
  • From 1.6.4.0
  • From 1.6.3.0 or older

| Special Workstations

  • Custom Recipe Book
  • Vanilla Recipe Book
Clone this wiki locally