Unicopia/src/main/java/com/minelittlepony/unicopia/item/URecipes.java

56 lines
2.7 KiB
Java
Raw Normal View History

2020-10-02 21:09:14 +02:00
package com.minelittlepony.unicopia.item;
2022-06-25 00:19:55 +02:00
import java.util.List;
2021-02-03 21:25:42 +01:00
import com.google.gson.JsonArray;
import com.minelittlepony.unicopia.ability.magic.spell.crafting.*;
2021-02-03 21:25:42 +01:00
2022-06-25 00:19:55 +02:00
import net.fabricmc.fabric.api.loot.v2.LootTableEvents;
2021-02-19 09:34:26 +01:00
import net.minecraft.loot.LootTable;
2021-02-03 21:25:42 +01:00
import net.minecraft.recipe.Ingredient;
2020-10-02 21:09:14 +02:00
import net.minecraft.recipe.RecipeSerializer;
import net.minecraft.recipe.RecipeType;
import net.minecraft.recipe.ShapedRecipe;
2020-10-02 21:09:14 +02:00
import net.minecraft.recipe.ShapelessRecipe;
2021-02-03 21:25:42 +01:00
import net.minecraft.recipe.SpecialRecipeSerializer;
2020-10-02 21:09:14 +02:00
import net.minecraft.util.Identifier;
2021-02-03 21:25:42 +01:00
import net.minecraft.util.collection.DefaultedList;
2020-10-02 21:09:14 +02:00
public interface URecipes {
RecipeType<SpellbookRecipe> SPELLBOOK = RecipeType.register("unicopia:spellbook");
2020-10-02 21:09:14 +02:00
RecipeSerializer<ShapelessRecipe> ZAP_APPLE_SERIALIZER = RecipeSerializer.register("unicopia:crafting_zap_apple", new ZapAppleRecipe.Serializer());
RecipeSerializer<GlowingRecipe> GLOWING_SERIALIZER = RecipeSerializer.register("unicopia:crafting_glowing", new SpecialRecipeSerializer<>(GlowingRecipe::new));
RecipeSerializer<JarInsertRecipe> JAR_INSERT_SERIALIZER = RecipeSerializer.register("unicopia:jar_insert", new SpecialRecipeSerializer<>(JarInsertRecipe::new));
RecipeSerializer<ShapedRecipe> CRAFTING_MAGICAL_SERIALIZER = RecipeSerializer.register("unicopia:crafting_magical", new SpellShapedCraftingRecipe.Serializer());
RecipeSerializer<SpellCraftingRecipe> TRAIT_REQUIREMENT = RecipeSerializer.register("unicopia:spellbook/crafting", new SpellCraftingRecipe.Serializer());
RecipeSerializer<SpellEnhancingRecipe> TRAIT_COMBINING = RecipeSerializer.register("unicopia:spellbook/combining", new SpellEnhancingRecipe.Serializer());
2022-09-11 18:52:38 +02:00
RecipeSerializer<SpellDuplicatingRecipe> SPELL_DUPLICATING = RecipeSerializer.register("unicopia:spellbook/duplicating", new SpellDuplicatingRecipe.Serializer());
2021-02-03 21:25:42 +01:00
static DefaultedList<Ingredient> getIngredients(JsonArray json) {
DefaultedList<Ingredient> defaultedList = DefaultedList.of();
for (int i = 0; i < json.size(); ++i) {
Ingredient ingredient = Ingredient.fromJson(json.get(i));
if (!ingredient.isEmpty()) {
defaultedList.add(ingredient);
}
}
return defaultedList;
}
2021-02-19 09:34:26 +01:00
static void bootstrap() {
2022-06-25 00:19:55 +02:00
LootTableEvents.MODIFY.register((res, manager, id, supplier, setter) -> {
2021-02-19 09:34:26 +01:00
if (!"minecraft".contentEquals(id.getNamespace())) {
return;
}
Identifier modId = new Identifier("unicopiamc", id.getPath());
2023-06-03 13:40:54 +02:00
LootTable table = manager.getLootTable(modId);
2021-02-19 09:34:26 +01:00
if (table != LootTable.EMPTY) {
2022-06-25 00:19:55 +02:00
supplier.pools(List.of(table.pools));
2021-02-19 09:34:26 +01:00
}
});
}
2020-10-02 21:09:14 +02:00
}