All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.minestom.server.recipe.Recipe Maven / Gradle / Ivy

There is a newer version: 7320437640
Show newest version
package net.minestom.server.recipe;

import net.minestom.server.item.ItemStack;
import net.minestom.server.network.NetworkBuffer;
import org.jetbrains.annotations.NotNull;

import java.util.List;

public record Recipe(@NotNull String id, @NotNull Data data) {
    public static final int MAX_INGREDIENTS = 128;

    sealed public interface Data {
    }

    public record Shaped(String group, RecipeCategory.Crafting category,
                         int width, int height, List ingredients,
                         ItemStack result, boolean showNotification) implements Data {
        public static final NetworkBuffer.Type SERIALIZER = RecipeSerializers.SHAPED;

        public Shaped {
            if (ingredients.size() != width * height)
                throw new IllegalArgumentException("Invalid shaped recipe, ingredients size must be equal to width * height");
            ingredients = List.copyOf(ingredients);
        }
    }

    public record Shapeless(String group, RecipeCategory.Crafting category,
                            List ingredients, ItemStack result) implements Data {
        public static final NetworkBuffer.Type SERIALIZER = RecipeSerializers.SHAPELESS;

        public Shapeless {
            if (ingredients.size() > MAX_INGREDIENTS)
                throw new IllegalArgumentException("Shapeless recipe has too many ingredients");
            ingredients = List.copyOf(ingredients);
        }
    }

    public record Smelting(String group, RecipeCategory.Cooking category,
                           Ingredient ingredient, ItemStack result,
                           float experience, int cookingTime) implements Data {
        public static final NetworkBuffer.Type SERIALIZER = RecipeSerializers.SMELTING;
    }

    public record Blasting(String group, RecipeCategory.Cooking category,
                           Ingredient ingredient, ItemStack result,
                           float experience, int cookingTime) implements Data {
        public static final NetworkBuffer.Type SERIALIZER = RecipeSerializers.BLASTING;
    }

    public record Smoking(String group, RecipeCategory.Cooking category,
                          Ingredient ingredient, ItemStack result,
                          float experience, int cookingTime) implements Data {
        public static final NetworkBuffer.Type SERIALIZER = RecipeSerializers.SMOKING;
    }

    public record CampfireCooking(String group, RecipeCategory.Cooking category,
                                  Ingredient ingredient, ItemStack result,
                                  float experience, int cookingTime) implements Data {
        public static final NetworkBuffer.Type SERIALIZER = RecipeSerializers.CAMPFIRE_COOKING;
    }

    public record Stonecutting(String group, Ingredient ingredient,
                               ItemStack result) implements Data {
        public static final NetworkBuffer.Type SERIALIZER = RecipeSerializers.STONECUTTING;
    }

    public record SmithingTransform(Ingredient template, Ingredient base,
                                    Ingredient addition, ItemStack result) implements Data {
        public static final NetworkBuffer.Type SERIALIZER = RecipeSerializers.SMITHING_TRANSFORM;
    }

    public record SmithingTrim(Ingredient template,
                               Ingredient base, Ingredient addition) implements Data {
        public static final NetworkBuffer.Type SERIALIZER = RecipeSerializers.SMITHING_TRIM;
    }

    public record Ingredient(@NotNull List<@NotNull ItemStack> items) {
        public Ingredient {
            items = List.copyOf(items);
        }

        public Ingredient(@NotNull ItemStack @NotNull ... items) {
            this(List.of(items));
        }
    }

    public record SpecialArmorDye(RecipeCategory.Crafting category) implements Data {
        public static final NetworkBuffer.Type SERIALIZER = RecipeSerializers.ARMOR_DYE;
    }

    public record SpecialBookCloning(RecipeCategory.Crafting category) implements Data {
        public static final NetworkBuffer.Type SERIALIZER = RecipeSerializers.BOOK_CLONING;
    }

    public record SpecialMapCloning(RecipeCategory.Crafting category) implements Data {
        public static final NetworkBuffer.Type SERIALIZER = RecipeSerializers.MAP_CLONING;
    }

    public record SpecialMapExtending(RecipeCategory.Crafting category) implements Data {
        public static final NetworkBuffer.Type SERIALIZER = RecipeSerializers.MAP_EXTENDING;
    }

    public record SpecialFireworkRocket(RecipeCategory.Crafting category) implements Data {
        public static final NetworkBuffer.Type SERIALIZER = RecipeSerializers.FIREWORK_ROCKET;
    }

    public record SpecialFireworkStar(RecipeCategory.Crafting category) implements Data {
        public static final NetworkBuffer.Type SERIALIZER = RecipeSerializers.FIREWORK_STAR;
    }

    public record SpecialFireworkStarFade(RecipeCategory.Crafting category) implements Data {
        public static final NetworkBuffer.Type SERIALIZER = RecipeSerializers.FIREWORK_STAR_FADE;
    }

    public record SpecialTippedArrow(RecipeCategory.Crafting category) implements Data {
        public static final NetworkBuffer.Type SERIALIZER = RecipeSerializers.TIPPED_ARROW;
    }

    public record SpecialBannerDuplicate(RecipeCategory.Crafting category) implements Data {
        public static final NetworkBuffer.Type SERIALIZER = RecipeSerializers.BANNER_DUPLICATE;
    }

    public record SpecialShieldDecoration(RecipeCategory.Crafting category) implements Data {
        public static final NetworkBuffer.Type SERIALIZER = RecipeSerializers.SHIELD_DECORATION;
    }

    public record SpecialShulkerBoxColoring(RecipeCategory.Crafting category) implements Data {
        public static final NetworkBuffer.Type SERIALIZER = RecipeSerializers.SPECIAL_SHULKER_BOX_COLORING;
    }

    public record SpecialSuspiciousStew(RecipeCategory.Crafting category) implements Data {
        public static final NetworkBuffer.Type SERIALIZER = RecipeSerializers.SUSPICIOUS_STEW;
    }

    public record SpecialRepairItem(RecipeCategory.Crafting category) implements Data {
        public static final NetworkBuffer.Type SERIALIZER = RecipeSerializers.REPAIR_ITEM;
    }

    public record DecoratedPot(RecipeCategory.Crafting category) implements Data {
        public static final NetworkBuffer.Type SERIALIZER = RecipeSerializers.DECORATED_POT;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy