Skip to content

3.2.1.2 Result Targets

WolfyScript edited this page Mar 1, 2022 · 2 revisions

With the Target feature, you can target specific ingredients of a recipe and use adapters to merge specific ItemMeta/NBT into the resulting ItemStack.

Everything works on a modular basis, which means you can select which adapters to use and you can even code and register your own adapters to merge custom nbt, etc.

There is no GUI for this feature as it is way too complex.
You need to edit your recipe JSON directly!

"result" : {
    "target" : {
      "mergeOptions" : [ {
        "slots" : [ 0 ],
        "adapters" : [ {
          "key" : "customcrafting:enchant"
        }, {
          "key" : "customcrafting:enchanted_book"
        } ]
      } ]
    }
  },

This example only targets the first ingredient of the recipe and will merge all the enchantments into the result. And if the ingredient is an Enchanted Book it will also do the same with the enchantments included in the book.

In the recipe config, you need to add the target field to your result.
Inside that target, you add the mergeOptions array field, which will contain all the options you may want to add.

Merge Option

They target specific slots inside the recipe (Not inside the crafting grid!) and can be configured with multiple adapters.

Properties:
slots: The targeted slots of the recipe.
adapters: The adapters to use for the selected slots.

Included Adapters

Damage

customcrafting:damage
Merges the damage of all items that are targeted (slots) into one.
The behaviour is similar to the vanilla item repair inside the crafting table.

Properties:
repairBonus - This will add part of the result max durability as a bonus.
additionalDamage - The damage added additionally to the combined values.

Display Name

customcrafting:display_name
Merges the names of all targeted items or uses the name of the last item found.

Properties:
appendName - Appends the names of all items together; If false, sets the result name to the name of the last item found.
extra - Extra text to be added to the end of the name.

Enchant

customcrafting:enchant
Adds the enchantments of all selected items to the result.
If there are multiple enchants of the same type, it will just add the one with the highest level.

Properties:
ignoreEnchantLimit - If it should ignore the vanilla enchant level limitations.
blackListedEnchants - List of enchants, that will be ignored.

Enchanted Book

customcrafting:enchanted_book
Adds the enchantments of all selected items (enchanted books) to the result.
If there are multiple enchants of the same type, it will just add the one with the highest level.

Firework Rocket

customcrafting:firework_rocket
This adapter only works for results that are of type FIREWORK_ROCKET!
It allows you to make your own firework recipe, like in vanilla.
It increases the power of the resulting firework depending on the amount of gunpowder, and adds the effects of firework stars to the result.

Properties:
powerIncrement - How much the power should be increased per gunpowder.

PlaceHolder API

customcrafting:placeholderapi
This adapter requires no target slot. Instead, it allows you to replace placeholders in the resulting item, even before the item is crafted, so the player will actually see what they are about to craft.

Properties:
replaceName - If it should replace placeholders in the item name.
nameBracketPlaceholders - If it should replace bracket placeholders in the item name.
replaceLore - If it should replace placeholders in the item lore.
loreBracketPlaceholders - If it should replace bracket placeholders in the item lore.


Custom Adapters

Adapters are created with extensibility in mind, so that you can easily create, register, and use your own adapters to manipulate the resulting items.

Create

To create a custom adapter, you need to create a new class, that extends the MergeAdapter.

import me.wolfyscript.customcrafting.recipes.items.target.MergeAdapter

An example Extension looks like this.
It is serialized/deserialized using Jackson, so you require using 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 TestMergeAdapter extends MergeAdapter {

    public TestMergeAdapter() {
        super(new NamespacedKey("your_namespace", "the_key_of_your_adapter"));
        //
    }

    public TestMergeAdapter(TestMergeAdapter adapter) {
        super(adapter);
        //This should copy all your values you have in your object.
    }

    @Override
    public ItemStack merge(RecipeData<?> recipeData, @Nullable Player player, @Nullable Block block, CustomItem customResult, ItemStack result) {
        /*
         Add your code to edit the result here.
        */
        return result; //And return the edited result.
    }

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

Register

To make use of the adapter in your recipes, you're required to register it.

import me.wolfyscript.customcrafting.CCClassRegistry;

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

@Override
public void onLoad() {
    getLogger().info("Registering Result Merge Adapters");
    CCClassRegistry.RESULT_MERGE_ADAPTERS.register(new TestMergeAdapter());
}

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