Added a recipe for removing items from jars

This commit is contained in:
Sollace 2023-09-29 00:03:10 +01:00
parent 3dcdf8664d
commit 27051ec13f
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
3 changed files with 64 additions and 0 deletions

View file

@ -0,0 +1,60 @@
package com.minelittlepony.unicopia.item;
import org.jetbrains.annotations.Nullable;
import net.minecraft.inventory.RecipeInputInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.recipe.RecipeSerializer;
import net.minecraft.recipe.SpecialCraftingRecipe;
import net.minecraft.recipe.book.CraftingRecipeCategory;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.util.Identifier;
import net.minecraft.world.World;
public class JarExtractRecipe extends SpecialCraftingRecipe {
public JarExtractRecipe(Identifier id, CraftingRecipeCategory category) {
super(id, category);
}
@Override
public final boolean fits(int i, int j) {
return i * j >= 1;
}
@Override
public final boolean matches(RecipeInputInventory inventory, World world) {
return !craft(inventory, null).isEmpty();
}
@Override
public ItemStack craft(RecipeInputInventory inventory, @Nullable DynamicRegistryManager manager) {
ItemStack jar = ItemStack.EMPTY;
for (int i = 0; i < inventory.size(); i++) {
ItemStack stack = inventory.getStack(i);
if (stack.isEmpty()) {
continue;
}
if (!stack.isOf(UItems.FILLED_JAR)) {
return ItemStack.EMPTY;
}
if (!jar.isEmpty()) {
return ItemStack.EMPTY;
}
if (!UItems.FILLED_JAR.hasAppearance(stack)) {
return ItemStack.EMPTY;
}
jar = stack;
}
return UItems.FILLED_JAR.getAppearanceStack(jar);
}
@Override
public RecipeSerializer<?> getSerializer() {
return URecipes.JAR_INSERT_SERIALIZER;
}
}

View file

@ -23,6 +23,7 @@ public interface URecipes {
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<JarExtractRecipe> JAR_EXTRACT_SERIALIZER = RecipeSerializer.register("unicopia:jar_extract", new SpecialRecipeSerializer<>(JarExtractRecipe::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());

View file

@ -0,0 +1,3 @@
{
"type": "unicopia:jar_extract"
}