Implement a way to list and remove recipes from the API

This commit is contained in:
mezz committed 2015-10-21 12:22:27 -07:00
1 parent 824b3f087a
commit c4311cca77
47 files changed
+1409 -1028

No files matched your search

@@ -1,22 +0,0 @@
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.core.recipes;
import net.minecraft.item.crafting.IRecipe;
public interface IDescriptiveRecipe extends IRecipe {
int getWidth();
int getHeight();
Object[] getIngredients();
}
@@ -31,6 +31,7 @@ import net.minecraftforge.oredict.ShapelessOreRecipe;
import cpw.mods.fml.common.registry.GameRegistry;
import forestry.api.recipes.IDescriptiveRecipe;
import forestry.api.recipes.RecipeManagers;
import forestry.core.config.ForestryBlock;
import forestry.core.config.ForestryItem;
@@ -24,6 +24,7 @@ import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;
import forestry.api.recipes.IDescriptiveRecipe;
import forestry.core.config.ForestryBlock;
import forestry.core.config.ForestryItem;
@@ -14,7 +14,7 @@ import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import forestry.core.recipes.IDescriptiveRecipe;
import forestry.api.recipes.IDescriptiveRecipe;
import forestry.core.recipes.RecipeUtil;
import uristqwerty.CraftGuide.api.ItemSlot;
@@ -1,25 +1,68 @@
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.factory;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import javax.annotation.Nullable;
import java.util.Map;
import java.util.Set;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import forestry.api.recipes.ICarpenterManager;
import forestry.api.recipes.ICarpenterRecipe;
import forestry.api.recipes.ICentrifugeManager;
import forestry.api.recipes.ICentrifugeRecipe;
import forestry.api.recipes.ICraftingProvider;
import forestry.api.recipes.IFabricatorManager;
import forestry.api.recipes.IFabricatorRecipe;
import forestry.api.recipes.IFermenterManager;
import forestry.api.recipes.IFermenterRecipe;
import forestry.api.recipes.IForestryRecipe;
import forestry.api.recipes.IMoistenerManager;
import forestry.api.recipes.IMoistenerRecipe;
import forestry.api.recipes.ISqueezerManager;
import forestry.api.recipes.ISqueezerRecipe;
import forestry.api.recipes.IStillManager;
import forestry.api.recipes.IStillRecipe;
public class DummyManagers {
public static class CarpenterManager implements ICarpenterManager {
public static abstract class DummyCraftingProvider<T extends IForestryRecipe> implements ICraftingProvider<T> {
@Override
public boolean addRecipe(T recipe) {
return false;
}
@Override
public boolean removeRecipe(T recipe) {
return false;
}
@Override
public Set<T> recipes() {
return ImmutableSet.of();
}
@Override
public Map<Object[], Object[]> getRecipes() {
return ImmutableMap.of();
}
}
public static class DummyCarpenterManager extends DummyCraftingProvider<ICarpenterRecipe> implements ICarpenterManager {
@Override
public void addRecipe(ItemStack box, ItemStack product, Object... materials) {
@@ -35,37 +78,17 @@ public class DummyManagers {
public void addRecipe(int packagingTime, FluidStack liquid, ItemStack box, ItemStack product, Object... materials) {
}
@Override
public Map<Object[], Object[]> getRecipes() {
return null;
}
}
public static class CentrifugeManager implements ICentrifugeManager {
@Override
public void addRecipe(ICentrifugeRecipe recipe) {
}
public static class DummyCentrifugeManager extends DummyCraftingProvider<ICentrifugeRecipe> implements ICentrifugeManager {
@Override
public void addRecipe(int timePerItem, ItemStack resource, Map<ItemStack, Float> products) {
}
@Override
public Map<Object[], Object[]> getRecipes() {
return null;
}
}
public static class FabricatorManager implements IFabricatorManager {
@Override
public void addRecipe(IFabricatorRecipe recipe) {
}
public static class DummyFabricatorManager extends DummyCraftingProvider<IFabricatorRecipe> implements IFabricatorManager {
@Override
public void addRecipe(ItemStack plan, FluidStack molten, ItemStack result, Object[] pattern) {
@@ -76,14 +99,9 @@ public class DummyManagers {
public void addSmelting(ItemStack resource, FluidStack molten, int meltingPoint) {
}
@Override
public Map<Object[], Object[]> getRecipes() {
return null;
}
}
public static class FermenterManager implements IFermenterManager {
public static class DummyFermenterManager extends DummyCraftingProvider<IFermenterRecipe> implements IFermenterManager {
@Override
public void addRecipe(ItemStack resource, int fermentationValue, float modifier, FluidStack output, FluidStack liquid) {
@@ -94,27 +112,17 @@ public class DummyManagers {
public void addRecipe(ItemStack resource, int fermentationValue, float modifier, FluidStack output) {
}
@Override
public Map<Object[], Object[]> getRecipes() {
return null;
}
}
public static class MoistenerManager implements IMoistenerManager {
public static class DummyMoistenerManager extends DummyCraftingProvider<IMoistenerRecipe> implements IMoistenerManager {
@Override
public void addRecipe(ItemStack resource, ItemStack product, int timePerItem) {
}
@Override
public Map<Object[], Object[]> getRecipes() {
return null;
}
}
public static class SqueezerManager implements ISqueezerManager {
public static class DummySqueezerManager extends DummyCraftingProvider<ISqueezerRecipe> implements ISqueezerManager {
@Override
public void addRecipe(int timePerItem, ItemStack[] resources, FluidStack liquid, ItemStack remnants, int chance) {
@@ -130,23 +138,13 @@ public class DummyManagers {
public void addContainerRecipe(int timePerItem, ItemStack emptyContainer, @Nullable ItemStack remnants, float chance) {
}
@Override
public Map<Object[], Object[]> getRecipes() {
return null;
}
}
public static class StillManager implements IStillManager {
public static class DummyStillManager extends DummyCraftingProvider<IStillRecipe> implements IStillManager {
@Override
public void addRecipe(int cyclesPerUnit, FluidStack input, FluidStack output) {
}
@Override
public Map<Object[], Object[]> getRecipes() {
return null;
}
}
}
@@ -0,0 +1,59 @@
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.factory.recipes;
import javax.annotation.Nullable;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import forestry.api.recipes.ICarpenterRecipe;
import forestry.api.recipes.IDescriptiveRecipe;
import forestry.core.recipes.ShapedRecipeCustom;
public class CarpenterRecipe implements ICarpenterRecipe {
private final int packagingTime;
@Nullable
private final FluidStack liquid;
@Nullable
private final ItemStack box;
private final ShapedRecipeCustom internal;
public CarpenterRecipe(int packagingTime, @Nullable FluidStack liquid, @Nullable ItemStack box, ShapedRecipeCustom internal) {
this.packagingTime = packagingTime;
this.liquid = liquid;
this.box = box;
this.internal = internal;
}
public int getPackagingTime() {
return packagingTime;
}
@Override
@Nullable
public ItemStack getBox() {
return box;
}
@Override
@Nullable
public FluidStack getFluidResource() {
return liquid;
}
@Override
public IDescriptiveRecipe getCraftingGridRecipe() {
return internal;
}
}
@@ -0,0 +1,132 @@
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.factory.recipes;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import forestry.api.recipes.ICarpenterManager;
import forestry.api.recipes.ICarpenterRecipe;
import forestry.api.recipes.IDescriptiveRecipe;
import forestry.core.recipes.ShapedRecipeCustom;
import forestry.core.utils.ItemStackUtil;
public class CarpenterRecipeManager implements ICarpenterManager {
private static final Set<ICarpenterRecipe> recipes = new HashSet<>();
public static final Set<Fluid> recipeFluids = new HashSet<>();
@Override
public void addRecipe(ItemStack box, ItemStack product, Object materials[]) {
addRecipe(5, null, box, product, materials);
}
@Override
public void addRecipe(int packagingTime, ItemStack box, ItemStack product, Object materials[]) {
addRecipe(packagingTime, null, box, product, materials);
}
@Override
public void addRecipe(int packagingTime, FluidStack liquid, ItemStack box, ItemStack product, Object materials[]) {
ICarpenterRecipe recipe = new CarpenterRecipe(packagingTime, liquid, box, ShapedRecipeCustom.createShapedRecipe(product, materials));
addRecipe(recipe);
}
public static ICarpenterRecipe findMatchingRecipe(FluidStack liquid, ItemStack item, IInventory inventorycrafting, World world) {
for (ICarpenterRecipe recipe : recipes) {
if (matches(recipe, liquid, item, inventorycrafting, world)) {
return recipe;
}
}
return null;
}
public static boolean matches(ICarpenterRecipe recipe, FluidStack resource, ItemStack item, IInventory inventoryCrafting, World world) {
FluidStack liquid = recipe.getFluidResource();
if (liquid != null) {
if (resource == null || !resource.containsFluid(liquid)) {
return false;
}
}
ItemStack box = recipe.getBox();
if (box != null && !ItemStackUtil.isCraftingEquivalent(box, item)) {
return false;
}
IDescriptiveRecipe internal = recipe.getCraftingGridRecipe();
return internal.matches(inventoryCrafting, world);
}
public static boolean isBox(ItemStack resource) {
if (resource == null) {
return false;
}
for (ICarpenterRecipe recipe : recipes) {
ItemStack box = recipe.getBox();
if (ItemStackUtil.isIdenticalItem(box, resource)) {
return true;
}
}
return false;
}
@Override
public boolean addRecipe(ICarpenterRecipe recipe) {
FluidStack fluidStack = recipe.getFluidResource();
if (fluidStack != null) {
recipeFluids.add(fluidStack.getFluid());
}
return recipes.add(recipe);
}
@Override
public boolean removeRecipe(ICarpenterRecipe recipe) {
boolean removed = recipes.remove(recipe);
if (removed) {
FluidStack fluidStack = recipe.getFluidResource();
if (fluidStack != null) {
recipeFluids.remove(fluidStack.getFluid());
}
}
return removed;
}
@Override
public Set<ICarpenterRecipe> recipes() {
return Collections.unmodifiableSet(recipes);
}
@Override
public Map<Object[], Object[]> getRecipes() {
HashMap<Object[], Object[]> recipeList = new HashMap<>();
for (ICarpenterRecipe recipe : recipes) {
recipeList.put(recipe.getCraftingGridRecipe().getIngredients(), new Object[]{recipe.getCraftingGridRecipe().getRecipeOutput()});
}
return recipeList;
}
}
@@ -0,0 +1,74 @@
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.factory.recipes;
import com.google.common.collect.ImmutableMap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Random;
import net.minecraft.item.ItemStack;
import forestry.api.recipes.ICentrifugeRecipe;
public class CentrifugeRecipe implements ICentrifugeRecipe {
private final int processingTime;
private final ItemStack input;
private final Map<ItemStack, Float> outputs;
public CentrifugeRecipe(int processingTime, ItemStack input, Map<ItemStack, Float> outputs) {
this.processingTime = processingTime;
this.input = input;
this.outputs = outputs;
for (ItemStack item : outputs.keySet()) {
if (item == null) {
throw new IllegalArgumentException("Tried to register a null product of " + input);
}
}
}
@Override
public ItemStack getInput() {
return input;
}
@Override
public int getProcessingTime() {
return processingTime;
}
@Override
public Collection<ItemStack> getProducts(Random random) {
List<ItemStack> products = new ArrayList<>();
for (Map.Entry<ItemStack, Float> entry : this.outputs.entrySet()) {
float probability = entry.getValue();
if (probability >= 1.0) {
products.add(entry.getKey().copy());
} else if (random.nextFloat() < probability) {
products.add(entry.getKey().copy());
}
}
return products;
}
@Override
public Map<ItemStack, Float> getAllProducts() {
return ImmutableMap.copyOf(outputs);
}
}
@@ -0,0 +1,76 @@
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.factory.recipes;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import net.minecraft.item.ItemStack;
import forestry.api.recipes.ICentrifugeManager;
import forestry.api.recipes.ICentrifugeRecipe;
import forestry.core.utils.ItemStackUtil;
public class CentrifugeRecipeManager implements ICentrifugeManager {
private static final Set<ICentrifugeRecipe> recipes = new HashSet<>();
@Override
public void addRecipe(int timePerItem, ItemStack resource, Map<ItemStack, Float> products) {
ICentrifugeRecipe recipe = new CentrifugeRecipe(timePerItem, resource, products);
addRecipe(recipe);
}
public static ICentrifugeRecipe findMatchingRecipe(ItemStack itemStack) {
if (itemStack == null) {
return null;
}
for (ICentrifugeRecipe recipe : recipes) {
ItemStack recipeInput = recipe.getInput();
if (ItemStackUtil.isCraftingEquivalent(recipeInput, itemStack)) {
return recipe;
}
}
return null;
}
@Override
public boolean addRecipe(ICentrifugeRecipe recipe) {
return recipes.add(recipe);
}
@Override
public boolean removeRecipe(ICentrifugeRecipe recipe) {
return recipes.remove(recipe);
}
@Override
public Set<ICentrifugeRecipe> recipes() {
return Collections.unmodifiableSet(recipes);
}
@Override
@Deprecated
public Map<Object[], Object[]> getRecipes() {
HashMap<Object[], Object[]> recipeList = new HashMap<>();
for (ICentrifugeRecipe recipe : recipes) {
Set<ItemStack> productsKeys = recipe.getAllProducts().keySet();
recipeList.put(new Object[]{recipe.getInput()}, productsKeys.toArray(new ItemStack[productsKeys.size()]));
}
return recipeList;
}
}
@@ -0,0 +1,129 @@
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.factory.recipes;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import forestry.api.recipes.IFabricatorManager;
import forestry.api.recipes.IFabricatorRecipe;
import forestry.core.recipes.ShapedRecipeCustom;
import forestry.core.utils.ItemStackUtil;
public class FabricatorRecipeManager implements IFabricatorManager {
private static final Set<IFabricatorRecipe> recipes = new HashSet<>();
public static final Set<FabricatorSmeltingRecipe> smeltings = new HashSet<>();
@Override
public void addRecipe(ItemStack plan, FluidStack molten, ItemStack result, Object[] pattern) {
IFabricatorRecipe recipe = new FabricatorRecipe(plan, molten, ShapedRecipeCustom.createShapedRecipe(result, pattern));
addRecipe(recipe);
}
@Override
public void addSmelting(ItemStack resource, FluidStack molten, int meltingPoint) {
if (resource == null || molten == null) {
return;
}
smeltings.add(new FabricatorSmeltingRecipe(resource, molten, meltingPoint));
}
public static IFabricatorRecipe findMatchingRecipe(ItemStack plan, FluidStack liquid, ItemStack[] resources) {
ItemStack[][] gridResources = new ItemStack[3][3];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
gridResources[j][i] = resources[i * 3 + j];
}
}
for (IFabricatorRecipe recipe : recipes) {
if (recipe.matches(plan, gridResources)) {
if (liquid == null || liquid.containsFluid(recipe.getLiquid())) {
return recipe;
}
}
}
return null;
}
public static boolean isPlan(ItemStack plan) {
for (IFabricatorRecipe recipe : recipes) {
if (ItemStackUtil.isIdenticalItem(recipe.getPlan(), plan)) {
return true;
}
}
return false;
}
public static FabricatorSmeltingRecipe findMatchingSmelting(ItemStack resource) {
if (resource == null) {
return null;
}
for (FabricatorSmeltingRecipe smelting : smeltings) {
if (ItemStackUtil.isCraftingEquivalent(smelting.getResource(), resource)) {
return smelting;
}
}
return null;
}
public static FabricatorSmeltingRecipe findMatchingSmelting(FluidStack product) {
if (product == null) {
return null;
}
for (FabricatorSmeltingRecipe smelting : smeltings) {
if (smelting.matches(product)) {
return smelting;
}
}
return null;
}
@Override
public boolean addRecipe(IFabricatorRecipe recipe) {
return recipes.add(recipe);
}
@Override
public boolean removeRecipe(IFabricatorRecipe recipe) {
return recipes.remove(recipe);
}
@Override
public Set<IFabricatorRecipe> recipes() {
return Collections.unmodifiableSet(recipes);
}
@Override
public Map<Object[], Object[]> getRecipes() {
HashMap<Object[], Object[]> recipeList = new HashMap<>();
for (IFabricatorRecipe recipe : recipes) {
recipeList.put(recipe.getIngredients(), new Object[]{recipe.getRecipeOutput()});
}
return recipeList;
}
}
@@ -0,0 +1,51 @@
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.factory.recipes;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
public class FabricatorSmeltingRecipe {
private final ItemStack resource;
private final FluidStack product;
private final int meltingPoint;
public FabricatorSmeltingRecipe(ItemStack resource, FluidStack molten, int meltingPoint) {
if (resource == null) {
throw new IllegalArgumentException("Resource cannot be null");
}
if (molten == null) {
throw new IllegalArgumentException("Molten cannot be null");
}
this.resource = resource;
this.product = molten;
this.meltingPoint = meltingPoint;
}
public boolean matches(FluidStack product) {
return this.product.isFluidEqual(product);
}
public ItemStack getResource() {
return resource;
}
public FluidStack getProduct() {
return product;
}
public int getMeltingPoint() {
return meltingPoint;
}
}
@@ -0,0 +1,78 @@
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.factory.recipes;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import forestry.api.recipes.IFermenterRecipe;
import forestry.core.fluids.Fluids;
public class FermenterRecipe implements IFermenterRecipe {
private final ItemStack resource;
private final int fermentationValue;
private final float modifier;
private final Fluid output;
private final FluidStack fluidResource;
public FermenterRecipe(ItemStack resource, int fermentationValue, float modifier, Fluid output, FluidStack fluidResource) {
// assume that fermenter recipes want to use Forestry's honey and not the legacy "fluid.honey"
if (Fluids.LEGACY_HONEY.is(fluidResource)) {
fluidResource = Fluids.HONEY.getFluid(fluidResource.amount);
}
if (resource == null) {
throw new NullPointerException("Fermenter Resource cannot be null!");
}
if (output == null) {
throw new NullPointerException("Fermenter Output cannot be null!");
}
if (fluidResource == null) {
throw new NullPointerException("Fermenter Liquid cannot be null!");
}
this.resource = resource;
this.fermentationValue = fermentationValue;
this.modifier = modifier;
this.output = output;
this.fluidResource = fluidResource;
}
@Override
public ItemStack getResource() {
return resource;
}
@Override
public FluidStack getFluidResource() {
return fluidResource;
}
@Override
public int getFermentationValue() {
return fermentationValue;
}
@Override
public float getModifier() {
return modifier;
}
@Override
public Fluid getOutput() {
return output;
}
}
@@ -0,0 +1,115 @@
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.factory.recipes;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import forestry.api.recipes.IFermenterManager;
import forestry.api.recipes.IFermenterRecipe;
import forestry.core.fluids.Fluids;
import forestry.core.utils.ItemStackUtil;
public class FermenterRecipeManager implements IFermenterManager {
private static final Set<IFermenterRecipe> recipes = new HashSet<>();
public static final Set<Fluid> recipeFluidInputs = new HashSet<>();
public static final Set<Fluid> recipeFluidOutputs = new HashSet<>();
@Override
public void addRecipe(ItemStack resource, int fermentationValue, float modifier, FluidStack output, FluidStack liquid) {
IFermenterRecipe recipe = new FermenterRecipe(resource, fermentationValue, modifier, output.getFluid(), liquid);
addRecipe(recipe);
}
@Override
public void addRecipe(ItemStack resource, int fermentationValue, float modifier, FluidStack output) {
addRecipe(resource, fermentationValue, modifier, output, Fluids.WATER.getFluid(1000));
}
public static IFermenterRecipe findMatchingRecipe(ItemStack res, FluidStack liqu) {
for (IFermenterRecipe recipe : recipes) {
if (matches(recipe, res, liqu)) {
return recipe;
}
}
return null;
}
private static boolean matches(IFermenterRecipe recipe, ItemStack res, FluidStack liqu) {
ItemStack resource = recipe.getResource();
if (!ItemStackUtil.isCraftingEquivalent(resource, res)) {
return false;
}
FluidStack fluid = recipe.getFluidResource();
return liqu != null && liqu.containsFluid(fluid);
}
public static boolean isResource(ItemStack resource) {
if (resource == null) {
return false;
}
for (IFermenterRecipe recipe : recipes) {
if (ItemStackUtil.isCraftingEquivalent(recipe.getResource(), resource)) {
return true;
}
}
return false;
}
@Override
public boolean addRecipe(IFermenterRecipe recipe) {
FluidStack liquid = recipe.getFluidResource();
recipeFluidInputs.add(liquid.getFluid());
Fluid output = recipe.getOutput();
recipeFluidOutputs.add(output);
return recipes.add(recipe);
}
@Override
public boolean removeRecipe(IFermenterRecipe recipe) {
FluidStack liquid = recipe.getFluidResource();
recipeFluidInputs.remove(liquid.getFluid());
Fluid output = recipe.getOutput();
recipeFluidOutputs.remove(output);
return recipes.remove(recipe);
}
@Override
public Set<IFermenterRecipe> recipes() {
return Collections.unmodifiableSet(recipes);
}
@Override
public Map<Object[], Object[]> getRecipes() {
HashMap<Object[], Object[]> recipeList = new HashMap<>();
for (IFermenterRecipe recipe : recipes) {
recipeList.put(new Object[]{recipe.getResource(), recipe.getFluidResource()}, new Object[]{recipe.getOutput()});
}
return recipeList;
}
}
@@ -12,6 +12,8 @@ package forestry.factory.recipes;
import net.minecraft.item.ItemStack;
import forestry.api.recipes.ISqueezerRecipe;
public interface ISqueezerContainerRecipe {
ItemStack getEmptyContainer();
@@ -12,18 +12,29 @@ package forestry.factory.recipes;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import forestry.api.recipes.IMoistenerRecipe;
public interface ISqueezerRecipe {
public class MoistenerRecipe implements IMoistenerRecipe {
ItemStack[] getResources();
private final int timePerItem;
private final ItemStack resource;
private final ItemStack product;
int getProcessingTime();
public MoistenerRecipe(ItemStack resource, ItemStack product, int timePerItem) {
this.timePerItem = timePerItem;
this.resource = resource;
this.product = product;
}
ItemStack getRemnants();
public int getTimePerItem() {
return timePerItem;
}
float getRemnantsChance();
FluidStack getFluidOutput();
public ItemStack getResource() {
return resource;
}
public ItemStack getProduct() {
return product;
}
}
@@ -0,0 +1,83 @@
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.factory.recipes;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import net.minecraft.item.ItemStack;
import forestry.api.recipes.IMoistenerManager;
import forestry.api.recipes.IMoistenerRecipe;
import forestry.core.utils.ItemStackUtil;
public class MoistenerRecipeManager implements IMoistenerManager {
private static final Set<IMoistenerRecipe> recipes = new HashSet<>();
@Override
public void addRecipe(ItemStack resource, ItemStack product, int timePerItem) {
IMoistenerRecipe recipe = new MoistenerRecipe(resource, product, timePerItem);
addRecipe(recipe);
}
public static boolean isResource(ItemStack resource) {
if (resource == null) {
return false;
}
for (IMoistenerRecipe rec : recipes) {
if (ItemStackUtil.isIdenticalItem(resource, rec.getResource())) {
return true;
}
}
return false;
}
public static IMoistenerRecipe findMatchingRecipe(ItemStack item) {
for (IMoistenerRecipe recipe : recipes) {
if (ItemStackUtil.isCraftingEquivalent(recipe.getResource(), item)) {
return recipe;
}
}
return null;
}
@Override
public boolean addRecipe(IMoistenerRecipe recipe) {
return recipes.add(recipe);
}
@Override
public boolean removeRecipe(IMoistenerRecipe recipe) {
return recipes.remove(recipe);
}
@Override
public Set<IMoistenerRecipe> recipes() {
return Collections.unmodifiableSet(recipes);
}
@Override
public Map<Object[], Object[]> getRecipes() {
HashMap<Object[], Object[]> recipeList = new HashMap<>();
for (IMoistenerRecipe recipe : recipes) {
recipeList.put(new ItemStack[]{recipe.getResource()}, new ItemStack[]{recipe.getProduct()});
}
return recipeList;
}
}
@@ -14,6 +14,7 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import forestry.api.recipes.ISqueezerRecipe;
import forestry.core.fluids.FluidHelper;
import forestry.core.utils.ItemStackUtil;
@@ -14,6 +14,8 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import forestry.api.recipes.ISqueezerRecipe;
public class SqueezerRecipe implements ISqueezerRecipe {
private final int processingTime;
@@ -0,0 +1,127 @@
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.factory.recipes;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import forestry.api.recipes.ISqueezerManager;
import forestry.api.recipes.ISqueezerRecipe;
import forestry.core.fluids.FluidHelper;
import forestry.core.utils.ItemStackUtil;
import forestry.core.utils.datastructures.ItemStackMap;
public class SqueezerRecipeManager implements ISqueezerManager {
private static final Set<ISqueezerRecipe> recipes = new HashSet<>();
public static final ItemStackMap<ISqueezerContainerRecipe> containerRecipes = new ItemStackMap<>();
@Override
public void addRecipe(int timePerItem, ItemStack[] resources, FluidStack liquid, @Nullable ItemStack remnants, int chance) {
ISqueezerRecipe recipe = new SqueezerRecipe(timePerItem, resources, liquid, remnants, chance / 100.0f);
addRecipe(recipe);
}
@Override
public void addRecipe(int timePerItem, ItemStack[] resources, FluidStack liquid) {
addRecipe(timePerItem, resources, liquid, null, 0);
}
@Override
public void addContainerRecipe(int timePerItem, ItemStack emptyContainer, @Nullable ItemStack remnants, float chance) {
containerRecipes.put(emptyContainer, new SqueezerContainerRecipe(emptyContainer, timePerItem, remnants, chance));
}
@Nullable
public static ISqueezerContainerRecipe findMatchingContainerRecipe(ItemStack filledContainer) {
ItemStack emptyContainer = FluidHelper.getEmptyContainer(filledContainer);
if (emptyContainer == null) {
return null;
}
return containerRecipes.get(emptyContainer);
}
public static ISqueezerRecipe findMatchingRecipe(ItemStack[] items) {
// Find container recipes
for (ItemStack itemStack : items) {
ISqueezerContainerRecipe containerRecipe = findMatchingContainerRecipe(itemStack);
if (containerRecipe != null) {
ISqueezerRecipe recipe = containerRecipe.getSqueezerRecipe(itemStack);
if (recipe != null) {
return recipe;
}
}
}
// First try to match a specific recipe (without OreDictionary)
for (ISqueezerRecipe recipe : recipes) {
if (ItemStackUtil.containsSets(recipe.getResources(), items, false, false) > 0) {
return recipe;
}
}
// If that fails - try again with OreDictionary support enabled
for (ISqueezerRecipe recipe : recipes) {
if (ItemStackUtil.containsSets(recipe.getResources(), items, true, false) > 0) {
return recipe;
}
}
return null;
}
public static boolean canUse(ItemStack itemStack) {
for (ISqueezerRecipe recipe : recipes) {
for (ItemStack recipeInput : recipe.getResources()) {
if (ItemStackUtil.isCraftingEquivalent(recipeInput, itemStack, true, false)) {
return true;
}
}
}
return SqueezerRecipeManager.findMatchingContainerRecipe(itemStack) != null;
}
@Override
public boolean addRecipe(ISqueezerRecipe recipe) {
return recipes.add(recipe);
}
@Override
public boolean removeRecipe(ISqueezerRecipe recipe) {
return recipes.remove(recipe);
}
@Override
public Set<ISqueezerRecipe> recipes() {
return Collections.unmodifiableSet(recipes);
}
@Override
public Map<Object[], Object[]> getRecipes() {
HashMap<Object[], Object[]> recipeList = new HashMap<>();
for (ISqueezerRecipe recipe : recipes) {
recipeList.put(recipe.getResources(), new Object[]{recipe.getRemnants(), recipe.getFluidOutput()});
}
return recipeList;
}
}
@@ -0,0 +1,48 @@
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.factory.recipes;
import net.minecraftforge.fluids.FluidStack;
import forestry.api.recipes.IStillRecipe;
public class StillRecipe implements IStillRecipe {
private final int timePerUnit;
private final FluidStack input;
private final FluidStack output;
public StillRecipe(int timePerUnit, FluidStack input, FluidStack output) {
this.timePerUnit = timePerUnit;
if (input == null) {
throw new IllegalArgumentException("Still recipes need an input. Input was null.");
}
if (output == null) {
throw new IllegalArgumentException("Still recipes need an output. Output was null.");
}
this.input = input;
this.output = output;
}
@Override
public int getCyclesPerUnit() {
return timePerUnit;
}
@Override
public FluidStack getInput() {
return input;
}
@Override
public FluidStack getOutput() {
return output;
}
}
@@ -0,0 +1,86 @@
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.factory.recipes;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import forestry.api.recipes.IStillManager;
import forestry.api.recipes.IStillRecipe;
public class StillRecipeManager implements IStillManager {
private static final Set<IStillRecipe> recipes = new HashSet<>();
public static final Set<Fluid> recipeFluidInputs = new HashSet<>();
public static final Set<Fluid> recipeFluidOutputs = new HashSet<>();
@Override
public void addRecipe(int timePerUnit, FluidStack input, FluidStack output) {
IStillRecipe recipe = new StillRecipe(timePerUnit, input, output);
addRecipe(recipe);
}
public static IStillRecipe findMatchingRecipe(FluidStack item) {
if (item == null) {
return null;
}
for (IStillRecipe recipe : recipes) {
if (item.containsFluid(recipe.getInput())) {
return recipe;
}
}
return null;
}
@Override
public boolean addRecipe(IStillRecipe recipe) {
FluidStack input = recipe.getInput();
recipeFluidInputs.add(input.getFluid());
FluidStack output = recipe.getOutput();
recipeFluidOutputs.add(output.getFluid());
return recipes.add(recipe);
}
@Override
public boolean removeRecipe(IStillRecipe recipe) {
FluidStack input = recipe.getInput();
recipeFluidInputs.remove(input.getFluid());
FluidStack output = recipe.getOutput();
recipeFluidOutputs.remove(output.getFluid());
return recipes.remove(recipe);
}
@Override
public Set<IStillRecipe> recipes() {
return Collections.unmodifiableSet(recipes);
}
@Override
public Map<Object[], Object[]> getRecipes() {
HashMap<Object[], Object[]> recipeList = new HashMap<>();
for (IStillRecipe recipe : recipes) {
recipeList.put(new Object[]{recipe.getInput()}, new Object[]{recipe.getOutput()});
}
return recipeList;
}
}
@@ -45,7 +45,7 @@ public class CraftGuideBottler implements RecipeProvider {
ItemStack machine = ForestryBlock.factoryTESR.getItemStack(1, Constants.DEFINITION_BOTTLER_META);
RecipeTemplate template = generator.createRecipeTemplate(slots, machine);
for (TileBottler.Recipe recipe : TileBottler.RecipeManager.recipes) {
for (TileBottler.BottlerRecipe recipe : TileBottler.RecipeManager.recipes()) {
Object[] array = new Object[4];
array[0] = recipe.can;
@@ -12,10 +12,11 @@ package forestry.factory.recipes.craftguide;
import net.minecraft.item.ItemStack;
import forestry.api.recipes.ICarpenterRecipe;
import forestry.api.recipes.RecipeManagers;
import forestry.core.config.Constants;
import forestry.core.config.ForestryBlock;
import forestry.core.recipes.RecipeUtil;
import forestry.factory.tiles.TileCarpenter;
import uristqwerty.CraftGuide.api.ItemSlot;
import uristqwerty.CraftGuide.api.LiquidSlot;
@@ -50,19 +51,19 @@ public class CraftGuideCarpenter implements RecipeProvider {
ItemStack machine = ForestryBlock.factoryTESR.getItemStack(1, Constants.DEFINITION_CARPENTER_META);
RecipeTemplate template = generator.createRecipeTemplate(slots, machine);
for (TileCarpenter.Recipe recipe : TileCarpenter.RecipeManager.recipes) {
for (ICarpenterRecipe recipe : RecipeManagers.carpenterManager.recipes()) {
Object[] array = new Object[12];
Object[] flattened = RecipeUtil.getCraftingRecipeAsArray(recipe.asIRecipe());
Object[] flattened = RecipeUtil.getCraftingRecipeAsArray(recipe.getCraftingGridRecipe());
if (flattened == null) {
flattened = generator.getCraftingRecipe(recipe.asIRecipe());
flattened = generator.getCraftingRecipe(recipe.getCraftingGridRecipe());
}
if (flattened == null) {
continue;
}
System.arraycopy(flattened, 0, array, 0, flattened.length);
if (recipe.getLiquid() != null) {
array[10] = recipe.getLiquid();
if (recipe.getFluidResource() != null) {
array[10] = recipe.getFluidResource();
}
array[11] = machine;
generator.addRecipe(template, array);
@@ -17,9 +17,9 @@ import java.util.Map.Entry;
import net.minecraft.item.ItemStack;
import forestry.api.recipes.ICentrifugeRecipe;
import forestry.api.recipes.RecipeManagers;
import forestry.core.config.Constants;
import forestry.core.config.ForestryBlock;
import forestry.factory.tiles.TileCentrifuge;
import uristqwerty.CraftGuide.api.ChanceSlot;
import uristqwerty.CraftGuide.api.ItemSlot;
@@ -53,7 +53,7 @@ public class CraftGuideCentrifuge implements RecipeProvider {
ItemStack machine = ForestryBlock.factoryTESR.getItemStack(1, Constants.DEFINITION_CENTRIFUGE_META);
RecipeTemplate template = generator.createRecipeTemplate(slots, machine);
for (ICentrifugeRecipe recipe : TileCentrifuge.RecipeManager.recipes) {
for (ICentrifugeRecipe recipe : RecipeManagers.centrifugeManager.recipes()) {
Object[] array = new Object[11];
List<Entry<ItemStack, Float>> entries = new ArrayList<>(recipe.getAllProducts().entrySet());
@@ -13,9 +13,9 @@ package forestry.factory.recipes.craftguide;
import net.minecraft.item.ItemStack;
import forestry.api.recipes.IFabricatorRecipe;
import forestry.api.recipes.RecipeManagers;
import forestry.core.config.Constants;
import forestry.core.config.ForestryBlock;
import forestry.factory.tiles.TileFabricator;
import uristqwerty.CraftGuide.api.ItemSlot;
import uristqwerty.CraftGuide.api.LiquidSlot;
@@ -50,7 +50,7 @@ public class CraftGuideFabricator implements RecipeProvider {
ItemStack machine = ForestryBlock.factoryPlain.getItemStack(1, Constants.DEFINITION_FABRICATOR_META);
RecipeTemplate template = generator.createRecipeTemplate(slots, machine);
for (IFabricatorRecipe recipe : TileFabricator.RecipeManager.recipes) {
for (IFabricatorRecipe recipe : RecipeManagers.fabricatorManager.recipes()) {
Object[] array = new Object[12];
Object[] recipeIngredients = recipe.getIngredients();
@@ -18,9 +18,10 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import forestry.api.fuels.FuelManager;
import forestry.api.recipes.IFermenterRecipe;
import forestry.api.recipes.RecipeManagers;
import forestry.core.config.Constants;
import forestry.core.config.ForestryBlock;
import forestry.factory.tiles.TileFermenter;
import uristqwerty.CraftGuide.api.ItemSlot;
import uristqwerty.CraftGuide.api.LiquidSlot;
@@ -53,15 +54,14 @@ public class CraftGuideFermenter implements RecipeProvider {
RecipeTemplate template = generator.createRecipeTemplate(slots, machine);
List<Object> fuels = new ArrayList<Object>(FuelManager.fermenterFuel.keySet());
for (TileFermenter.Recipe recipe : TileFermenter.RecipeManager.recipes) {
for (IFermenterRecipe recipe : RecipeManagers.fermenterManager.recipes()) {
Object[] array = new Object[5];
array[0] = recipe.resource;
array[0] = recipe.getResource();
array[1] = fuels;
array[2] = recipe.liquid;
FluidStack output = recipe.output.copy();
output.amount *= recipe.fermentationValue;
output.amount *= recipe.modifier;
array[2] = recipe.getFluidResource();
int amount = Math.round(recipe.getFermentationValue() * recipe.getModifier());
FluidStack output = new FluidStack(recipe.getOutput(), amount);
array[3] = output;
array[4] = machine;
generator.addRecipe(template, array);
@@ -12,10 +12,10 @@ package forestry.factory.recipes.craftguide;
import net.minecraft.item.ItemStack;
import forestry.api.recipes.ISqueezerRecipe;
import forestry.api.recipes.RecipeManagers;
import forestry.core.config.Constants;
import forestry.core.config.ForestryBlock;
import forestry.factory.recipes.ISqueezerRecipe;
import forestry.factory.tiles.TileSqueezer;
import uristqwerty.CraftGuide.api.ChanceSlot;
import uristqwerty.CraftGuide.api.ItemSlot;
@@ -51,7 +51,7 @@ public class CraftGuideSqueezer implements RecipeProvider {
ItemStack machine = ForestryBlock.factoryTESR.getItemStack(1, Constants.DEFINITION_SQUEEZER_META);
RecipeTemplate template = generator.createRecipeTemplate(slots, machine);
for (ISqueezerRecipe recipe : TileSqueezer.RecipeManager.recipes) {
for (ISqueezerRecipe recipe : RecipeManagers.squeezerManager.recipes()) {
Object[] array = new Object[12];
System.arraycopy(recipe.getResources(), 0, array, 0, recipe.getResources().length);
@@ -12,9 +12,10 @@ package forestry.factory.recipes.craftguide;
import net.minecraft.item.ItemStack;
import forestry.api.recipes.IStillRecipe;
import forestry.api.recipes.RecipeManagers;
import forestry.core.config.Constants;
import forestry.core.config.ForestryBlock;
import forestry.factory.tiles.TileStill;
import uristqwerty.CraftGuide.api.ItemSlot;
import uristqwerty.CraftGuide.api.LiquidSlot;
@@ -44,11 +45,11 @@ public class CraftGuideStill implements RecipeProvider {
ItemStack machine = ForestryBlock.factoryTESR.getItemStack(1, Constants.DEFINITION_STILL_META);
RecipeTemplate template = generator.createRecipeTemplate(slots, machine);
for (TileStill.Recipe recipe : TileStill.RecipeManager.recipes) {
for (IStillRecipe recipe : RecipeManagers.stillManager.recipes()) {
Object[] array = new Object[3];
array[0] = recipe.input;
array[1] = recipe.output;
array[0] = recipe.getInput();
array[1] = recipe.getOutput();
array[2] = machine;
generator.addRecipe(template, array);
}
@@ -35,12 +35,12 @@ import codechicken.nei.PositionedStack;
public class NEIHandlerBottler extends RecipeHandlerBase {
private static final List<TileBottler.Recipe> recipes = new ArrayList<>();
private static final List<TileBottler.BottlerRecipe> recipes = new ArrayList<>();
@Override
public void prepare() {
for (FluidContainerData container : FluidContainerRegistry.getRegisteredFluidContainerData()) {
TileBottler.Recipe recipe = TileBottler.RecipeManager.findMatchingRecipe(container.fluid, container.emptyContainer);
TileBottler.BottlerRecipe recipe = TileBottler.RecipeManager.findMatchingRecipe(container.fluid, container.emptyContainer);
if (recipe != null) {
recipes.add(recipe);
}
@@ -53,7 +53,7 @@ public class NEIHandlerBottler extends RecipeHandlerBase {
public PositionedStack input;
public PositionedStack output;
public CachedBottlerRecipe(TileBottler.Recipe recipe) {
public CachedBottlerRecipe(TileBottler.BottlerRecipe recipe) {
if (recipe.input != null) {
this.fluid = new PositionedFluidTank(recipe.input, 10000, new Rectangle(48, 6, 16, 58), NEIHandlerBottler.this.getGuiTexture(), new Point(176, 0));
}
@@ -120,14 +120,14 @@ public class NEIHandlerBottler extends RecipeHandlerBase {
@Override
public void loadAllRecipes() {
for (TileBottler.Recipe recipe : recipes) {
for (TileBottler.BottlerRecipe recipe : recipes) {
this.arecipes.add(new CachedBottlerRecipe(recipe));
}
}
@Override
public void loadCraftingRecipes(ItemStack result) {
for (TileBottler.Recipe recipe : recipes) {
for (TileBottler.BottlerRecipe recipe : recipes) {
if (NEIServerUtils.areStacksSameTypeCrafting(recipe.bottled, result)) {
this.arecipes.add(new CachedBottlerRecipe(recipe));
}
@@ -136,7 +136,7 @@ public class NEIHandlerBottler extends RecipeHandlerBase {
@Override
public void loadUsageRecipes(ItemStack ingred) {
for (TileBottler.Recipe recipe : recipes) {
for (TileBottler.BottlerRecipe recipe : recipes) {
if (NEIServerUtils.areStacksSameTypeCrafting(recipe.can, ingred)) {
this.arecipes.add(new CachedBottlerRecipe(recipe));
}
@@ -145,7 +145,7 @@ public class NEIHandlerBottler extends RecipeHandlerBase {
@Override
public void loadUsageRecipes(FluidStack ingred) {
for (TileBottler.Recipe recipe : recipes) {
for (TileBottler.BottlerRecipe recipe : recipes) {
if (NEIUtils.areFluidsSameType(recipe.input, ingred)) {
this.arecipes.add(new CachedBottlerRecipe(recipe));
}
@@ -21,12 +21,13 @@ import net.minecraft.util.StatCollector;
import net.minecraftforge.fluids.FluidStack;
import forestry.core.recipes.IDescriptiveRecipe;
import forestry.api.recipes.ICarpenterRecipe;
import forestry.api.recipes.IDescriptiveRecipe;
import forestry.api.recipes.RecipeManagers;
import forestry.core.recipes.nei.NEIUtils;
import forestry.core.recipes.nei.PositionedFluidTank;
import forestry.core.recipes.nei.RecipeHandlerBase;
import forestry.factory.gui.GuiCarpenter;
import forestry.factory.tiles.TileCarpenter;
import codechicken.lib.gui.GuiDraw;
import codechicken.nei.NEIServerUtils;
@@ -49,8 +50,8 @@ public class NEIHandlerCarpenter extends RecipeHandlerBase {
public PositionedFluidTank tank;
public PositionedStack output;
public CachedCarpenterRecipe(TileCarpenter.Recipe recipe, boolean genPerms) {
IDescriptiveRecipe irecipe = (IDescriptiveRecipe) recipe.asIRecipe();
public CachedCarpenterRecipe(ICarpenterRecipe recipe, boolean genPerms) {
IDescriptiveRecipe irecipe = recipe.getCraftingGridRecipe();
if (irecipe != null) {
if (irecipe.getIngredients() != null) {
this.setIngredients(irecipe.getWidth(), irecipe.getHeight(), irecipe.getIngredients());
@@ -58,11 +59,11 @@ public class NEIHandlerCarpenter extends RecipeHandlerBase {
if (recipe.getBox() != null) {
this.inputs.add(new PositionedStack(recipe.getBox(), 78, 6));
}
if (recipe.getLiquid() != null) {
this.tank = new PositionedFluidTank(recipe.getLiquid(), 10000, new Rectangle(145, 3, 16, 58), NEIHandlerCarpenter.this.getGuiTexture(), new Point(176, 0));
if (recipe.getFluidResource() != null) {
this.tank = new PositionedFluidTank(recipe.getFluidResource(), 10000, new Rectangle(145, 3, 16, 58), NEIHandlerCarpenter.this.getGuiTexture(), new Point(176, 0));
}
if (recipe.getCraftingResult() != null) {
this.output = new PositionedStack(recipe.getCraftingResult(), 75, 37);
if (recipe.getCraftingGridRecipe().getRecipeOutput() != null) {
this.output = new PositionedStack(recipe.getCraftingGridRecipe().getRecipeOutput(), 75, 37);
}
}
@@ -71,7 +72,7 @@ public class NEIHandlerCarpenter extends RecipeHandlerBase {
}
}
public CachedCarpenterRecipe(TileCarpenter.Recipe recipe) {
public CachedCarpenterRecipe(ICarpenterRecipe recipe) {
this(recipe, false);
}
@@ -155,15 +156,15 @@ public class NEIHandlerCarpenter extends RecipeHandlerBase {
@Override
public void loadAllRecipes() {
for (TileCarpenter.Recipe recipe : TileCarpenter.RecipeManager.recipes) {
for (ICarpenterRecipe recipe : RecipeManagers.carpenterManager.recipes()) {
this.arecipes.add(new CachedCarpenterRecipe(recipe, true));
}
}
@Override
public void loadCraftingRecipes(ItemStack result) {
for (TileCarpenter.Recipe recipe : TileCarpenter.RecipeManager.recipes) {
if (NEIServerUtils.areStacksSameTypeCrafting(recipe.getCraftingResult(), result)) {
for (ICarpenterRecipe recipe : RecipeManagers.carpenterManager.recipes()) {
if (NEIServerUtils.areStacksSameTypeCrafting(recipe.getCraftingGridRecipe().getRecipeOutput(), result)) {
this.arecipes.add(new CachedCarpenterRecipe(recipe, true));
}
}
@@ -172,7 +173,7 @@ public class NEIHandlerCarpenter extends RecipeHandlerBase {
@Override
public void loadUsageRecipes(ItemStack ingred) {
super.loadUsageRecipes(ingred);
for (TileCarpenter.Recipe recipe : TileCarpenter.RecipeManager.recipes) {
for (ICarpenterRecipe recipe : RecipeManagers.carpenterManager.recipes()) {
CachedCarpenterRecipe crecipe = new CachedCarpenterRecipe(recipe);
if (crecipe.inputs != null && crecipe.contains(crecipe.inputs, ingred)) {
crecipe.generatePermutations();
@@ -184,8 +185,8 @@ public class NEIHandlerCarpenter extends RecipeHandlerBase {
@Override
public void loadUsageRecipes(FluidStack ingredient) {
for (TileCarpenter.Recipe recipe : TileCarpenter.RecipeManager.recipes) {
if (NEIUtils.areFluidsSameType(recipe.getLiquid(), ingredient)) {
for (ICarpenterRecipe recipe : RecipeManagers.carpenterManager.recipes()) {
if (NEIUtils.areFluidsSameType(recipe.getFluidResource(), ingredient)) {
this.arecipes.add(new CachedCarpenterRecipe(recipe, true));
}
}
@@ -23,10 +23,10 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.StatCollector;
import forestry.api.recipes.ICentrifugeRecipe;
import forestry.api.recipes.RecipeManagers;
import forestry.core.recipes.nei.PositionedStackAdv;
import forestry.core.recipes.nei.RecipeHandlerBase;
import forestry.factory.gui.GuiCentrifuge;
import forestry.factory.tiles.TileCentrifuge;
import codechicken.nei.NEIServerUtils;
import codechicken.nei.PositionedStack;
@@ -131,14 +131,14 @@ public class NEIHandlerCentrifuge extends RecipeHandlerBase {
@Override
public void loadAllRecipes() {
for (ICentrifugeRecipe recipe : TileCentrifuge.RecipeManager.recipes) {
for (ICentrifugeRecipe recipe : RecipeManagers.centrifugeManager.recipes()) {
this.arecipes.add(new CachedCentrifugeRecipe(recipe, true));
}
}
@Override
public void loadCraftingRecipes(ItemStack result) {
for (ICentrifugeRecipe recipe : TileCentrifuge.RecipeManager.recipes) {
for (ICentrifugeRecipe recipe : RecipeManagers.centrifugeManager.recipes()) {
CachedCentrifugeRecipe crecipe = new CachedCentrifugeRecipe(recipe);
if (crecipe.outputs != null && crecipe.contains(crecipe.outputs, result)) {
crecipe.setIngredientPermutation(crecipe.outputs, result);
@@ -150,7 +150,7 @@ public class NEIHandlerCentrifuge extends RecipeHandlerBase {
@Override
public void loadUsageRecipes(ItemStack ingred) {
super.loadCraftingRecipes(ingred);
for (ICentrifugeRecipe recipe : TileCentrifuge.RecipeManager.recipes) {
for (ICentrifugeRecipe recipe : RecipeManagers.centrifugeManager.recipes()) {
if (NEIServerUtils.areStacksSameTypeCrafting(recipe.getInput(), ingred)) {
this.arecipes.add(new CachedCentrifugeRecipe(recipe, true));
}
@@ -28,12 +28,14 @@ import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import forestry.api.recipes.IFabricatorRecipe;
import forestry.api.recipes.RecipeManagers;
import forestry.core.recipes.nei.INBTMatchingCachedRecipe;
import forestry.core.recipes.nei.NEIUtils;
import forestry.core.recipes.nei.PositionedFluidTank;
import forestry.core.recipes.nei.RecipeHandlerBase;
import forestry.factory.gui.GuiFabricator;
import forestry.factory.tiles.TileFabricator;
import forestry.factory.recipes.FabricatorRecipeManager;
import forestry.factory.recipes.FabricatorSmeltingRecipe;
import codechicken.nei.NEIServerUtils;
import codechicken.nei.PositionedStack;
@@ -55,7 +57,7 @@ public class NEIHandlerFabricator extends RecipeHandlerBase {
if (recipe.getLiquid() != null) {
this.tank = new PositionedFluidTank(recipe.getLiquid(), 2000, new Rectangle(21, 37, 16, 16));
List<ItemStack> smeltingInput = new ArrayList<>();
for (TileFabricator.Smelting s : getSmeltingInputs().get(recipe.getLiquid().getFluid())) {
for (FabricatorSmeltingRecipe s : getSmeltingInputs().get(recipe.getLiquid().getFluid())) {
smeltingInput.add(s.getResource());
}
if (!smeltingInput.isEmpty()) {
@@ -198,14 +200,14 @@ public class NEIHandlerFabricator extends RecipeHandlerBase {
@Override
public void loadAllRecipes() {
for (IFabricatorRecipe recipe : TileFabricator.RecipeManager.recipes) {
for (IFabricatorRecipe recipe : RecipeManagers.fabricatorManager.recipes()) {
this.arecipes.add(new CachedFabricatorRecipe(recipe, true));
}
}
@Override
public void loadCraftingRecipes(ItemStack result) {
for (IFabricatorRecipe recipe : TileFabricator.RecipeManager.recipes) {
for (IFabricatorRecipe recipe : RecipeManagers.fabricatorManager.recipes()) {
if (NEIServerUtils.areStacksSameTypeCrafting(recipe.getRecipeOutput(), result)) {
CachedFabricatorRecipe crecipe = new CachedFabricatorRecipe(recipe, true);
NEIUtils.setResultPermutationNBT(crecipe, result);
@@ -217,7 +219,7 @@ public class NEIHandlerFabricator extends RecipeHandlerBase {
@Override
public void loadUsageRecipes(ItemStack ingred) {
super.loadUsageRecipes(ingred);
for (IFabricatorRecipe recipe : TileFabricator.RecipeManager.recipes) {
for (IFabricatorRecipe recipe : RecipeManagers.fabricatorManager.recipes()) {
CachedFabricatorRecipe crecipe = new CachedFabricatorRecipe(recipe);
if (crecipe.inputs != null && crecipe.contains(crecipe.inputs, ingred) || crecipe.smeltingInput != null && crecipe.contains(crecipe.smeltingInput, ingred)) {
crecipe.generatePermutations();
@@ -230,7 +232,7 @@ public class NEIHandlerFabricator extends RecipeHandlerBase {
@Override
public void loadUsageRecipes(FluidStack ingredient) {
for (IFabricatorRecipe recipe : TileFabricator.RecipeManager.recipes) {
for (IFabricatorRecipe recipe : RecipeManagers.fabricatorManager.recipes()) {
if (NEIUtils.areFluidsSameType(recipe.getLiquid(), ingredient)) {
this.arecipes.add(new CachedFabricatorRecipe(recipe, true));
}
@@ -242,7 +244,7 @@ public class NEIHandlerFabricator extends RecipeHandlerBase {
super.provideItemTooltip(guiRecipe, itemStack, currenttip, crecipe, relMouse);
if (new Rectangle(20, 9, 18, 18).contains(relMouse)) {
for (TileFabricator.Smelting smelting : TileFabricator.RecipeManager.smeltings) {
for (FabricatorSmeltingRecipe smelting : FabricatorRecipeManager.smeltings) {
if (NEIServerUtils.areStacksSameTypeCrafting(smelting.getResource(), itemStack) && smelting.getProduct() != null) {
currenttip.add(EnumChatFormatting.GRAY.toString() + NEIUtils.translate("handler.forestry.fabricator.worth") + " " + smelting.getProduct().amount + " mB");
}
@@ -252,12 +254,12 @@ public class NEIHandlerFabricator extends RecipeHandlerBase {
return currenttip;
}
private static Map<Fluid, List<TileFabricator.Smelting>> getSmeltingInputs() {
Map<Fluid, List<TileFabricator.Smelting>> smeltingInputs = new HashMap<>();
for (TileFabricator.Smelting smelting : TileFabricator.RecipeManager.smeltings) {
private static Map<Fluid, List<FabricatorSmeltingRecipe>> getSmeltingInputs() {
Map<Fluid, List<FabricatorSmeltingRecipe>> smeltingInputs = new HashMap<>();
for (FabricatorSmeltingRecipe smelting : FabricatorRecipeManager.smeltings) {
Fluid fluid = smelting.getProduct().getFluid();
if (!smeltingInputs.containsKey(fluid)) {
smeltingInputs.put(fluid, new ArrayList<TileFabricator.Smelting>());
smeltingInputs.put(fluid, new ArrayList<FabricatorSmeltingRecipe>());
}
smeltingInputs.get(fluid).add(smelting);
}
@@ -24,13 +24,15 @@ import net.minecraftforge.fluids.FluidStack;
import forestry.api.fuels.FermenterFuel;
import forestry.api.fuels.FuelManager;
import forestry.api.recipes.IFermenterRecipe;
import forestry.api.recipes.IVariableFermentable;
import forestry.api.recipes.RecipeManagers;
import forestry.core.config.Constants;
import forestry.core.recipes.nei.INBTMatchingCachedRecipe;
import forestry.core.recipes.nei.NEIUtils;
import forestry.core.recipes.nei.PositionedFluidTank;
import forestry.core.recipes.nei.RecipeHandlerBase;
import forestry.factory.gui.GuiFermenter;
import forestry.factory.tiles.TileFermenter;
import codechicken.lib.gui.GuiDraw;
import codechicken.nei.NEIServerUtils;
@@ -53,19 +55,18 @@ public class NEIHandlerFermenter extends RecipeHandlerBase {
public PositionedStack resource;
public List<PositionedStack> inputItems = new ArrayList<>();
public CachedFermenterRecipe(TileFermenter.Recipe recipe, ItemStack fermentable, boolean genPerms) {
if (recipe.liquid != null) {
FluidStack input = recipe.liquid.copy();
input.amount = recipe.fermentationValue;
public CachedFermenterRecipe(IFermenterRecipe recipe, ItemStack fermentable, boolean genPerms) {
if (recipe.getFluidResource() != null) {
FluidStack input = recipe.getFluidResource().copy();
input.amount = recipe.getFermentationValue();
this.tanks.add(new PositionedFluidTank(input, 10000, new Rectangle(30, 4, 16, 58), NEIHandlerFermenter.this.getGuiTexture(), new Point(176, 0)));
}
if (recipe.output != null) {
FluidStack output = recipe.output.copy();
if (recipe.getOutput() != null) {
int amount = Math.round(recipe.getFermentationValue() * recipe.getModifier());
if (fermentable.getItem() instanceof IVariableFermentable) {
output.amount = (int) (recipe.fermentationValue * recipe.modifier * ((IVariableFermentable) fermentable.getItem()).getFermentationModifier(fermentable));
} else {
output.amount = (int) (recipe.fermentationValue * recipe.modifier);
amount *= ((IVariableFermentable) fermentable.getItem()).getFermentationModifier(fermentable);
}
FluidStack output = new FluidStack(recipe.getOutput(), amount);
this.tanks.add(new PositionedFluidTank(output, 10000, new Rectangle(120, 4, 16, 58), NEIHandlerFermenter.this.getGuiTexture(), new Point(176, 0)));
}
@@ -146,28 +147,29 @@ public class NEIHandlerFermenter extends RecipeHandlerBase {
this.drawProgressBar(93, 31, 176, 78, 4, 18, 80, 11);
}
private List<CachedFermenterRecipe> getCachedRecipes(TileFermenter.Recipe recipe, boolean generatePermutations) {
if (recipe.resource != null && recipe.resource.getItem() instanceof IVariableFermentable) {
private List<CachedFermenterRecipe> getCachedRecipes(IFermenterRecipe recipe, boolean generatePermutations) {
if (recipe.getResource() != null && recipe.getResource().getItem() instanceof IVariableFermentable) {
List<CachedFermenterRecipe> crecipes = new ArrayList<>();
for (ItemStack stack : NEIUtils.getItemVariations(recipe.resource)) {
for (ItemStack stack : NEIUtils.getItemVariations(recipe.getResource())) {
crecipes.add(new CachedFermenterRecipe(recipe, stack, generatePermutations));
}
return crecipes;
}
return Collections.singletonList(new CachedFermenterRecipe(recipe, recipe.resource, generatePermutations));
return Collections.singletonList(new CachedFermenterRecipe(recipe, recipe.getResource(), generatePermutations));
}
@Override
public void loadAllRecipes() {
for (TileFermenter.Recipe recipe : TileFermenter.RecipeManager.recipes) {
for (IFermenterRecipe recipe : RecipeManagers.fermenterManager.recipes()) {
this.arecipes.addAll(this.getCachedRecipes(recipe, true));
}
}
@Override
public void loadCraftingRecipes(FluidStack result) {
for (TileFermenter.Recipe recipe : TileFermenter.RecipeManager.recipes) {
if (NEIUtils.areFluidsSameType(recipe.output, result)) {
for (IFermenterRecipe recipe : RecipeManagers.fermenterManager.recipes()) {
FluidStack output = new FluidStack(recipe.getOutput(), Constants.BUCKET_VOLUME);
if (NEIUtils.areFluidsSameType(output, result)) {
this.arecipes.addAll(this.getCachedRecipes(recipe, true));
}
}
@@ -176,9 +178,9 @@ public class NEIHandlerFermenter extends RecipeHandlerBase {
@Override
public void loadUsageRecipes(ItemStack ingred) {
super.loadUsageRecipes(ingred);
for (TileFermenter.Recipe recipe : TileFermenter.RecipeManager.recipes) {
if (recipe.resource != null) {
for (ItemStack stack : NEIUtils.getItemVariations(recipe.resource)) {
for (IFermenterRecipe recipe : RecipeManagers.fermenterManager.recipes()) {
if (recipe.getResource() != null) {
for (ItemStack stack : NEIUtils.getItemVariations(recipe.getResource())) {
if (stack.hasTagCompound() && NEIServerUtils.areStacksSameType(stack, ingred) || !stack.hasTagCompound() && NEIServerUtils.areStacksSameTypeCrafting(stack, ingred)) {
CachedFermenterRecipe crecipe = new CachedFermenterRecipe(recipe, stack, true);
NEIUtils.setIngredientPermutationNBT(crecipe, ingred);
@@ -199,8 +201,8 @@ public class NEIHandlerFermenter extends RecipeHandlerBase {
@Override
public void loadUsageRecipes(FluidStack ingred) {
for (TileFermenter.Recipe recipe : TileFermenter.RecipeManager.recipes) {
if (NEIUtils.areFluidsSameType(recipe.liquid, ingred)) {
for (IFermenterRecipe recipe : RecipeManagers.fermenterManager.recipes()) {
if (NEIUtils.areFluidsSameType(recipe.getFluidResource(), ingred)) {
this.arecipes.addAll(this.getCachedRecipes(recipe, true));
}
}
@@ -24,10 +24,11 @@ import net.minecraftforge.fluids.FluidStack;
import forestry.api.fuels.FuelManager;
import forestry.api.fuels.MoistenerFuel;
import forestry.api.recipes.IMoistenerRecipe;
import forestry.api.recipes.RecipeManagers;
import forestry.core.recipes.nei.PositionedFluidTank;
import forestry.core.recipes.nei.RecipeHandlerBase;
import forestry.factory.gui.GuiMoistener;
import forestry.factory.tiles.TileMoistener;
import codechicken.nei.NEIServerUtils;
import codechicken.nei.PositionedStack;
@@ -41,7 +42,7 @@ public class NEIHandlerMoistener extends RecipeHandlerBase {
public PositionedStack input;
public PositionedStack output;
public CachedMoistenerRecipe(TileMoistener.Recipe recipe, MoistenerFuel fuel) {
public CachedMoistenerRecipe(IMoistenerRecipe recipe, MoistenerFuel fuel) {
this.tank = new PositionedFluidTank(FluidRegistry.getFluidStack("water", 10000), 10000, new Rectangle(11, 5, 16, 58), NEIHandlerMoistener.this.getGuiTexture(), new Point(176, 0));
this.tank.showAmount = false;
if (fuel.item != null) {
@@ -50,11 +51,11 @@ public class NEIHandlerMoistener extends RecipeHandlerBase {
if (fuel.product != null) {
this.fuels.add(new PositionedStack(fuel.product, 100, 26));
}
if (recipe.resource != null) {
this.input = new PositionedStack(recipe.resource, 138, 8);
if (recipe.getResource() != null) {
this.input = new PositionedStack(recipe.getResource(), 138, 8);
}
if (recipe.product != null) {
this.output = new PositionedStack(recipe.product, 138, 44);
if (recipe.getProduct() != null) {
this.output = new PositionedStack(recipe.getProduct(), 138, 44);
}
}
@@ -118,7 +119,7 @@ public class NEIHandlerMoistener extends RecipeHandlerBase {
@Override
public void loadAllRecipes() {
for (TileMoistener.Recipe recipe : TileMoistener.RecipeManager.recipes) {
for (IMoistenerRecipe recipe : RecipeManagers.moistenerManager.recipes()) {
for (MoistenerFuel fuel : FuelManager.moistenerResource.values()) {
this.arecipes.add(new CachedMoistenerRecipe(recipe, fuel));
}
@@ -127,9 +128,9 @@ public class NEIHandlerMoistener extends RecipeHandlerBase {
@Override
public void loadCraftingRecipes(ItemStack result) {
for (TileMoistener.Recipe recipe : TileMoistener.RecipeManager.recipes) {
for (IMoistenerRecipe recipe : RecipeManagers.moistenerManager.recipes()) {
for (MoistenerFuel fuel : FuelManager.moistenerResource.values()) {
if (NEIServerUtils.areStacksSameTypeCrafting(recipe.product, result) || NEIServerUtils.areStacksSameTypeCrafting(fuel.product, result)) {
if (NEIServerUtils.areStacksSameTypeCrafting(recipe.getProduct(), result) || NEIServerUtils.areStacksSameTypeCrafting(fuel.product, result)) {
this.arecipes.add(new CachedMoistenerRecipe(recipe, fuel));
}
}
@@ -139,9 +140,9 @@ public class NEIHandlerMoistener extends RecipeHandlerBase {
@Override
public void loadUsageRecipes(ItemStack ingred) {
super.loadUsageRecipes(ingred);
for (TileMoistener.Recipe recipe : TileMoistener.RecipeManager.recipes) {
for (IMoistenerRecipe recipe : RecipeManagers.moistenerManager.recipes()) {
for (MoistenerFuel fuel : FuelManager.moistenerResource.values()) {
if (NEIServerUtils.areStacksSameTypeCrafting(recipe.resource, ingred) || NEIServerUtils.areStacksSameTypeCrafting(fuel.item, ingred)) {
if (NEIServerUtils.areStacksSameTypeCrafting(recipe.getResource(), ingred) || NEIServerUtils.areStacksSameTypeCrafting(fuel.item, ingred)) {
this.arecipes.add(new CachedMoistenerRecipe(recipe, fuel));
}
}
@@ -24,6 +24,8 @@ import net.minecraft.util.StatCollector;
import net.minecraftforge.fluids.FluidStack;
import forestry.api.recipes.ISqueezerRecipe;
import forestry.api.recipes.RecipeManagers;
import forestry.core.fluids.FluidHelper;
import forestry.core.recipes.nei.NEIUtils;
import forestry.core.recipes.nei.PositionedFluidTank;
@@ -31,8 +33,7 @@ import forestry.core.recipes.nei.PositionedStackAdv;
import forestry.core.recipes.nei.RecipeHandlerBase;
import forestry.factory.gui.GuiSqueezer;
import forestry.factory.recipes.ISqueezerContainerRecipe;
import forestry.factory.recipes.ISqueezerRecipe;
import forestry.factory.tiles.TileSqueezer;
import forestry.factory.recipes.SqueezerRecipeManager;
import codechicken.nei.NEIServerUtils;
import codechicken.nei.PositionedStack;
@@ -190,22 +191,22 @@ public class NEIHandlerSqueezer extends RecipeHandlerBase {
@Override
public void loadAllRecipes() {
for (ISqueezerRecipe recipe : TileSqueezer.RecipeManager.recipes) {
for (ISqueezerRecipe recipe : RecipeManagers.squeezerManager.recipes()) {
this.arecipes.add(new CachedSqueezerRecipe(recipe, true));
}
for (ISqueezerContainerRecipe containerRecipe : TileSqueezer.RecipeManager.containerRecipes.values()) {
for (ISqueezerContainerRecipe containerRecipe : SqueezerRecipeManager.containerRecipes.values()) {
this.arecipes.add(new CachedSqueezerRecipe(containerRecipe, true));
}
}
@Override
public void loadCraftingRecipes(ItemStack result) {
for (ISqueezerRecipe recipe : TileSqueezer.RecipeManager.recipes) {
for (ISqueezerRecipe recipe : RecipeManagers.squeezerManager.recipes()) {
if (NEIServerUtils.areStacksSameTypeCrafting(recipe.getRemnants(), result)) {
this.arecipes.add(new CachedSqueezerRecipe(recipe, true));
}
}
for (ISqueezerContainerRecipe containerRecipe : TileSqueezer.RecipeManager.containerRecipes.values()) {
for (ISqueezerContainerRecipe containerRecipe : SqueezerRecipeManager.containerRecipes.values()) {
if (NEIServerUtils.areStacksSameTypeCrafting(containerRecipe.getRemnants(), result)) {
this.arecipes.add(new CachedSqueezerRecipe(containerRecipe, true));
}
@@ -214,12 +215,12 @@ public class NEIHandlerSqueezer extends RecipeHandlerBase {
@Override
public void loadCraftingRecipes(FluidStack result) {
for (ISqueezerRecipe recipe : TileSqueezer.RecipeManager.recipes) {
for (ISqueezerRecipe recipe : RecipeManagers.squeezerManager.recipes()) {
if (NEIUtils.areFluidsSameType(recipe.getFluidOutput(), result)) {
this.arecipes.add(new CachedSqueezerRecipe(recipe, true));
}
}
for (ISqueezerContainerRecipe containerRecipe : TileSqueezer.RecipeManager.containerRecipes.values()) {
for (ISqueezerContainerRecipe containerRecipe : SqueezerRecipeManager.containerRecipes.values()) {
ItemStack emptyContainer = containerRecipe.getEmptyContainer();
ItemStack filledContainer = FluidHelper.getFilledContainer(result, emptyContainer);
if (filledContainer != null) {
@@ -235,7 +236,7 @@ public class NEIHandlerSqueezer extends RecipeHandlerBase {
public void loadUsageRecipes(ItemStack ingred) {
ingred.stackSize = 1;
ISqueezerContainerRecipe containerRecipe = TileSqueezer.RecipeManager.findMatchingContainerRecipe(ingred);
ISqueezerContainerRecipe containerRecipe = SqueezerRecipeManager.findMatchingContainerRecipe(ingred);
if (containerRecipe != null) {
CachedSqueezerRecipe crecipe = new CachedSqueezerRecipe(containerRecipe, true);
crecipe.setIngredients(new ItemStack[]{ingred});
@@ -245,7 +246,7 @@ public class NEIHandlerSqueezer extends RecipeHandlerBase {
return;
}
ISqueezerRecipe recipe = TileSqueezer.RecipeManager.findMatchingRecipe(new ItemStack[]{ingred});
ISqueezerRecipe recipe = SqueezerRecipeManager.findMatchingRecipe(new ItemStack[]{ingred});
if (recipe != null) {
CachedSqueezerRecipe crecipe = new CachedSqueezerRecipe(recipe);
// Override recipe to show the right input in case it's OD
@@ -20,11 +20,12 @@ import net.minecraft.util.StatCollector;
import net.minecraftforge.fluids.FluidStack;
import forestry.api.recipes.IStillRecipe;
import forestry.api.recipes.RecipeManagers;
import forestry.core.recipes.nei.NEIUtils;
import forestry.core.recipes.nei.PositionedFluidTank;
import forestry.core.recipes.nei.RecipeHandlerBase;
import forestry.factory.gui.GuiStill;
import forestry.factory.tiles.TileStill;
import codechicken.lib.gui.GuiDraw;
import codechicken.nei.PositionedStack;
@@ -35,12 +36,12 @@ public class NEIHandlerStill extends RecipeHandlerBase {
public List<PositionedFluidTank> tanks = new ArrayList<>();
public CachedStillRecipe(TileStill.Recipe recipe) {
if (recipe.input != null) {
this.tanks.add(new PositionedFluidTank(recipe.input, 10000, new Rectangle(30, 4, 16, 58), NEIHandlerStill.this.getGuiTexture(), new Point(176, 0)));
public CachedStillRecipe(IStillRecipe recipe) {
if (recipe.getInput() != null) {
this.tanks.add(new PositionedFluidTank(recipe.getInput(), 10000, new Rectangle(30, 4, 16, 58), NEIHandlerStill.this.getGuiTexture(), new Point(176, 0)));
}
if (recipe.output != null) {
this.tanks.add(new PositionedFluidTank(recipe.output, 10000, new Rectangle(120, 4, 16, 58), NEIHandlerStill.this.getGuiTexture(), new Point(176, 0)));
if (recipe.getOutput() != null) {
this.tanks.add(new PositionedFluidTank(recipe.getOutput(), 10000, new Rectangle(120, 4, 16, 58), NEIHandlerStill.this.getGuiTexture(), new Point(176, 0)));
}
}
@@ -95,15 +96,15 @@ public class NEIHandlerStill extends RecipeHandlerBase {
@Override
public void loadAllRecipes() {
for (TileStill.Recipe recipe : TileStill.RecipeManager.recipes) {
for (IStillRecipe recipe : RecipeManagers.stillManager.recipes()) {
this.arecipes.add(new CachedStillRecipe(recipe));
}
}
@Override
public void loadCraftingRecipes(FluidStack result) {
for (TileStill.Recipe recipe : TileStill.RecipeManager.recipes) {
if (NEIUtils.areFluidsSameType(recipe.output, result)) {
for (IStillRecipe recipe : RecipeManagers.stillManager.recipes()) {
if (NEIUtils.areFluidsSameType(recipe.getOutput(), result)) {
this.arecipes.add(new CachedStillRecipe(recipe));
}
}
@@ -111,8 +112,8 @@ public class NEIHandlerStill extends RecipeHandlerBase {
@Override
public void loadUsageRecipes(FluidStack ingred) {
for (TileStill.Recipe recipe : TileStill.RecipeManager.recipes) {
if (NEIUtils.areFluidsSameType(recipe.input, ingred)) {
for (IStillRecipe recipe : RecipeManagers.stillManager.recipes()) {
if (NEIUtils.areFluidsSameType(recipe.getInput(), ingred)) {
this.arecipes.add(new CachedStillRecipe(recipe));
}
}
@@ -11,11 +11,13 @@
package forestry.factory.tiles;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Set;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
@@ -35,7 +37,6 @@ import net.minecraftforge.fluids.FluidTankInfo;
import cpw.mods.fml.common.Optional;
import forestry.api.core.ForestryAPI;
import forestry.api.recipes.ICraftingProvider;
import forestry.core.config.Config;
import forestry.core.config.Constants;
import forestry.core.errors.EnumErrorCode;
@@ -64,15 +65,14 @@ public class TileBottler extends TilePowered implements ISidedInventory, ILiquid
private static final short CYCLES_FILLING_DEFAULT = 5;
/* RECIPE MANAGMENT */
public static class Recipe {
public static class BottlerRecipe {
public final int cyclesPerUnit;
public final FluidStack input;
public final ItemStack can;
public final ItemStack bottled;
public Recipe(int cyclesPerUnit, FluidStack input, ItemStack can, ItemStack bottled) {
public BottlerRecipe(int cyclesPerUnit, FluidStack input, ItemStack can, ItemStack bottled) {
this.cyclesPerUnit = cyclesPerUnit;
this.input = input;
this.can = can;
@@ -84,20 +84,20 @@ public class TileBottler extends TilePowered implements ISidedInventory, ILiquid
}
}
public static class RecipeManager implements ICraftingProvider {
public static class RecipeManager {
public static final ArrayList<TileBottler.Recipe> recipes = new ArrayList<>();
private static final Set<BottlerRecipe> recipes = new HashSet<>();
/**
* @return Recipe matching both res and empty, null if none
*/
public static Recipe findMatchingRecipe(FluidStack res, ItemStack empty) {
public static BottlerRecipe findMatchingRecipe(FluidStack res, ItemStack empty) {
// We need both ingredients
if (res == null || empty == null || !FluidHelper.isEmptyContainer(empty)) {
return null;
}
for (Recipe recipe : recipes) {
for (BottlerRecipe recipe : recipes) {
if (recipe.matches(res, empty)) {
return recipe;
}
@@ -106,7 +106,7 @@ public class TileBottler extends TilePowered implements ISidedInventory, ILiquid
// No recipe matched. See if the liquid dictionary has anything.
ItemStack filled = FluidHelper.getFilledContainer(res, empty);
if (filled != null) {
Recipe recipe = new Recipe(CYCLES_FILLING_DEFAULT, res, empty, filled);
BottlerRecipe recipe = new BottlerRecipe(CYCLES_FILLING_DEFAULT, res, empty, filled);
recipes.add(recipe);
return recipe;
}
@@ -124,11 +124,14 @@ public class TileBottler extends TilePowered implements ISidedInventory, ILiquid
return FluidRegistry.isFluidRegistered(res.getFluid());
}
@Override
public Map<Object[], Object[]> getRecipes() {
public static Set<BottlerRecipe> recipes() {
return Collections.unmodifiableSet(recipes);
}
public static Map<Object[], Object[]> getRecipes() {
HashMap<Object[], Object[]> recipeList = new HashMap<>();
for (Recipe recipe : recipes) {
for (BottlerRecipe recipe : recipes) {
recipeList.put(new Object[]{recipe.input, recipe.can}, new Object[]{recipe.bottled});
}
@@ -139,7 +142,7 @@ public class TileBottler extends TilePowered implements ISidedInventory, ILiquid
private final StandardTank resourceTank;
private final TankManager tankManager;
private Recipe currentRecipe;
private BottlerRecipe currentRecipe;
private int fillingTime;
private int fillingTotalTime;
@@ -242,7 +245,7 @@ public class TileBottler extends TilePowered implements ISidedInventory, ILiquid
private void checkRecipe() {
ItemStack emptyCan = getStackInSlot(SLOT_INPUT_EMPTY_CAN);
Recipe recipe = RecipeManager.findMatchingRecipe(resourceTank.getFluid(), emptyCan);
BottlerRecipe recipe = RecipeManager.findMatchingRecipe(resourceTank.getFluid(), emptyCan);
if (currentRecipe != recipe) {
currentRecipe = recipe;
@@ -12,12 +12,6 @@ package forestry.factory.tiles;
import javax.annotation.Nullable;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
@@ -26,25 +20,20 @@ import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.inventory.InventoryCraftResult;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.oredict.OreDictionary;
import forestry.api.core.ForestryAPI;
import forestry.api.core.IErrorLogic;
import forestry.api.recipes.ICarpenterManager;
import forestry.api.recipes.ICarpenterRecipe;
import forestry.core.config.Config;
import forestry.core.config.Constants;
import forestry.core.config.ForestryItem;
import forestry.core.errors.EnumErrorCode;
import forestry.core.fluids.FluidHelper;
import forestry.core.fluids.Fluids;
import forestry.core.fluids.TankManager;
import forestry.core.fluids.tanks.FilteredTank;
import forestry.core.inventory.IInventoryAdapter;
@@ -53,7 +42,6 @@ import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
import forestry.core.network.GuiId;
import forestry.core.proxy.Proxies;
import forestry.core.recipes.ShapedRecipeCustom;
import forestry.core.render.TankRenderInfo;
import forestry.core.tiles.IItemStackDisplay;
import forestry.core.tiles.ILiquidTankTile;
@@ -61,6 +49,7 @@ import forestry.core.tiles.TilePowered;
import forestry.core.utils.InventoryUtil;
import forestry.core.utils.ItemStackUtil;
import forestry.core.utils.SlotUtil;
import forestry.factory.recipes.CarpenterRecipeManager;
public class TileCarpenter extends TilePowered implements ISidedInventory, ILiquidTankTile, IItemStackDisplay {
@@ -81,7 +70,7 @@ public class TileCarpenter extends TilePowered implements ISidedInventory, ILiqu
private final InventoryCraftResult craftPreviewInventory;
@Nullable
private TileCarpenter.Recipe currentRecipe;
private ICarpenterRecipe currentRecipe;
private int packageTime;
private int totalTime;
private ItemStack pendingProduct;
@@ -93,7 +82,7 @@ public class TileCarpenter extends TilePowered implements ISidedInventory, ILiqu
public TileCarpenter() {
super(1100, 4000, 200);
setHints(Config.hints.get("carpenter"));
resourceTank = new FilteredTank(Constants.PROCESSOR_TANK_CAPACITY, RecipeManager.recipeFluids);
resourceTank = new FilteredTank(Constants.PROCESSOR_TANK_CAPACITY, CarpenterRecipeManager.recipeFluids);
craftingInventory = new TileInventoryAdapter<>(this, 10, "CraftItems");
craftPreviewInventory = new InventoryCraftResult();
@@ -145,7 +134,7 @@ public class TileCarpenter extends TilePowered implements ISidedInventory, ILiqu
}
// Reset recipe according to contents
setCurrentRecipe(RecipeManager.findMatchingRecipe(resourceTank.getFluid(), getBoxStack(), craftingInventory, worldObj));
setCurrentRecipe(CarpenterRecipeManager.findMatchingRecipe(resourceTank.getFluid(), getBoxStack(), craftingInventory, worldObj));
}
@Override
@@ -164,16 +153,16 @@ public class TileCarpenter extends TilePowered implements ISidedInventory, ILiqu
if (worldObj.isRemote) {
return;
}
setCurrentRecipe(RecipeManager.findMatchingRecipe(resourceTank.getFluid(), getBoxStack(), craftingInventory, getWorldObj()));
setCurrentRecipe(CarpenterRecipeManager.findMatchingRecipe(resourceTank.getFluid(), getBoxStack(), craftingInventory, getWorldObj()));
}
private void setCurrentRecipe(@Nullable TileCarpenter.Recipe currentRecipe) {
private void setCurrentRecipe(@Nullable ICarpenterRecipe currentRecipe) {
this.currentRecipe = currentRecipe;
final ItemStack craftingResult;
if (currentRecipe != null) {
craftingResult = currentRecipe.getCraftingResult();
craftingResult = currentRecipe.getCraftingGridRecipe().getRecipeOutput();
} else {
craftingResult = null;
}
@@ -199,7 +188,7 @@ public class TileCarpenter extends TilePowered implements ISidedInventory, ILiqu
}
if (currentRecipe == null) {
Recipe recipe = TileCarpenter.RecipeManager.findMatchingRecipe(resourceTank.getFluid(), getBoxStack(), craftingInventory, worldObj);
ICarpenterRecipe recipe = CarpenterRecipeManager.findMatchingRecipe(resourceTank.getFluid(), getBoxStack(), craftingInventory, worldObj);
if (recipe != null) {
setCurrentRecipe(recipe);
}
@@ -224,7 +213,7 @@ public class TileCarpenter extends TilePowered implements ISidedInventory, ILiqu
if (packageTime <= 0) {
pendingProduct = currentRecipe.getCraftingResult();
pendingProduct = currentRecipe.getCraftingGridRecipe().getRecipeOutput();
totalTime = 0;
// Remove resources
@@ -247,7 +236,7 @@ public class TileCarpenter extends TilePowered implements ISidedInventory, ILiqu
}
// Enough items available, start the process
packageTime = totalTime = currentRecipe.packagingTime;
packageTime = totalTime = currentRecipe.getPackagingTime();
// Update product display
resetRecipe();
@@ -264,15 +253,16 @@ public class TileCarpenter extends TilePowered implements ISidedInventory, ILiqu
return true;
}
// Check whether liquid is needed and if there is enough available
if (currentRecipe.liquid != null) {
if (resourceTank.getFluidAmount() < currentRecipe.liquid.amount) {
FluidStack fluid = currentRecipe.getFluidResource();
if (fluid != null) {
if (resourceTank.getFluidAmount() < fluid.amount) {
return false;
}
}
IInventoryAdapter accessibleInventory = getInternalInventory();
// Check whether boxes are available
if (currentRecipe.box != null) {
if (currentRecipe.getBox() != null) {
if (accessibleInventory.getStackInSlot(SLOT_BOX) == null) {
return false;
}
@@ -285,19 +275,20 @@ public class TileCarpenter extends TilePowered implements ISidedInventory, ILiqu
return ItemStackUtil.containsSets(set, stock, true, false) > 0;
}
private boolean removeResources(Recipe recipe) {
private boolean removeResources(ICarpenterRecipe recipe) {
// Remove resources
if (recipe.liquid != null) {
FluidStack amountDrained = resourceTank.drain(recipe.liquid.amount, false);
if (amountDrained != null && amountDrained.amount == recipe.liquid.amount) {
resourceTank.drain(recipe.liquid.amount, true);
FluidStack fluid = recipe.getFluidResource();
if (fluid != null) {
FluidStack amountDrained = resourceTank.drain(fluid.amount, false);
if (amountDrained != null && amountDrained.amount == fluid.amount) {
resourceTank.drain(fluid.amount, true);
} else {
return false;
}
}
// Remove boxes
if (recipe.box != null) {
if (recipe.getBox() != null) {
ItemStack removed = getInternalInventory().decrStackSize(SLOT_BOX, 1);
if (removed == null || removed.stackSize == 0) {
return false;
@@ -335,7 +326,7 @@ public class TileCarpenter extends TilePowered implements ISidedInventory, ILiqu
// Stop working if the output slot cannot take more
ItemStack product = getStackInSlot(SLOT_PRODUCT);
if (product != null && product.getMaxStackSize() - product.stackSize < currentRecipe.getCraftingResult().stackSize) {
if (product != null && product.getMaxStackSize() - product.stackSize < currentRecipe.getCraftingGridRecipe().getRecipeOutput().stackSize) {
return false;
}
@@ -443,7 +434,7 @@ public class TileCarpenter extends TilePowered implements ISidedInventory, ILiqu
Fluid fluid = FluidHelper.getFluidInContainer(itemStack);
return tile.tankManager.accepts(fluid);
} else if (slotIndex == SLOT_BOX) {
return RecipeManager.isBox(itemStack);
return CarpenterRecipeManager.isBox(itemStack);
} else if (canSlotAccept(SLOT_CAN_INPUT, itemStack) || canSlotAccept(SLOT_BOX, itemStack)) {
return false;
}
@@ -457,137 +448,4 @@ public class TileCarpenter extends TilePowered implements ISidedInventory, ILiqu
}
}
/* RECIPE MANAGMENT */
public static class Recipe {
private final int packagingTime;
private final FluidStack liquid;
private final ItemStack box;
private final ShapedRecipeCustom internal;
public Recipe(int packagingTime, FluidStack liquid, ItemStack box, ShapedRecipeCustom internal) {
this.packagingTime = packagingTime;
this.liquid = liquid;
this.box = box;
this.internal = internal;
}
public ItemStack getCraftingResult() {
return internal.getRecipeOutput();
}
public boolean matches(FluidStack resource, ItemStack item, IInventory inventorycrafting, World world) {
if (liquid != null) {
if (resource == null || !resource.containsFluid(liquid)) {
return false;
}
}
// Check box
if (box != null && !ItemStackUtil.isCraftingEquivalent(box, item)) {
return false;
}
return internal.matches(inventorycrafting, world);
}
public ItemStack getBox() {
return box;
}
public FluidStack getLiquid() {
return liquid;
}
public IRecipe asIRecipe() {
return internal;
}
}
public static class RecipeManager implements ICarpenterManager {
public static final ArrayList<TileCarpenter.Recipe> recipes = new ArrayList<>();
private static final Set<Fluid> recipeFluids = new HashSet<>();
private static final List<ItemStack> boxes = new ArrayList<>();
public void addCrating(ItemStack itemStack) {
ItemStack uncrated = ((forestry.core.items.ItemCrated) itemStack.getItem()).getContained();
addRecipe(Constants.CARPENTER_CRATING_CYCLES, Fluids.WATER.getFluid(Constants.CARPENTER_CRATING_LIQUID_QUANTITY),
ForestryItem.crate.getItemStack(), itemStack, new Object[]{"###", "###", "###", '#', uncrated});
addRecipe(null, new ItemStack(uncrated.getItem(), 9, uncrated.getItemDamage()), new Object[]{"#", '#', itemStack});
}
public void addCratingWithOreDict(ItemStack itemStack) {
ItemStack uncrated = ((forestry.core.items.ItemCrated) itemStack.getItem()).getContained();
int[] oreIds = OreDictionary.getOreIDs(uncrated);
for (int oreId : oreIds) {
String oreName = OreDictionary.getOreName(oreId);
addCrating(oreName, uncrated, itemStack);
}
}
public void addCrating(String toCrate, ItemStack unpack, ItemStack crated) {
addRecipe(Constants.CARPENTER_CRATING_CYCLES, Fluids.WATER.getFluid(Constants.CARPENTER_CRATING_LIQUID_QUANTITY),
ForestryItem.crate.getItemStack(), crated, new Object[]{"###", "###", "###", '#', toCrate});
addRecipe(null, new ItemStack(unpack.getItem(), 9, unpack.getItemDamage()), new Object[]{"#", '#', crated});
}
@Override
public void addRecipe(ItemStack box, ItemStack product, Object materials[]) {
addRecipe(5, null, box, product, materials);
}
@Override
public void addRecipe(int packagingTime, ItemStack box, ItemStack product, Object materials[]) {
addRecipe(packagingTime, null, box, product, materials);
}
@Override
public void addRecipe(int packagingTime, FluidStack liquid, ItemStack box, ItemStack product, Object materials[]) {
recipes.add(new Recipe(packagingTime, liquid, box, ShapedRecipeCustom.createShapedRecipe(product, materials)));
if (liquid != null) {
recipeFluids.add(liquid.getFluid());
}
if (box != null && !isBox(box)) {
boxes.add(box);
}
}
public static Recipe findMatchingRecipe(FluidStack liquid, ItemStack item, IInventory inventorycrafting, World world) {
for (Recipe recipe : recipes) {
if (recipe.matches(liquid, item, inventorycrafting, world)) {
return recipe;
}
}
return null;
}
public static boolean isBox(ItemStack resource) {
if (resource == null) {
return false;
}
for (ItemStack box : boxes) {
if (ItemStackUtil.isIdenticalItem(box, resource)) {
return true;
}
}
return false;
}
@Override
public Map<Object[], Object[]> getRecipes() {
HashMap<Object[], Object[]> recipeList = new HashMap<>();
for (Recipe recipe : recipes) {
recipeList.put(recipe.internal.getIngredients(), new Object[]{recipe.getCraftingResult()});
}
return recipeList;
}
}
}
@@ -10,17 +10,9 @@
******************************************************************************/
package forestry.factory.tiles;
import com.google.common.collect.ImmutableMap;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.Stack;
import net.minecraft.entity.player.EntityPlayer;
@@ -40,7 +32,6 @@ import forestry.api.circuits.ICircuitBoard;
import forestry.api.circuits.ICircuitSocketType;
import forestry.api.core.ForestryAPI;
import forestry.api.core.IErrorLogic;
import forestry.api.recipes.ICentrifugeManager;
import forestry.api.recipes.ICentrifugeRecipe;
import forestry.core.circuits.ISocketable;
import forestry.core.config.Config;
@@ -54,8 +45,8 @@ import forestry.core.network.DataOutputStreamForestry;
import forestry.core.network.GuiId;
import forestry.core.tiles.TilePowered;
import forestry.core.utils.InventoryUtil;
import forestry.core.utils.ItemStackUtil;
import forestry.core.utils.SlotUtil;
import forestry.factory.recipes.CentrifugeRecipeManager;
import forestry.factory.triggers.FactoryTriggers;
import buildcraft.api.statements.ITriggerExternal;
@@ -168,7 +159,7 @@ public class TileCentrifuge extends TilePowered implements ISocketable, ISidedIn
private void checkRecipe() {
ItemStack resource = getStackInSlot(SLOT_RESOURCE);
ICentrifugeRecipe matchingRecipe = RecipeManager.findMatchingRecipe(resource);
ICentrifugeRecipe matchingRecipe = CentrifugeRecipeManager.findMatchingRecipe(resource);
if (currentRecipe != matchingRecipe) {
currentRecipe = matchingRecipe;
@@ -236,7 +227,7 @@ public class TileCentrifuge extends TilePowered implements ISocketable, ISidedIn
@Override
public boolean canSlotAccept(int slotIndex, ItemStack itemStack) {
return slotIndex == SLOT_RESOURCE && RecipeManager.findMatchingRecipe(itemStack) != null;
return slotIndex == SLOT_RESOURCE && CentrifugeRecipeManager.findMatchingRecipe(itemStack) != null;
}
@Override
@@ -289,98 +280,4 @@ public class TileCentrifuge extends TilePowered implements ISocketable, ISidedIn
return CircuitSocketType.MACHINE;
}
/* RECIPE MANAGEMENT */
public static class CentrifugeRecipe implements ICentrifugeRecipe {
private final int processingTime;
private final ItemStack input;
private final Map<ItemStack, Float> outputs;
public CentrifugeRecipe(int processingTime, ItemStack input, Map<ItemStack, Float> outputs) {
this.processingTime = processingTime;
this.input = input;
this.outputs = outputs;
for (ItemStack item : outputs.keySet()) {
if (item == null) {
throw new IllegalArgumentException("Tried to register a null product of " + input);
}
}
}
@Override
public ItemStack getInput() {
return input;
}
@Override
public int getProcessingTime() {
return processingTime;
}
@Override
public Collection<ItemStack> getProducts(Random random) {
List<ItemStack> products = new ArrayList<>();
for (Map.Entry<ItemStack, Float> entry : this.outputs.entrySet()) {
float probability = entry.getValue();
if (probability >= 1.0) {
products.add(entry.getKey().copy());
} else if (random.nextFloat() < probability) {
products.add(entry.getKey().copy());
}
}
return products;
}
@Override
public Map<ItemStack, Float> getAllProducts() {
return ImmutableMap.copyOf(outputs);
}
}
public static class RecipeManager implements ICentrifugeManager {
public static final List<ICentrifugeRecipe> recipes = new ArrayList<>();
@Override
public void addRecipe(ICentrifugeRecipe recipe) {
recipes.add(recipe);
}
@Override
public void addRecipe(int timePerItem, ItemStack resource, Map<ItemStack, Float> products) {
ICentrifugeRecipe recipe = new CentrifugeRecipe(timePerItem, resource, products);
addRecipe(recipe);
}
public static ICentrifugeRecipe findMatchingRecipe(ItemStack itemStack) {
if (itemStack == null) {
return null;
}
for (ICentrifugeRecipe recipe : recipes) {
ItemStack recipeInput = recipe.getInput();
if (ItemStackUtil.isCraftingEquivalent(recipeInput, itemStack)) {
return recipe;
}
}
return null;
}
@Override
public Map<Object[], Object[]> getRecipes() {
HashMap<Object[], Object[]> recipeList = new HashMap<>();
for (ICentrifugeRecipe recipe : recipes) {
Set<ItemStack> productsKeys = recipe.getAllProducts().keySet();
recipeList.put(new Object[]{recipe.getInput()}, productsKeys.toArray(new ItemStack[productsKeys.size()]));
}
return recipeList;
}
}
}
@@ -11,10 +11,6 @@
package forestry.factory.tiles;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
@@ -31,7 +27,6 @@ import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import forestry.api.core.ForestryAPI;
import forestry.api.recipes.IFabricatorManager;
import forestry.api.recipes.IFabricatorRecipe;
import forestry.core.config.Constants;
import forestry.core.fluids.Fluids;
@@ -45,14 +40,14 @@ import forestry.core.items.ICraftingPlan;
import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
import forestry.core.network.GuiId;
import forestry.core.recipes.ShapedRecipeCustom;
import forestry.core.tiles.ICrafter;
import forestry.core.tiles.ILiquidTankTile;
import forestry.core.tiles.TilePowered;
import forestry.core.utils.InventoryUtil;
import forestry.core.utils.ItemStackUtil;
import forestry.core.utils.SlotUtil;
import forestry.factory.recipes.FabricatorRecipe;
import forestry.factory.recipes.FabricatorRecipeManager;
import forestry.factory.recipes.FabricatorSmeltingRecipe;
public class TileFabricator extends TilePowered implements ICrafter, ILiquidTankTile, ISidedInventory {
@@ -155,8 +150,8 @@ public class TileFabricator extends TilePowered implements ICrafter, ILiquidTank
if (!moltenTank.isEmpty()) {
// Remove smelt if we have gone below melting point
Smelting smelt = RecipeManager.findMatchingSmelting(moltenTank.getFluid());
if (smelt != null && heat < smelt.meltingPoint) {
FabricatorSmeltingRecipe smelt = FabricatorRecipeManager.findMatchingSmelting(moltenTank.getFluid());
if (smelt != null && heat < smelt.getMeltingPoint()) {
moltenTank.drain(5, true);
}
}
@@ -172,8 +167,8 @@ public class TileFabricator extends TilePowered implements ICrafter, ILiquidTank
return;
}
Smelting smelt = RecipeManager.findMatchingSmelting(smeltResource);
if (smelt == null || smelt.meltingPoint > heat) {
FabricatorSmeltingRecipe smelt = FabricatorRecipeManager.findMatchingSmelting(smeltResource);
if (smelt == null || smelt.getMeltingPoint() > heat) {
return;
}
@@ -215,7 +210,7 @@ public class TileFabricator extends TilePowered implements ICrafter, ILiquidTank
IInventoryAdapter inventory = getInternalInventory();
ItemStack plan = inventory.getStackInSlot(SLOT_PLAN);
ItemStack[] crafting = InventoryUtil.getStacks(craftingInventory, SLOT_CRAFTING_1, SLOT_CRAFTING_COUNT);
return RecipeManager.findMatchingRecipe(plan, moltenTank.getFluid(), crafting);
return FabricatorRecipeManager.findMatchingRecipe(plan, moltenTank.getFluid(), crafting);
}
/* ICRAFTER */
@@ -302,7 +297,7 @@ public class TileFabricator extends TilePowered implements ICrafter, ILiquidTank
public boolean hasWork() {
IInventoryAdapter inventory = getInternalInventory();
ItemStack itemToMelt = inventory.getStackInSlot(SLOT_METAL);
Smelting smelting = RecipeManager.findMatchingSmelting(itemToMelt);
FabricatorSmeltingRecipe smelting = FabricatorRecipeManager.findMatchingSmelting(itemToMelt);
if (smelting != null && moltenTank.fill(smelting.getProduct(), false) > 0) {
return true;
}
@@ -310,7 +305,7 @@ public class TileFabricator extends TilePowered implements ICrafter, ILiquidTank
ItemStack plan = inventory.getStackInSlot(SLOT_PLAN);
ItemStack[] resources = InventoryUtil.getStacks(craftingInventory, SLOT_CRAFTING_1, SLOT_CRAFTING_COUNT);
return RecipeManager.findMatchingRecipe(plan, moltenTank.getFluid(), resources) != null;
return FabricatorRecipeManager.findMatchingRecipe(plan, moltenTank.getFluid(), resources) != null;
}
public int getHeatScaled(int i) {
@@ -319,14 +314,14 @@ public class TileFabricator extends TilePowered implements ICrafter, ILiquidTank
private int getMeltingPoint() {
if (moltenTank.getFluidAmount() > 0) {
Smelting smelt = RecipeManager.findMatchingSmelting(moltenTank.getFluid());
FabricatorSmeltingRecipe smelt = FabricatorRecipeManager.findMatchingSmelting(moltenTank.getFluid());
if (smelt != null) {
return smelt.meltingPoint;
return smelt.getMeltingPoint();
}
} else if (this.getStackInSlot(SLOT_METAL) != null) {
Smelting smelt = RecipeManager.findMatchingSmelting(this.getStackInSlot(SLOT_METAL));
FabricatorSmeltingRecipe smelt = FabricatorRecipeManager.findMatchingSmelting(this.getStackInSlot(SLOT_METAL));
if (smelt != null) {
return smelt.meltingPoint;
return smelt.getMeltingPoint();
}
}
@@ -418,13 +413,13 @@ public class TileFabricator extends TilePowered implements ICrafter, ILiquidTank
@Override
public boolean canSlotAccept(int slotIndex, ItemStack itemStack) {
if (slotIndex == SLOT_METAL) {
return RecipeManager.findMatchingSmelting(itemStack) != null;
return FabricatorRecipeManager.findMatchingSmelting(itemStack) != null;
} else if (slotIndex == SLOT_PLAN) {
return RecipeManager.isPlan(itemStack);
return FabricatorRecipeManager.isPlan(itemStack);
} else if (SlotUtil.isSlotInRange(slotIndex, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT)) {
if (RecipeManager.isPlan(itemStack)) {
if (FabricatorRecipeManager.isPlan(itemStack)) {
return false;
} else if (RecipeManager.findMatchingSmelting(itemStack) != null) {
} else if (FabricatorRecipeManager.findMatchingSmelting(itemStack) != null) {
return false;
}
}
@@ -437,132 +432,4 @@ public class TileFabricator extends TilePowered implements ICrafter, ILiquidTank
}
}
public static class Smelting {
private final ItemStack resource;
private final FluidStack product;
private final int meltingPoint;
public Smelting(ItemStack resource, FluidStack molten, int meltingPoint) {
if (resource == null) {
throw new IllegalArgumentException("Resource cannot be null");
}
if (molten == null) {
throw new IllegalArgumentException("Molten cannot be null");
}
this.resource = resource;
this.product = molten;
this.meltingPoint = meltingPoint;
}
public boolean matches(FluidStack product) {
return this.product.isFluidEqual(product);
}
public ItemStack getResource() {
return resource;
}
public FluidStack getProduct() {
return product;
}
public int getMeltingPoint() {
return meltingPoint;
}
}
public static class RecipeManager implements IFabricatorManager {
public static final List<IFabricatorRecipe> recipes = new ArrayList<>();
public static final List<Smelting> smeltings = new ArrayList<>();
@Override
public void addRecipe(IFabricatorRecipe recipe) {
recipes.add(recipe);
}
@Override
public void addRecipe(ItemStack plan, FluidStack molten, ItemStack result, Object[] pattern) {
IFabricatorRecipe recipe = new FabricatorRecipe(plan, molten, ShapedRecipeCustom.createShapedRecipe(result, pattern));
addRecipe(recipe);
}
@Override
public void addSmelting(ItemStack resource, FluidStack molten, int meltingPoint) {
if (resource == null || molten == null) {
return;
}
smeltings.add(new Smelting(resource, molten, meltingPoint));
}
public static IFabricatorRecipe findMatchingRecipe(ItemStack plan, FluidStack liquid, ItemStack[] resources) {
ItemStack[][] gridResources = new ItemStack[3][3];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
gridResources[j][i] = resources[i * 3 + j];
}
}
for (IFabricatorRecipe recipe : recipes) {
if (recipe.matches(plan, gridResources)) {
if (liquid == null || liquid.containsFluid(recipe.getLiquid())) {
return recipe;
}
}
}
return null;
}
public static boolean isPlan(ItemStack plan) {
for (IFabricatorRecipe recipe : recipes) {
if (ItemStackUtil.isIdenticalItem(recipe.getPlan(), plan)) {
return true;
}
}
return false;
}
public static Smelting findMatchingSmelting(ItemStack resource) {
if (resource == null) {
return null;
}
for (Smelting smelting : smeltings) {
if (ItemStackUtil.isCraftingEquivalent(smelting.resource, resource)) {
return smelting;
}
}
return null;
}
public static Smelting findMatchingSmelting(FluidStack product) {
if (product == null) {
return null;
}
for (Smelting smelting : smeltings) {
if (smelting.matches(product)) {
return smelting;
}
}
return null;
}
@Override
public Map<Object[], Object[]> getRecipes() {
HashMap<Object[], Object[]> recipeList = new HashMap<>();
for (IFabricatorRecipe recipe : recipes) {
recipeList.put(recipe.getIngredients(), new Object[]{recipe.getRecipeOutput()});
}
return recipeList;
}
}
}
@@ -11,12 +11,8 @@
package forestry.factory.tiles;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
@@ -36,13 +32,12 @@ import cpw.mods.fml.common.Optional;
import forestry.api.core.ForestryAPI;
import forestry.api.core.IErrorLogic;
import forestry.api.fuels.FuelManager;
import forestry.api.recipes.IFermenterManager;
import forestry.api.recipes.IFermenterRecipe;
import forestry.api.recipes.IVariableFermentable;
import forestry.core.config.Config;
import forestry.core.config.Constants;
import forestry.core.errors.EnumErrorCode;
import forestry.core.fluids.FluidHelper;
import forestry.core.fluids.Fluids;
import forestry.core.fluids.TankManager;
import forestry.core.fluids.tanks.FilteredTank;
import forestry.core.fluids.tanks.StandardTank;
@@ -54,7 +49,7 @@ import forestry.core.network.GuiId;
import forestry.core.render.TankRenderInfo;
import forestry.core.tiles.ILiquidTankTile;
import forestry.core.tiles.TilePowered;
import forestry.core.utils.ItemStackUtil;
import forestry.factory.recipes.FermenterRecipeManager;
import forestry.factory.triggers.FactoryTriggers;
import buildcraft.api.statements.ITriggerExternal;
@@ -68,111 +63,12 @@ public class TileFermenter extends TilePowered implements ISidedInventory, ILiqu
public static final short SLOT_CAN_INPUT = 3;
public static final short SLOT_INPUT = 4;
// / RECIPE MANAGMENT
public static class Recipe {
public final ItemStack resource;
public final int fermentationValue;
public final float modifier;
public final FluidStack output;
public final FluidStack liquid;
public Recipe(ItemStack resource, int fermentationValue, float modifier, FluidStack output, FluidStack liquid) {
this.resource = resource;
this.fermentationValue = fermentationValue;
this.modifier = modifier;
this.output = output;
this.liquid = liquid;
if (resource == null) {
throw new NullPointerException("Fermenter Resource cannot be null!");
}
if (output == null) {
throw new NullPointerException("Fermenter Output cannot be null!");
}
if (liquid == null) {
throw new NullPointerException("Fermenter Liquid cannot be null!");
}
}
public boolean matches(ItemStack res, FluidStack liqu) {
if (!ItemStackUtil.isCraftingEquivalent(resource, res)) {
return false;
}
return liqu != null && liqu.containsFluid(liquid);
}
}
public static class RecipeManager implements IFermenterManager {
public static final ArrayList<TileFermenter.Recipe> recipes = new ArrayList<>();
public static final HashSet<Fluid> recipeFluidInputs = new HashSet<>();
public static final HashSet<Fluid> recipeFluidOutputs = new HashSet<>();
@Override
public void addRecipe(ItemStack resource, int fermentationValue, float modifier, FluidStack output, FluidStack liquid) {
// assume that fermenter recipes want to use Forestry's honey and not the legacy "fluid.honey"
if (Fluids.LEGACY_HONEY.is(liquid)) {
liquid = Fluids.HONEY.getFluid(liquid.amount);
}
recipes.add(new Recipe(resource, fermentationValue, modifier, output, liquid));
if (liquid != null) {
recipeFluidInputs.add(liquid.getFluid());
}
if (output != null) {
recipeFluidOutputs.add(output.getFluid());
}
}
@Override
public void addRecipe(ItemStack resource, int fermentationValue, float modifier, FluidStack output) {
addRecipe(resource, fermentationValue, modifier, output, Fluids.WATER.getFluid(1000));
}
public static Recipe findMatchingRecipe(ItemStack res, FluidStack liqu) {
for (Recipe recipe : recipes) {
if (recipe.matches(res, liqu)) {
return recipe;
}
}
return null;
}
public static boolean isResource(ItemStack resource) {
if (resource == null) {
return false;
}
for (Recipe recipe : recipes) {
if (ItemStackUtil.isCraftingEquivalent(recipe.resource, resource)) {
return true;
}
}
return false;
}
@Override
public Map<Object[], Object[]> getRecipes() {
HashMap<Object[], Object[]> recipeList = new HashMap<>();
for (Recipe recipe : recipes) {
recipeList.put(new Object[]{recipe.resource, recipe.liquid}, new Object[]{recipe.output});
}
return recipeList;
}
}
private final FilteredTank resourceTank;
private final FilteredTank productTank;
private final TankManager tankManager;
private Recipe currentRecipe;
private IFermenterRecipe currentRecipe;
private float currentResourceModifier;
private int fermentationTime = 0;
private int fermentationTotalTime = 0;
@@ -184,9 +80,9 @@ public class TileFermenter extends TilePowered implements ISidedInventory, ILiqu
super(2000, 8000, 600);
setInternalInventory(new FermenterInventoryAdapter(this));
setHints(Config.hints.get("fermenter"));
resourceTank = new FilteredTank(Constants.PROCESSOR_TANK_CAPACITY, RecipeManager.recipeFluidInputs);
resourceTank = new FilteredTank(Constants.PROCESSOR_TANK_CAPACITY, FermenterRecipeManager.recipeFluidInputs);
resourceTank.tankMode = StandardTank.TankMode.INPUT;
productTank = new FilteredTank(Constants.PROCESSOR_TANK_CAPACITY, RecipeManager.recipeFluidOutputs);
productTank = new FilteredTank(Constants.PROCESSOR_TANK_CAPACITY, FermenterRecipeManager.recipeFluidOutputs);
productTank.tankMode = StandardTank.TankMode.OUTPUT;
tankManager = new TankManager(resourceTank, productTank);
}
@@ -259,7 +155,7 @@ public class TileFermenter extends TilePowered implements ISidedInventory, ILiqu
IErrorLogic errorLogic = getErrorLogic();
boolean hasRecipe = RecipeManager.findMatchingRecipe(inventory.getStackInSlot(SLOT_RESOURCE), resourceTank.getFluid()) != null;
boolean hasRecipe = FermenterRecipeManager.findMatchingRecipe(inventory.getStackInSlot(SLOT_RESOURCE), resourceTank.getFluid()) != null;
errorLogic.setCondition(!hasRecipe, EnumErrorCode.NORECIPE);
boolean hasResource = resourceTank.getFluidAmount() >= fuelCurrentFerment;
@@ -299,8 +195,8 @@ public class TileFermenter extends TilePowered implements ISidedInventory, ILiqu
int fermented = Math.min(fermentationTime, this.fuelCurrentFerment);
// input are checked, add output if possible
if (!addProduct(new FluidStack(currentRecipe.output,
Math.round(fermented * currentRecipe.modifier * currentResourceModifier)))) {
if (!addProduct(new FluidStack(currentRecipe.getOutput(),
Math.round(fermented * currentRecipe.getModifier() * currentResourceModifier)))) {
return false; // the output tank is too full, TODO: check/add error code?
}
@@ -345,7 +241,7 @@ public class TileFermenter extends TilePowered implements ISidedInventory, ILiqu
private void checkRecipe() {
IInventoryAdapter inventory = getInternalInventory();
Recipe sameRec = RecipeManager.findMatchingRecipe(inventory.getStackInSlot(SLOT_RESOURCE), resourceTank.getFluid());
IFermenterRecipe sameRec = FermenterRecipeManager.findMatchingRecipe(inventory.getStackInSlot(SLOT_RESOURCE), resourceTank.getFluid());
if (currentRecipe != sameRec) {
currentRecipe = sameRec;
@@ -359,8 +255,8 @@ public class TileFermenter extends TilePowered implements ISidedInventory, ILiqu
return;
}
fermentationTime = currentRecipe.fermentationValue;
fermentationTotalTime = currentRecipe.fermentationValue;
fermentationTime = currentRecipe.getFermentationValue();
fermentationTotalTime = currentRecipe.getFermentationValue();
}
/**
@@ -419,7 +315,7 @@ public class TileFermenter extends TilePowered implements ISidedInventory, ILiqu
@Override
public boolean hasWork() {
if (currentRecipe == null && RecipeManager.findMatchingRecipe(getStackInSlot(SLOT_RESOURCE), resourceTank.getFluid()) == null) {
if (currentRecipe == null && FermenterRecipeManager.findMatchingRecipe(getStackInSlot(SLOT_RESOURCE), resourceTank.getFluid()) == null) {
return false;
}
@@ -560,7 +456,7 @@ public class TileFermenter extends TilePowered implements ISidedInventory, ILiqu
@Override
public boolean canSlotAccept(int slotIndex, ItemStack itemStack) {
if (slotIndex == SLOT_RESOURCE) {
return RecipeManager.isResource(itemStack);
return FermenterRecipeManager.isResource(itemStack);
} else if (slotIndex == SLOT_INPUT) {
Fluid fluid = FluidHelper.getFluidInContainer(itemStack);
return tile.resourceTank.accepts(fluid);
@@ -12,8 +12,6 @@ package forestry.factory.tiles;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
@@ -32,7 +30,7 @@ import forestry.api.core.ForestryAPI;
import forestry.api.core.IErrorLogic;
import forestry.api.fuels.FuelManager;
import forestry.api.fuels.MoistenerFuel;
import forestry.api.recipes.IMoistenerManager;
import forestry.api.recipes.IMoistenerRecipe;
import forestry.core.config.Config;
import forestry.core.config.Constants;
import forestry.core.errors.EnumErrorCode;
@@ -51,6 +49,7 @@ import forestry.core.tiles.TileBase;
import forestry.core.utils.InventoryUtil;
import forestry.core.utils.ItemStackUtil;
import forestry.core.utils.SlotUtil;
import forestry.factory.recipes.MoistenerRecipeManager;
public class TileMoistener extends TileBase implements ISidedInventory, ILiquidTankTile, IRenderableTile {
@@ -63,71 +62,9 @@ public class TileMoistener extends TileBase implements ISidedInventory, ILiquidT
private static final short SLOT_PRODUCT = 10;
private static final short SLOT_RESOURCE = 11;
/* RECIPE MANAGMENT */
public static class Recipe {
public final int timePerItem;
public final ItemStack resource;
public final ItemStack product;
public Recipe(ItemStack resource, ItemStack product, int timePerItem) {
this.timePerItem = timePerItem;
this.resource = resource;
this.product = product;
}
public boolean matches(ItemStack res) {
return ItemStackUtil.isCraftingEquivalent(resource, res);
}
}
public static class RecipeManager implements IMoistenerManager {
public static final ArrayList<TileMoistener.Recipe> recipes = new ArrayList<>();
@Override
public void addRecipe(ItemStack resource, ItemStack product, int timePerItem) {
recipes.add(new TileMoistener.Recipe(resource, product, timePerItem));
}
public static boolean isResource(ItemStack resource) {
if (resource == null) {
return false;
}
for (Recipe rec : recipes) {
if (ItemStackUtil.isIdenticalItem(resource, rec.resource)) {
return true;
}
}
return false;
}
public static Recipe findMatchingRecipe(ItemStack item) {
for (Recipe recipe : recipes) {
if (recipe.matches(item)) {
return recipe;
}
}
return null;
}
@Override
public Map<Object[], Object[]> getRecipes() {
HashMap<Object[], Object[]> recipeList = new HashMap<>();
for (Recipe recipe : recipes) {
recipeList.put(new ItemStack[]{recipe.resource}, new ItemStack[]{recipe.product});
}
return recipeList;
}
}
private final FilteredTank resourceTank;
private final TankManager tankManager;
private TileMoistener.Recipe currentRecipe;
private IMoistenerRecipe currentRecipe;
private int burnTime = 0;
private int totalTime = 0;
@@ -305,7 +242,7 @@ public class TileMoistener extends TileBase implements ISidedInventory, ILiquidT
}
public void checkRecipe() {
Recipe sameRec = RecipeManager.findMatchingRecipe(getInternalInventory().getStackInSlot(SLOT_RESOURCE));
IMoistenerRecipe sameRec = MoistenerRecipeManager.findMatchingRecipe(getInternalInventory().getStackInSlot(SLOT_RESOURCE));
if (currentRecipe != sameRec) {
currentRecipe = sameRec;
resetRecipe();
@@ -320,9 +257,9 @@ public class TileMoistener extends TileBase implements ISidedInventory, ILiquidT
productionTime = 0;
timePerItem = 0;
} else {
currentProduct = currentRecipe.product;
productionTime = currentRecipe.timePerItem;
timePerItem = currentRecipe.timePerItem;
currentProduct = currentRecipe.getProduct();
productionTime = currentRecipe.getTimePerItem();
timePerItem = currentRecipe.getTimePerItem();
}
}
@@ -632,7 +569,7 @@ public class TileMoistener extends TileBase implements ISidedInventory, ILiquidT
@Override
public boolean canSlotAccept(int slotIndex, ItemStack itemStack) {
if (slotIndex == SLOT_RESOURCE) {
return RecipeManager.isResource(itemStack);
return MoistenerRecipeManager.isResource(itemStack);
}
if (SlotUtil.isSlotInRange(slotIndex, SLOT_STASH_1, SLOT_STASH_COUNT)) {
@@ -660,4 +597,5 @@ public class TileMoistener extends TileBase implements ISidedInventory, ILiquidT
return false;
}
}
}
@@ -10,15 +10,7 @@
******************************************************************************/
package forestry.factory.tiles;
import javax.annotation.Nullable;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
@@ -38,7 +30,7 @@ import forestry.api.circuits.ICircuitBoard;
import forestry.api.circuits.ICircuitSocketType;
import forestry.api.core.ForestryAPI;
import forestry.api.core.IErrorLogic;
import forestry.api.recipes.ISqueezerManager;
import forestry.api.recipes.ISqueezerRecipe;
import forestry.core.circuits.ISocketable;
import forestry.core.circuits.ISpeedUpgradable;
import forestry.core.config.Config;
@@ -58,11 +50,7 @@ import forestry.core.tiles.ILiquidTankTile;
import forestry.core.tiles.TilePowered;
import forestry.core.utils.InventoryUtil;
import forestry.core.utils.ItemStackUtil;
import forestry.core.utils.datastructures.ItemStackMap;
import forestry.factory.recipes.ISqueezerContainerRecipe;
import forestry.factory.recipes.ISqueezerRecipe;
import forestry.factory.recipes.SqueezerContainerRecipe;
import forestry.factory.recipes.SqueezerRecipe;
import forestry.factory.recipes.SqueezerRecipeManager;
public class TileSqueezer extends TilePowered implements ISocketable, ISidedInventory, ILiquidTankTile, ISpeedUpgradable {
@@ -176,7 +164,7 @@ public class TileSqueezer extends TilePowered implements ISocketable, ISidedInve
if (currentRecipe != null && ItemStackUtil.containsSets(currentRecipe.getResources(), resources, true, false) > 0) {
matchingRecipe = currentRecipe;
} else {
matchingRecipe = RecipeManager.findMatchingRecipe(resources);
matchingRecipe = SqueezerRecipeManager.findMatchingRecipe(resources);
}
}
@@ -345,7 +333,7 @@ public class TileSqueezer extends TilePowered implements ISocketable, ISidedInve
return false;
}
if (RecipeManager.canUse(itemStack)) {
if (SqueezerRecipeManager.canUse(itemStack)) {
return true;
}
}
@@ -382,87 +370,4 @@ public class TileSqueezer extends TilePowered implements ISocketable, ISidedInve
}
}
public static class RecipeManager implements ISqueezerManager {
public static final List<ISqueezerRecipe> recipes = new ArrayList<>();
public static final Set<ItemStack> recipeInputs = new HashSet<>();
public static final ItemStackMap<ISqueezerContainerRecipe> containerRecipes = new ItemStackMap<>();
@Override
public void addRecipe(int timePerItem, ItemStack[] resources, FluidStack liquid, @Nullable ItemStack remnants, int chance) {
recipes.add(new SqueezerRecipe(timePerItem, resources, liquid, remnants, chance / 100.0f));
recipeInputs.addAll(Arrays.asList(resources));
}
@Override
public void addRecipe(int timePerItem, ItemStack[] resources, FluidStack liquid) {
addRecipe(timePerItem, resources, liquid, null, 0);
}
@Override
public void addContainerRecipe(int timePerItem, ItemStack emptyContainer, @Nullable ItemStack remnants, float chance) {
containerRecipes.put(emptyContainer, new SqueezerContainerRecipe(emptyContainer, timePerItem, remnants, chance));
}
@Nullable
public static ISqueezerContainerRecipe findMatchingContainerRecipe(ItemStack filledContainer) {
ItemStack emptyContainer = FluidHelper.getEmptyContainer(filledContainer);
if (emptyContainer == null) {
return null;
}
return containerRecipes.get(emptyContainer);
}
public static ISqueezerRecipe findMatchingRecipe(ItemStack[] items) {
// Find container recipes
for (ItemStack itemStack : items) {
ISqueezerContainerRecipe containerRecipe = findMatchingContainerRecipe(itemStack);
if (containerRecipe != null) {
ISqueezerRecipe recipe = containerRecipe.getSqueezerRecipe(itemStack);
if (recipe != null) {
return recipe;
}
}
}
// First try to match a specific recipe (without OreDictionary)
for (ISqueezerRecipe recipe : recipes) {
if (ItemStackUtil.containsSets(recipe.getResources(), items, false, false) > 0) {
return recipe;
}
}
// If that fails - try again with OreDictionary support enabled
for (ISqueezerRecipe recipe : recipes) {
if (ItemStackUtil.containsSets(recipe.getResources(), items, true, false) > 0) {
return recipe;
}
}
return null;
}
public static boolean canUse(ItemStack itemStack) {
for (ItemStack recipeInput : recipeInputs) {
if (ItemStackUtil.isCraftingEquivalent(recipeInput, itemStack, true, false)) {
return true;
}
}
return RecipeManager.findMatchingContainerRecipe(itemStack) != null;
}
@Override
public Map<Object[], Object[]> getRecipes() {
HashMap<Object[], Object[]> recipeList = new HashMap<>();
for (ISqueezerRecipe recipe : recipes) {
recipeList.put(recipe.getResources(), new Object[]{recipe.getRemnants(), recipe.getFluidOutput()});
}
return recipeList;
}
}
}
@@ -11,10 +11,6 @@
package forestry.factory.tiles;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
@@ -30,7 +26,7 @@ import net.minecraftforge.fluids.FluidTankInfo;
import forestry.api.core.ForestryAPI;
import forestry.api.core.IErrorLogic;
import forestry.api.recipes.IStillManager;
import forestry.api.recipes.IStillRecipe;
import forestry.core.config.Config;
import forestry.core.config.Constants;
import forestry.core.errors.EnumErrorCode;
@@ -46,6 +42,7 @@ import forestry.core.network.GuiId;
import forestry.core.render.TankRenderInfo;
import forestry.core.tiles.ILiquidTankTile;
import forestry.core.tiles.TilePowered;
import forestry.factory.recipes.StillRecipeManager;
public class TileStill extends TilePowered implements ISidedInventory, ILiquidTankTile {
@@ -54,77 +51,12 @@ public class TileStill extends TilePowered implements ISidedInventory, ILiquidTa
public static final short SLOT_RESOURCE = 1;
public static final short SLOT_CAN = 2;
public static class Recipe {
public final int timePerUnit;
public final FluidStack input;
public final FluidStack output;
public Recipe(int timePerUnit, FluidStack input, FluidStack output) {
this.timePerUnit = timePerUnit;
if (input == null) {
throw new IllegalArgumentException("Still recipes need an input. Input was null.");
}
if (output == null) {
throw new IllegalArgumentException("Still recipes need an output. Output was null.");
}
this.input = input;
this.output = output;
}
public boolean matches(FluidStack res) {
return res != null && res.containsFluid(input);
}
}
public static class RecipeManager implements IStillManager {
public static final ArrayList<TileStill.Recipe> recipes = new ArrayList<>();
public static final HashSet<Fluid> recipeFluidInputs = new HashSet<>();
public static final HashSet<Fluid> recipeFluidOutputs = new HashSet<>();
@Override
public void addRecipe(int timePerUnit, FluidStack input, FluidStack output) {
recipes.add(new TileStill.Recipe(timePerUnit, input, output));
if (input != null) {
recipeFluidInputs.add(input.getFluid());
}
if (output != null) {
recipeFluidOutputs.add(output.getFluid());
}
}
public static Recipe findMatchingRecipe(FluidStack item) {
for (Recipe recipe : recipes) {
if (recipe.matches(item)) {
return recipe;
}
}
return null;
}
public static boolean isInput(FluidStack res) {
return recipeFluidInputs.contains(res.getFluid());
}
@Override
public Map<Object[], Object[]> getRecipes() {
HashMap<Object[], Object[]> recipeList = new HashMap<>();
for (Recipe recipe : recipes) {
recipeList.put(new Object[]{recipe.input}, new Object[]{recipe.output});
}
return recipeList;
}
}
/* MEMBER */
private final FilteredTank resourceTank;
private final FilteredTank productTank;
private final TankManager tankManager;
private Recipe currentRecipe;
private IStillRecipe currentRecipe;
private FluidStack bufferedLiquid;
private int distillationTime = 0;
private int distillationTotalTime = 0;
@@ -133,9 +65,9 @@ public class TileStill extends TilePowered implements ISidedInventory, ILiquidTa
super(1100, 8000, 200);
setInternalInventory(new StillInventoryAdapter(this));
setHints(Config.hints.get("still"));
resourceTank = new FilteredTank(Constants.PROCESSOR_TANK_CAPACITY, RecipeManager.recipeFluidInputs);
resourceTank = new FilteredTank(Constants.PROCESSOR_TANK_CAPACITY, StillRecipeManager.recipeFluidInputs);
resourceTank.tankMode = StandardTank.TankMode.INPUT;
productTank = new FilteredTank(Constants.PROCESSOR_TANK_CAPACITY, RecipeManager.recipeFluidOutputs);
productTank = new FilteredTank(Constants.PROCESSOR_TANK_CAPACITY, StillRecipeManager.recipeFluidOutputs);
productTank.tankMode = StandardTank.TankMode.OUTPUT;
tankManager = new TankManager(resourceTank, productTank);
}
@@ -214,16 +146,16 @@ public class TileStill extends TilePowered implements ISidedInventory, ILiquidTa
// Ongoing process
if (distillationTime > 0 && !errorLogic.hasErrors()) {
distillationTime -= currentRecipe.input.amount;
productTank.fill(currentRecipe.output, true);
distillationTime -= currentRecipe.getInput().amount;
productTank.fill(currentRecipe.getOutput(), true);
return true;
} else if (currentRecipe != null) {
int resourceRequired = currentRecipe.timePerUnit * currentRecipe.input.amount;
int resourceRequired = currentRecipe.getCyclesPerUnit() * currentRecipe.getInput().amount;
boolean canFill = productTank.fill(currentRecipe.output, false) == currentRecipe.output.amount;
boolean canFill = productTank.fill(currentRecipe.getOutput(), false) == currentRecipe.getOutput().amount;
errorLogic.setCondition(!canFill, EnumErrorCode.NOSPACETANK);
boolean hasResource = resourceTank.getFluidAmount() >= resourceRequired;
@@ -233,7 +165,7 @@ public class TileStill extends TilePowered implements ISidedInventory, ILiquidTa
// Start next cycle if enough bio mass is available
distillationTime = distillationTotalTime = resourceRequired;
resourceTank.drain(resourceRequired, true);
bufferedLiquid = new FluidStack(currentRecipe.input, resourceRequired);
bufferedLiquid = new FluidStack(currentRecipe.getInput(), resourceRequired);
return true;
}
@@ -244,10 +176,10 @@ public class TileStill extends TilePowered implements ISidedInventory, ILiquidTa
}
private void checkRecipe() {
Recipe matchingRecipe = RecipeManager.findMatchingRecipe(resourceTank.getFluid());
IStillRecipe matchingRecipe = StillRecipeManager.findMatchingRecipe(resourceTank.getFluid());
if (matchingRecipe == null && bufferedLiquid != null && distillationTime > 0) {
matchingRecipe = RecipeManager.findMatchingRecipe(new FluidStack(bufferedLiquid, distillationTime));
matchingRecipe = StillRecipeManager.findMatchingRecipe(new FluidStack(bufferedLiquid, distillationTime));
}
if (currentRecipe != matchingRecipe) {
@@ -263,8 +195,8 @@ public class TileStill extends TilePowered implements ISidedInventory, ILiquidTa
return false;
}
return (distillationTime > 0 || resourceTank.getFluidAmount() >= currentRecipe.timePerUnit * currentRecipe.input.amount)
&& productTank.getFluidAmount() <= productTank.getCapacity() - currentRecipe.output.amount;
return (distillationTime > 0 || resourceTank.getFluidAmount() >= currentRecipe.getCyclesPerUnit() * currentRecipe.getInput().amount)
&& productTank.getFluidAmount() <= productTank.getCapacity() - currentRecipe.getOutput().amount;
}
public int getDistillationProgressScaled(int i) {
@@ -25,6 +25,7 @@ import cpw.mods.fml.common.network.IGuiHandler;
import forestry.api.circuits.ChipsetManager;
import forestry.api.circuits.CircuitSocketType;
import forestry.api.circuits.ICircuitLayout;
import forestry.api.recipes.ICraftingProvider;
import forestry.api.recipes.RecipeManagers;
import forestry.core.blocks.BlockBase;
import forestry.core.circuits.Circuit;
@@ -50,6 +51,13 @@ import forestry.factory.DummyManagers;
import forestry.factory.GuiHandlerFactory;
import forestry.factory.circuits.CircuitSpeedUpgrade;
import forestry.factory.network.PacketWorktableMemoryUpdate;
import forestry.factory.recipes.CarpenterRecipeManager;
import forestry.factory.recipes.CentrifugeRecipeManager;
import forestry.factory.recipes.FabricatorRecipeManager;
import forestry.factory.recipes.FermenterRecipeManager;
import forestry.factory.recipes.MoistenerRecipeManager;
import forestry.factory.recipes.SqueezerRecipeManager;
import forestry.factory.recipes.StillRecipeManager;
import forestry.factory.tiles.TileBottler;
import forestry.factory.tiles.TileCarpenter;
import forestry.factory.tiles.TileCentrifuge;
@@ -63,7 +71,6 @@ import forestry.factory.tiles.TileStill;
import forestry.factory.tiles.TileWorktable;
import forestry.factory.triggers.FactoryTriggers;
@Plugin(pluginID = "Factory", name = "Factory", author = "SirSengir", url = Constants.URL, unlocalizedDescription = "for.plugin.factory.description")
public class PluginFactory extends ForestryPlugin {
@@ -83,14 +90,14 @@ public class PluginFactory extends ForestryPlugin {
protected void setupAPI() {
super.setupAPI();
RecipeManagers.craftingProviders = ImmutableList.of(
RecipeManagers.carpenterManager = new TileCarpenter.RecipeManager(),
RecipeManagers.centrifugeManager = new TileCentrifuge.RecipeManager(),
RecipeManagers.fabricatorManager = new TileFabricator.RecipeManager(),
RecipeManagers.fermenterManager = new TileFermenter.RecipeManager(),
RecipeManagers.moistenerManager = new TileMoistener.RecipeManager(),
RecipeManagers.squeezerManager = new TileSqueezer.RecipeManager(),
RecipeManagers.stillManager = new TileStill.RecipeManager()
RecipeManagers.craftingProviders = ImmutableList.<ICraftingProvider>of(
RecipeManagers.carpenterManager = new CarpenterRecipeManager(),
RecipeManagers.centrifugeManager = new CentrifugeRecipeManager(),
RecipeManagers.fabricatorManager = new FabricatorRecipeManager(),
RecipeManagers.fermenterManager = new FermenterRecipeManager(),
RecipeManagers.moistenerManager = new MoistenerRecipeManager(),
RecipeManagers.squeezerManager = new SqueezerRecipeManager(),
RecipeManagers.stillManager = new StillRecipeManager()
);
}
@@ -105,14 +112,14 @@ public class PluginFactory extends ForestryPlugin {
protected void disabledSetupAPI() {
super.disabledSetupAPI();
RecipeManagers.craftingProviders = ImmutableList.of(
RecipeManagers.carpenterManager = new DummyManagers.CarpenterManager(),
RecipeManagers.centrifugeManager = new DummyManagers.CentrifugeManager(),
RecipeManagers.fabricatorManager = new DummyManagers.FabricatorManager(),
RecipeManagers.fermenterManager = new DummyManagers.FermenterManager(),
RecipeManagers.moistenerManager = new DummyManagers.MoistenerManager(),
RecipeManagers.squeezerManager = new DummyManagers.SqueezerManager(),
RecipeManagers.stillManager = new DummyManagers.StillManager()
RecipeManagers.craftingProviders = ImmutableList.<ICraftingProvider>of(
RecipeManagers.carpenterManager = new DummyManagers.DummyCarpenterManager(),
RecipeManagers.centrifugeManager = new DummyManagers.DummyCentrifugeManager(),
RecipeManagers.fabricatorManager = new DummyManagers.DummyFabricatorManager(),
RecipeManagers.fermenterManager = new DummyManagers.DummyFermenterManager(),
RecipeManagers.moistenerManager = new DummyManagers.DummyMoistenerManager(),
RecipeManagers.squeezerManager = new DummyManagers.DummySqueezerManager(),
RecipeManagers.stillManager = new DummyManagers.DummyStillManager()
);
}
@@ -44,6 +44,7 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.common.IPlantable;
import net.minecraftforge.common.IShearable;
import net.minecraftforge.common.config.Property;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.oredict.OreDictionary;
import cpw.mods.fml.common.SidedProxy;
@@ -70,7 +71,6 @@ import forestry.core.recipes.RecipeUtil;
import forestry.core.utils.ItemStackUtil;
import forestry.core.utils.Log;
import forestry.core.utils.StringUtil;
import forestry.factory.tiles.TileCarpenter;
import forestry.storage.BackpackDefinition;
import forestry.storage.BackpackInterface;
import forestry.storage.CrateRegistry;
@@ -465,17 +465,33 @@ public class PluginStorage extends ForestryPlugin {
}
public static void createCrateRecipes() {
TileCarpenter.RecipeManager carpenterManager = (TileCarpenter.RecipeManager) RecipeManagers.carpenterManager;
for (ItemCrated crate : crates) {
ItemStack itemStack = new ItemStack(crate);
ItemStack crateStack = new ItemStack(crate);
ItemStack uncrated = crate.getContained();
if (crate.usesOreDict()) {
carpenterManager.addCratingWithOreDict(itemStack);
int[] oreIds = OreDictionary.getOreIDs(uncrated);
for (int oreId : oreIds) {
String oreName = OreDictionary.getOreName(oreId);
addCrating(crateStack, oreName);
}
} else {
carpenterManager.addCrating(itemStack);
addCrating(crateStack, uncrated);
}
addUncrating(crateStack, uncrated);
}
}
private static void addCrating(ItemStack crateStack, Object uncrated) {
FluidStack water = Fluids.WATER.getFluid(Constants.CARPENTER_CRATING_LIQUID_QUANTITY);
ItemStack box = ForestryItem.crate.getItemStack();
RecipeManagers.carpenterManager.addRecipe(Constants.CARPENTER_CRATING_CYCLES, water, box, crateStack, "###", "###", "###", '#', uncrated);
}
private static void addUncrating(ItemStack crateStack, ItemStack uncrated) {
ItemStack product = new ItemStack(uncrated.getItem(), 9, uncrated.getItemDamage());
RecipeManagers.carpenterManager.addRecipe(Constants.CARPENTER_UNCRATING_CYCLES, null, product, "#", '#', crateStack);
}
@Override
public boolean processIMCMessage(IMCMessage message) {
if (message.key.equals("add-backpack-items")) {