public AbstractRecipe(Object[] input, Object... output) { this.input = new RecipeInput(input); this.output = new RecipeOutput(output); }
@Test public void testRecipeIngredients() { // Add null -> null recipe RecipeManager.getInstance().addRecipe(new DrinkRecipe(null, null)); // Should be null recipe DrinkRecipe recipe = RecipeManager.getInstance().getRecipeNullable(DrinkRecipe.class, new RecipeInput((Item)null)); // Should be presented Assert.assertNotNull(recipe); // Null input Assert.assertNull(recipe.getInput().first()); // Null output Assert.assertNull(recipe.getOutput().first()); } }
@Override public void startProgress() { DrinkRecipe recipe = RecipeManager.getInstance().getRecipeNullable(DrinkRecipe.class, new RecipeInput(itemStackHandler.getStackInSlot(0).getItem())); if (recipe != null) { FoodCraftReloaded.getLogger().debug("Smelting drink machine: Found recipe " + recipe.getOutput().<FluidStack>first().getFluid().getName()); fluidOutput = recipe.getOutput().first(); output = recipe.getOutput().second(); itemStackHandler.getStackInSlot(0).setCount(itemStackHandler.getStackInSlot(0).getCount() - 1); } }
@Override public boolean canStart() { DrinkRecipe recipe = RecipeManager.getInstance().getRecipeNullable(DrinkRecipe.class, new RecipeInput(itemStackHandler.getStackInSlot(0).getItem())); return super.canStart() && recipe != null && tank.getFluidAmount() < TileEntityDrinkMachine.FLUID_CAPACITY; }
@Override public void getIngredients(@Nonnull IIngredients ingredients) { ingredients.setInput(ItemStack.class, new ItemStack(getRecipe().getInput().<Item>first())); ingredients.setOutput(FluidStack.class, getRecipe().getOutput().first()); ingredients.setOutput(ItemStack.class, getRecipe().getOutput().second()); } }
VegetableEnumLoader vegetableLoader = FoodCraftReloadedMod.getProxy().getLoaderManager().getLoader(VegetableEnumLoader.class).get(); for (FruitType fruitType : FruitType.values()) { RecipeManager.getInstance().addRecipe(new DrinkRecipe(fruitLoader.getInstanceMap(ItemFruit.class).get(fruitType), new FluidStack(fruitLoader.getInstance(FluidFruitJuice.class, fruitType), 1000))); GameRegistry.addShapedRecipe(new ResourceLocation(FoodCraftReloadedMod.MODID, NameBuilder.buildRegistryName(fruitType.toString(), "sapling")), new ResourceLocation(FoodCraftReloadedMod.MODID, "sapling"), RecipeManager.getInstance().addRecipe( new DrinkRecipe(vegetableLoader.getInstanceMap(ItemVegetable.class).get(vegetableType), new FluidStack(vegetableLoader.getInstance(FluidVegetableJuice.class, vegetableType), 1000)) );
@Nullable public <T, R extends Recipe<T>> R getIngredientRecipeNullable(Class<R> recipeClass, T input) { if (!(input instanceof RecipeInput) && !((((RecipeInput) input).value instanceof ItemStack[]) || ((RecipeInput) input).value instanceof Item[])) return null; return getRecipes(recipeClass).stream() .filter(recipe -> recipe.getInput() instanceof RecipeInput) .filter(recipe -> ((RecipeInput) recipe.getInput()).getValue() instanceof Ingredient[]) .filter(recipe -> ((RecipeInput) recipe.getInput()).getValue().length == ((RecipeInput) input).getValue().length) .filter(recipe -> { Ingredient[] ingredients = (Ingredient[]) ((RecipeInput) recipe.getInput()).getValue(); Object[] inputs = ((RecipeInput) input).getValue(); for (int i = 0; i < inputs.length; i++) { ItemStack stack; if (inputs[i] instanceof Item) stack = new ItemStack((Item) inputs[i]); else stack = (ItemStack) inputs[i]; if (!ingredients[i].apply(stack)) return false; } return true; }) .findAny().orElse(null); } }
@Override public void register(IModRegistry registry) { registry.addRecipes(RecipeManager.getInstance().getRecipes(DrinkRecipe.class).stream().map(DrinkRecipeWrapper::new).collect(Collectors.toList()), RecipeUIDs.DRINK); registry.handleRecipes(DrinkRecipeWrapper.class, recipe -> recipe, RecipeUIDs.DRINK); registry.addRecipeClickArea(GuiContainerDrinkMachine.class, 87, 27, 27, 25, RecipeUIDs.DRINK); registry.addRecipeClickArea(GuiContainerSmeltingDrinkMachine.class, 87, 27, 27, 25, RecipeUIDs.DRINK); registry.addRecipeCatalyst(new ItemStack(FCRBlocks.DRINK_MACHINE), RecipeUIDs.DRINK); registry.addRecipeCatalyst(new ItemStack(FCRBlocks.SMELTING_DRINK_MACHINE), RecipeUIDs.DRINK); }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; AbstractRecipe that = (AbstractRecipe) o; if (input != null ? !input.equals(that.input) : that.input != null) return false; return output != null ? output.equals(that.output) : that.output == null; }
default boolean matches(T input) { return input.equals(getInput()); } }
@Nullable public <T, R extends Recipe<T>> R getRecipeNullable(Class<R> recipeClass, T input) { return getRecipe(recipeClass, input).orElse(null); }
@Override public void startProgress() { DrinkRecipe recipe = RecipeManager.getInstance().getRecipeNullable(DrinkRecipe.class, new RecipeInput(itemStackHandler.getStackInSlot(0).getItem())); if (recipe != null) { FoodCraftReloaded.getLogger().debug("Smelting drink machine: Found recipe " + recipe.getOutput().<FluidStack>first().getFluid().getName()); fluidOutput = recipe.getOutput().first(); output = recipe.getOutput().second(); itemStackHandler.getStackInSlot(0).setCount(itemStackHandler.getStackInSlot(0).getCount() - 1); } }
@Override public boolean canStart() { DrinkRecipe recipe = RecipeManager.getInstance().getRecipeNullable(DrinkRecipe.class, new RecipeInput(itemStackHandler.getStackInSlot(0).getItem())); return super.canStart() && recipe != null && tank.getFluidAmount() < TileEntityDrinkMachine.FLUID_CAPACITY; }
public <T, R extends Recipe<T>> Optional<R> getRecipe(Class<R> recipeClass, T input) { return (Optional<R>) recipeMap.get(recipeClass).stream().filter(recipe -> recipe.getInput().equals(input)).findAny(); }