Files
src
build.gradle
settings.gradle
Code
4 78
src/main/java/com/kodari/craftingrecipes/CustomCraftingRecipesPlugin.java
package com.kodari.craftingrecipes;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ShapelessRecipe;
import org.bukkit.plugin.java.JavaPlugin;
public final class CustomCraftingRecipesPlugin extends JavaPlugin {
@Override
public void onEnable() {
registerRecipes();
}
private void registerRecipes() {
ShapelessRecipe netheriteRecipe = new ShapelessRecipe(
new NamespacedKey(this, "iron_and_blaze_to_netherite"),
item("NETHERITE_INGOT")
);
netheriteRecipe.addIngredient(item("IRON_INGOT"));
netheriteRecipe.addIngredient(item("BLAZE_POWDER"));
Bukkit.addRecipe(netheriteRecipe);
ShapelessRecipe goldenAppleRecipe = new ShapelessRecipe(
new NamespacedKey(this, "apple_and_nugget_to_golden_apple"),
item("GOLDEN_APPLE")
);
goldenAppleRecipe.addIngredient(item("APPLE"));
goldenAppleRecipe.addIngredient(item("GOLD_NUGGET"));
Bukkit.addRecipe(goldenAppleRecipe);
}
private ItemStack item(String materialName) {
return XMaterial.matchXMaterial(materialName)
.map(XMaterial::parseItem)
.orElseThrow(() -> new IllegalStateException("Required material is unavailable: " + materialName));
}
}