diff --git a/api/forestry b/api/forestry index d2a73f85e..2da758033 160000 --- a/api/forestry +++ b/api/forestry @@ -1 +1 @@ -Subproject commit d2a73f85e656151cf6f46d9eb2d997087ba26f33 +Subproject commit 2da7580337591ae3c53da85b4b2c0c58d2b3da6a diff --git a/src/main/java/forestry/core/fluids/FluidHelper.java b/src/main/java/forestry/core/fluids/FluidHelper.java index 1eba6e777..3ca262efe 100644 --- a/src/main/java/forestry/core/fluids/FluidHelper.java +++ b/src/main/java/forestry/core/fluids/FluidHelper.java @@ -10,6 +10,9 @@ ******************************************************************************/ package forestry.core.fluids; +import java.util.ArrayList; +import java.util.List; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.Item; @@ -19,11 +22,13 @@ import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidContainerRegistry; import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData; +import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidContainerItem; import net.minecraftforge.fluids.IFluidHandler; import forestry.core.config.Constants; +import forestry.core.config.ForestryItem; import forestry.core.utils.InventoryUtil; import forestry.core.utils.ItemStackUtil; @@ -147,14 +152,12 @@ public final class FluidHelper { return false; } - if (output != null && drainedItem != null) { - if (outputSlot == inputSlot) { - if (input.stackSize > 1) { - return false; - } - } else if (!ItemStackUtil.isIdenticalItem(output, drainedItem)) { - return false; - } else if (output.stackSize + drainedItem.stackSize > output.getMaxStackSize()) { + if (!hasRoomForDrainedContainer(input, output, drainedItem, inputSlot, outputSlot)) { + Item item = drainedItem.getItem(); + // consume forestry containers if there is no room for them + if (ForestryItem.canEmpty.isItemEqual(item) || ForestryItem.waxCapsule.isItemEqual(item) || ForestryItem.refractoryEmpty.isItemEqual(item)) { + drainedItem = null; + } else { return false; } } @@ -177,6 +180,22 @@ public final class FluidHelper { return true; } + private static boolean hasRoomForDrainedContainer(ItemStack input, ItemStack output, ItemStack drainedItem, int inputSlot, int outputSlot) { + if (output == null || drainedItem == null) { + return true; + } + + if (outputSlot == inputSlot) { + return input.stackSize == 1; + } + + if (!ItemStackUtil.isIdenticalItem(output, drainedItem)) { + return false; + } + + return output.stackSize + drainedItem.stackSize <= output.getMaxStackSize(); + } + public static boolean isFillableContainer(ItemStack stack, FluidStack liquid) { ItemStack empty = ItemStackUtil.createSplitStack(stack, 1); Item item = empty.getItem(); @@ -222,18 +241,45 @@ public final class FluidHelper { Item item = container.getItem(); if (item == null) { return null; - } else if (item instanceof IFluidContainerItem) { + } + + if (item instanceof IFluidContainerItem) { ItemStack drained = container.copy(); drained.stackSize = 1; IFluidContainerItem containerItem = (IFluidContainerItem) item; containerItem.drain(drained, drainAmount, true); return drained; - } else { + } else if (FluidContainerRegistry.isContainer(container)) { if (drainAmount < Constants.BUCKET_VOLUME) { return container; } - return item.getContainerItem(container); + return FluidContainerRegistry.drainFluidContainer(container); } + + return null; + } + + public static ItemStack getEmptyContainer(ItemStack container) { + if (container == null) { + return null; + } + FluidStack fluidStack = FluidHelper.getFluidStackInContainer(container); + if (fluidStack == null) { + return null; + } + + return FluidHelper.getDrainedContainer(container, fluidStack.amount); + } + + public static List getAllFilledContainers(ItemStack empty) { + List filledContainers = new ArrayList(); + for (Fluid fluid : FluidRegistry.getRegisteredFluids().values()) { + ItemStack filledContainer = getFilledContainer(fluid, empty); + if (filledContainer != null) { + filledContainers.add(filledContainer); + } + } + return filledContainers; } public static ItemStack getFilledContainer(Fluid fluid, ItemStack empty) { @@ -264,6 +310,9 @@ public final class FluidHelper { } public static FluidStack getFluidStackInContainer(ItemStack stack) { + if (stack == null) { + return null; + } Item item = stack.getItem(); if (item instanceof IFluidContainerItem) { IFluidContainerItem containerItem = (IFluidContainerItem) item; diff --git a/src/main/java/forestry/core/fluids/LiquidRegistryHelper.java b/src/main/java/forestry/core/fluids/LiquidRegistryHelper.java index fb36badda..e1e9ad248 100644 --- a/src/main/java/forestry/core/fluids/LiquidRegistryHelper.java +++ b/src/main/java/forestry/core/fluids/LiquidRegistryHelper.java @@ -10,6 +10,8 @@ ******************************************************************************/ package forestry.core.fluids; +import java.util.EnumMap; + import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemBucket; @@ -19,53 +21,44 @@ import net.minecraftforge.fluids.FluidContainerRegistry; import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData; import net.minecraftforge.fluids.FluidStack; -import forestry.api.recipes.RecipeManagers; import forestry.core.config.Constants; import forestry.core.config.ForestryItem; import forestry.core.items.ItemLiquidContainer; import forestry.core.utils.Log; +import static forestry.core.items.ItemLiquidContainer.EnumContainerType; + public class LiquidRegistryHelper { + private static final EnumMap emptyContainers = new EnumMap(EnumContainerType.class); + + static { + emptyContainers.put(EnumContainerType.CAN, ForestryItem.canEmpty); + emptyContainers.put(EnumContainerType.CAPSULE, ForestryItem.waxCapsule); + emptyContainers.put(EnumContainerType.REFRACTORY, ForestryItem.refractoryEmpty); + } + public static void registerLiquidContainer(Fluids fluid, ItemStack filled) { Item item = filled.getItem(); + ItemStack empty = null; + if (item.getContainerItem() instanceof ItemBucket) { - LiquidRegistryHelper.registerLiquidContainer(fluid, Constants.BUCKET_VOLUME, filled, new ItemStack(Items.bucket)); - return; + empty = new ItemStack(Items.bucket); } else if (item instanceof ItemLiquidContainer) { ItemLiquidContainer liquidContainer = (ItemLiquidContainer) item; - switch (liquidContainer.getType()) { - case CAN: - LiquidRegistryHelper.registerTinContainer(fluid, Constants.BUCKET_VOLUME, filled, ForestryItem.canEmpty.getItemStack()); - return; - case CAPSULE: - LiquidRegistryHelper.registerWaxContainer(fluid, Constants.BUCKET_VOLUME, filled, ForestryItem.waxCapsule.getItemStack()); - return; - case REFRACTORY: - LiquidRegistryHelper.registerRefractoryContainer(fluid, Constants.BUCKET_VOLUME, filled, ForestryItem.refractoryEmpty.getItemStack()); - return; - } + EnumContainerType containerType = liquidContainer.getType(); + ForestryItem emptyContainer = emptyContainers.get(containerType); + empty = emptyContainer.getItemStack(); + } + + if (empty == null) { + Log.warning("Unable to inject liquid container: " + filled); + } else { + registerLiquidContainer(fluid, Constants.BUCKET_VOLUME, filled, empty); } - Log.warning("Unable to inject liquid container: " + filled); } public static void registerLiquidContainer(Fluids fluid, int volume, ItemStack filled, ItemStack empty) { - registerLiquidContainer(fluid, volume, filled, empty, null, 0); - } - - public static void registerWaxContainer(Fluids fluid, int volume, ItemStack filled, ItemStack empty) { - registerLiquidContainer(fluid, volume, filled, empty, ForestryItem.beeswax.getItemStack(), 10); - } - - public static void registerRefractoryContainer(Fluids fluid, int volume, ItemStack filled, ItemStack empty) { - registerLiquidContainer(fluid, volume, filled, empty, ForestryItem.refractoryWax.getItemStack(), 10); - } - - public static void registerTinContainer(Fluids fluid, int volume, ItemStack filled, ItemStack empty) { - registerLiquidContainer(fluid, volume, filled, empty, ForestryItem.ingotTin.getItemStack(), 5); - } - - public static void registerLiquidContainer(Fluids fluid, int volume, ItemStack filled, ItemStack empty, ItemStack remnant, int chance) { FluidStack contained = fluid.getFluid(volume); if (contained == null) { throw new IllegalArgumentException(String.format("Attempted to inject a liquid container for the non-existent liquid '%s'.", fluid)); @@ -73,16 +66,6 @@ public class LiquidRegistryHelper { FluidContainerData container = new FluidContainerData(contained, filled, empty); FluidContainerRegistry.registerFluidContainer(container); - - if (RecipeManagers.squeezerManager != null) { - if (!container.filledContainer.getItem().hasContainerItem(container.filledContainer)) { - if (remnant != null) { - RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{container.filledContainer}, container.fluid, remnant, chance); - } else { - RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{container.filledContainer}, container.fluid); - } - } - } } } diff --git a/src/main/java/forestry/core/recipes/nei/PositionedFluidTank.java b/src/main/java/forestry/core/recipes/nei/PositionedFluidTank.java index b0bf469d8..7ea93803f 100644 --- a/src/main/java/forestry/core/recipes/nei/PositionedFluidTank.java +++ b/src/main/java/forestry/core/recipes/nei/PositionedFluidTank.java @@ -12,6 +12,8 @@ package forestry.core.recipes.nei; import java.awt.Point; import java.awt.Rectangle; +import java.util.Collection; +import java.util.Collections; import java.util.List; import net.minecraft.client.renderer.Tessellator; @@ -30,6 +32,7 @@ import codechicken.nei.recipe.GuiUsageRecipe; public class PositionedFluidTank { + public FluidTank[] tanks; public FluidTank tank; public Rectangle position; public String overlayTexture; @@ -38,21 +41,35 @@ public class PositionedFluidTank { public boolean showAmount = true; public boolean perTick = false; - public PositionedFluidTank(FluidTank tank, Rectangle position, String overlayTexture, Point overlayTexturePos) { + public PositionedFluidTank(FluidTank[] tanks, Rectangle position, String overlayTexture, Point overlayTexturePos) { this.position = position; - this.tank = tank; + this.tanks = tanks; + this.tank = tanks[0]; this.overlayTexture = overlayTexture; this.overlayTexturePos = overlayTexturePos; } + public PositionedFluidTank(Collection fluids, int capacity, Rectangle position, String overlayTexture, Point overlayTexturePos) { + this(createFluidTanks(capacity, fluids), position, overlayTexture, overlayTexturePos); + } + public PositionedFluidTank(FluidStack fluid, int capacity, Rectangle position, String overlayTexture, Point overlayTexturePos) { - this(new FluidTank(fluid != null ? fluid.copy() : null, capacity), position, overlayTexture, overlayTexturePos); + this(createFluidTanks(capacity, Collections.singletonList(fluid)), position, overlayTexture, overlayTexturePos); } public PositionedFluidTank(FluidStack fluid, int capacity, Rectangle position) { this(fluid, capacity, position, null, null); } + private static FluidTank[] createFluidTanks(int capacity, Collection fluidStacks) { + FluidTank[] tanks = new FluidTank[fluidStacks.size()]; + int i = 0; + for (FluidStack fluidStack : fluidStacks) { + tanks[i++] = new FluidTank(fluidStacks != null ? fluidStack.copy() : null, capacity); + } + return tanks; + } + public List handleTooltip(List currenttip) { if (this.tank == null || this.tank.getFluid() == null || this.tank.getFluid().getFluid() == null || this.tank.getFluid().amount <= 0) { return currenttip; @@ -132,4 +149,12 @@ public class PositionedFluidTank { GuiDraw.drawTexturedModalRect(this.position.x, this.position.y, this.overlayTexturePos.x, this.overlayTexturePos.y, this.position.width, this.position.height); } } + + public void setPermutationToRender(int index) { + this.tank = this.tanks[index]; + } + + public int getPermutationCount() { + return this.tanks.length; + } } diff --git a/src/main/java/forestry/factory/DummyManagers.java b/src/main/java/forestry/factory/DummyManagers.java index a1e175987..d0e30dd33 100644 --- a/src/main/java/forestry/factory/DummyManagers.java +++ b/src/main/java/forestry/factory/DummyManagers.java @@ -1,5 +1,6 @@ package forestry.factory; +import javax.annotation.Nullable; import java.util.Map; import net.minecraft.item.ItemStack; @@ -125,6 +126,11 @@ public class DummyManagers { } + @Override + public void addContainerRecipe(int timePerItem, ItemStack emptyContainer, @Nullable ItemStack remnants, float chance) { + + } + @Override public Map getRecipes() { return null; diff --git a/src/main/java/forestry/factory/recipes/ISqueezerContainerRecipe.java b/src/main/java/forestry/factory/recipes/ISqueezerContainerRecipe.java new file mode 100644 index 000000000..9bfc1fe6f --- /dev/null +++ b/src/main/java/forestry/factory/recipes/ISqueezerContainerRecipe.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * 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; + +public interface ISqueezerContainerRecipe { + ItemStack getEmptyContainer(); + + int getProcessingTime(); + + ItemStack getRemnants(); + + float getRemnantsChance(); + + ISqueezerRecipe getSqueezerRecipe(ItemStack filledContainer); +} diff --git a/src/main/java/forestry/factory/recipes/SqueezerContainerRecipe.java b/src/main/java/forestry/factory/recipes/SqueezerContainerRecipe.java new file mode 100644 index 000000000..9d6fa02bb --- /dev/null +++ b/src/main/java/forestry/factory/recipes/SqueezerContainerRecipe.java @@ -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 net.minecraft.item.ItemStack; + +import net.minecraftforge.fluids.FluidStack; + +import forestry.core.fluids.FluidHelper; + +public class SqueezerContainerRecipe implements ISqueezerContainerRecipe { + + private final ItemStack emptyContainer; + private final int processingTime; + private final ItemStack remnants; + private final float remnantsChance; + + public SqueezerContainerRecipe(ItemStack emptyContainer, int processingTime, ItemStack remnants, float remnantsChance) { + this.emptyContainer = emptyContainer; + this.processingTime = processingTime; + this.remnants = remnants; + this.remnantsChance = remnantsChance; + } + + @Override + public ItemStack getEmptyContainer() { + return emptyContainer; + } + + @Override + public int getProcessingTime() { + return processingTime; + } + + @Override + public ItemStack getRemnants() { + return remnants; + } + + @Override + public float getRemnantsChance() { + return remnantsChance; + } + + @Override + public ISqueezerRecipe getSqueezerRecipe(ItemStack filledContainer) { + FluidStack fluidOutput = FluidHelper.getFluidStackInContainer(filledContainer); + return new SqueezerRecipe(processingTime, new ItemStack[]{filledContainer}, fluidOutput, remnants, remnantsChance); + } + +} diff --git a/src/main/java/forestry/factory/recipes/nei/NEIHandlerBottler.java b/src/main/java/forestry/factory/recipes/nei/NEIHandlerBottler.java index 2a7bdd8f9..3830de644 100644 --- a/src/main/java/forestry/factory/recipes/nei/NEIHandlerBottler.java +++ b/src/main/java/forestry/factory/recipes/nei/NEIHandlerBottler.java @@ -136,7 +136,6 @@ public class NEIHandlerBottler extends RecipeHandlerBase { @Override public void loadUsageRecipes(ItemStack ingred) { - super.loadUsageRecipes(ingred); for (TileBottler.Recipe recipe : recipes) { if (NEIServerUtils.areStacksSameTypeCrafting(recipe.can, ingred)) { this.arecipes.add(new CachedBottlerRecipe(recipe)); diff --git a/src/main/java/forestry/factory/recipes/nei/NEIHandlerSqueezer.java b/src/main/java/forestry/factory/recipes/nei/NEIHandlerSqueezer.java index 2af6f75fa..6dbf413b9 100644 --- a/src/main/java/forestry/factory/recipes/nei/NEIHandlerSqueezer.java +++ b/src/main/java/forestry/factory/recipes/nei/NEIHandlerSqueezer.java @@ -13,7 +13,10 @@ package forestry.factory.recipes.nei; import java.awt.Point; import java.awt.Rectangle; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; import java.util.List; +import java.util.Random; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.item.ItemStack; @@ -21,11 +24,13 @@ import net.minecraft.util.StatCollector; import net.minecraftforge.fluids.FluidStack; +import forestry.core.fluids.FluidHelper; import forestry.core.recipes.nei.NEIUtils; import forestry.core.recipes.nei.PositionedFluidTank; 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; @@ -42,13 +47,14 @@ public class NEIHandlerSqueezer extends RecipeHandlerBase { public PositionedFluidTank tank; public PositionedStackAdv remnants = null; public int processingTime; + public boolean containerRecipe = false; public CachedSqueezerRecipe(ISqueezerRecipe recipe, boolean genPerms) { if (recipe.getResources() != null) { this.setIngredients(recipe.getResources()); } if (recipe.getFluidOutput() != null) { - this.tank = new PositionedFluidTank(recipe.getFluidOutput(), 10000, new Rectangle(117, 7, 16, 58), NEIHandlerSqueezer.this.getGuiTexture(), new Point(176, 0)); + setTankFluid(recipe.getFluidOutput()); } if (recipe.getRemnants() != null) { this.remnants = new PositionedStackAdv(recipe.getRemnants(), 92, 49).setChance(recipe.getRemnantsChance()); @@ -65,7 +71,32 @@ public class NEIHandlerSqueezer extends RecipeHandlerBase { this(recipe, false); } + public CachedSqueezerRecipe(ISqueezerContainerRecipe recipe, boolean genPerms) { + this.containerRecipe = true; + + ItemStack emptyContainer = recipe.getEmptyContainer(); + List ingredients = FluidHelper.getAllFilledContainers(emptyContainer); + setIngredients(new Object[]{ingredients}); + List fluids = new ArrayList(); + for (ItemStack ingredient : ingredients) { + FluidStack fluidStack = FluidHelper.getFluidStackInContainer(ingredient); + fluids.add(fluidStack); + } + setTankFluid(fluids); + + if (recipe.getRemnants() != null) { + this.remnants = new PositionedStackAdv(recipe.getRemnants(), 92, 49).setChance(recipe.getRemnantsChance()); + } + + this.processingTime = recipe.getProcessingTime(); + + if (genPerms) { + this.generatePermutations(); + } + } + public void setIngredients(Object[] inputs) { + this.inputs.clear(); int i = 0; for (Object stack : inputs) { if (i >= INPUTS.length) { @@ -76,11 +107,35 @@ public class NEIHandlerSqueezer extends RecipeHandlerBase { } } + public void setTankFluid(FluidStack... fluidStack) { + setTankFluid(Arrays.asList(fluidStack)); + } + + public void setTankFluid(Collection fluidStacks) { + this.tank = new PositionedFluidTank(fluidStacks, 10000, new Rectangle(117, 7, 16, 58), NEIHandlerSqueezer.this.getGuiTexture(), new Point(176, 0)); + } + @Override public List getIngredients() { return this.getCycledIngredients(NEIHandlerSqueezer.this.cycleticks / 20, this.inputs); } + @Override + public List getCycledIngredients(int cycle, List ingredients) { + if (containerRecipe) { + // cycle ingredients and output together + Random random = new Random(cycle); + cycle = Math.abs(random.nextInt()); + for (PositionedStack ingredient : ingredients) { + ingredient.setPermutationToRender(cycle % ingredient.items.length); + } + tank.setPermutationToRender(cycle % tank.getPermutationCount()); + return ingredients; + } else { + return super.getCycledIngredients(cycle, ingredients); + } + } + @Override public PositionedFluidTank getFluidTank() { return this.tank; @@ -138,16 +193,23 @@ public class NEIHandlerSqueezer extends RecipeHandlerBase { for (ISqueezerRecipe recipe : TileSqueezer.RecipeManager.recipes) { this.arecipes.add(new CachedSqueezerRecipe(recipe, true)); } + for (ISqueezerContainerRecipe containerRecipe : TileSqueezer.RecipeManager.containerRecipes.values()) { + this.arecipes.add(new CachedSqueezerRecipe(containerRecipe, true)); + } } @Override public void loadCraftingRecipes(ItemStack result) { - super.loadCraftingRecipes(result); for (ISqueezerRecipe recipe : TileSqueezer.RecipeManager.recipes) { if (NEIServerUtils.areStacksSameTypeCrafting(recipe.getRemnants(), result)) { this.arecipes.add(new CachedSqueezerRecipe(recipe, true)); } } + for (ISqueezerContainerRecipe containerRecipe : TileSqueezer.RecipeManager.containerRecipes.values()) { + if (NEIServerUtils.areStacksSameTypeCrafting(containerRecipe.getRemnants(), result)) { + this.arecipes.add(new CachedSqueezerRecipe(containerRecipe, true)); + } + } } @Override @@ -157,10 +219,28 @@ public class NEIHandlerSqueezer extends RecipeHandlerBase { this.arecipes.add(new CachedSqueezerRecipe(recipe, true)); } } + for (ISqueezerContainerRecipe containerRecipe : TileSqueezer.RecipeManager.containerRecipes.values()) { + ItemStack emptyContainer = containerRecipe.getEmptyContainer(); + if (FluidHelper.isFillableContainer(emptyContainer, result)) { + ItemStack filledContainer = FluidHelper.getFilledContainer(result, emptyContainer); + ISqueezerRecipe recipe = containerRecipe.getSqueezerRecipe(filledContainer); + this.arecipes.add(new CachedSqueezerRecipe(recipe, true)); + } + } } @Override public void loadUsageRecipes(ItemStack ingred) { + ISqueezerContainerRecipe containerRecipe = TileSqueezer.RecipeManager.findMatchingContainerRecipe(ingred); + if (containerRecipe != null) { + CachedSqueezerRecipe crecipe = new CachedSqueezerRecipe(containerRecipe, true); + crecipe.setIngredients(new ItemStack[]{ingred}); + FluidStack fluidStack = FluidHelper.getFluidStackInContainer(ingred); + crecipe.setTankFluid(fluidStack); + this.arecipes.add(crecipe); + return; + } + ISqueezerRecipe recipe = TileSqueezer.RecipeManager.findMatchingRecipe(new ItemStack[]{ingred}); if (recipe != null) { CachedSqueezerRecipe crecipe = new CachedSqueezerRecipe(recipe); diff --git a/src/main/java/forestry/factory/tiles/TileSqueezer.java b/src/main/java/forestry/factory/tiles/TileSqueezer.java index 2d49b03a1..556f17d7a 100644 --- a/src/main/java/forestry/factory/tiles/TileSqueezer.java +++ b/src/main/java/forestry/factory/tiles/TileSqueezer.java @@ -10,6 +10,7 @@ ******************************************************************************/ package forestry.factory.tiles; +import javax.annotation.Nullable; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -55,7 +56,10 @@ 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; public class TileSqueezer extends TilePowered implements ISocketable, ISidedInventory, ILiquidTankTile, ISpeedUpgradable { @@ -166,7 +170,12 @@ public class TileSqueezer extends TilePowered implements ISocketable, ISidedInve ISqueezerRecipe matchingRecipe = null; if (inventory.hasResources()) { ItemStack[] resources = inventory.getResources(); - matchingRecipe = RecipeManager.findMatchingRecipe(resources); + + if (currentRecipe != null && ItemStackUtil.containsSets(currentRecipe.getResources(), resources, true, false) > 0) { + matchingRecipe = currentRecipe; + } else { + matchingRecipe = RecipeManager.findMatchingRecipe(resources); + } } if (currentRecipe != matchingRecipe) { @@ -370,13 +379,12 @@ public class TileSqueezer extends TilePowered implements ISocketable, ISidedInve public static final List recipes = new ArrayList(); public static final Set recipeInputs = new HashSet(); + public static final ItemStackMap containerRecipes = new ItemStackMap(); @Override - public void addRecipe(int timePerItem, ItemStack[] resources, FluidStack liquid, ItemStack remnants, int chance) { + 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)); - if (resources != null) { - recipeInputs.addAll(Arrays.asList(resources)); - } + recipeInputs.addAll(Arrays.asList(resources)); } @Override @@ -384,15 +392,43 @@ public class TileSqueezer extends TilePowered implements ISocketable, ISidedInve 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)); + } + + public static ISqueezerContainerRecipe findMatchingContainerRecipe(ItemStack filledContainer) { + ItemStack emptyContainer = FluidHelper.getEmptyContainer(filledContainer); + if (emptyContainer == null) { + return null; + } + + ISqueezerContainerRecipe containerRecipe = containerRecipes.get(emptyContainer); + if (containerRecipe != null) { + return containerRecipe; + } + + // default recipe for unregistered fluid items, has no remnants + return new SqueezerContainerRecipe(emptyContainer, 10, null, 0); + } + public static ISqueezerRecipe findMatchingRecipe(ItemStack[] items) { - // First try to match a specific recipe (without OD) + // Find container recipes + for (ItemStack itemStack : items) { + ISqueezerContainerRecipe recipe = findMatchingContainerRecipe(itemStack); + if (recipe != null) { + return recipe.getSqueezerRecipe(itemStack); + } + } + + // 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 oredict support enabled + // If that fails - try again with OreDictionary support enabled for (ISqueezerRecipe recipe : recipes) { if (ItemStackUtil.containsSets(recipe.getResources(), items, true, false) > 0) { return recipe; @@ -403,15 +439,13 @@ public class TileSqueezer extends TilePowered implements ISocketable, ISidedInve } public static boolean canUse(ItemStack itemStack) { - if (recipeInputs.contains(itemStack)) { - return true; - } for (ItemStack recipeInput : recipeInputs) { if (ItemStackUtil.isCraftingEquivalent(recipeInput, itemStack, true, false)) { return true; } } - return false; + + return RecipeManager.findMatchingContainerRecipe(itemStack) != null; } @Override diff --git a/src/main/java/forestry/plugins/PluginFluids.java b/src/main/java/forestry/plugins/PluginFluids.java index b0e46295b..5733b3e83 100644 --- a/src/main/java/forestry/plugins/PluginFluids.java +++ b/src/main/java/forestry/plugins/PluginFluids.java @@ -35,6 +35,7 @@ import cpw.mods.fml.relauncher.SideOnly; import forestry.api.fuels.FuelManager; import forestry.api.fuels.GeneratorFuel; +import forestry.api.recipes.RecipeManagers; import forestry.core.config.Config; import forestry.core.config.Constants; import forestry.core.config.ForestryItem; @@ -144,6 +145,12 @@ public class PluginFluids extends ForestryPlugin { } } + if (RecipeManagers.squeezerManager != null) { + RecipeManagers.squeezerManager.addContainerRecipe(10, ForestryItem.canEmpty.getItemStack(), ForestryItem.ingotTin.getItemStack(), 0.05f); + RecipeManagers.squeezerManager.addContainerRecipe(10, ForestryItem.waxCapsule.getItemStack(), ForestryItem.beeswax.getItemStack(), 0.10f); + RecipeManagers.squeezerManager.addContainerRecipe(10, ForestryItem.refractoryEmpty.getItemStack(), ForestryItem.refractoryWax.getItemStack(), 0.10f); + } + FluidStack ethanol = Fluids.ETHANOL.getFluid(1); GeneratorFuel ethanolFuel = new GeneratorFuel(ethanol, (int) (32 * GameMode.getGameMode().getFloatSetting("fuel.ethanol.generator")), 4); FuelManager.generatorFuel.put(ethanol.getFluid(), ethanolFuel); diff --git a/src/main/java/forestry/plugins/PluginIC2.java b/src/main/java/forestry/plugins/PluginIC2.java index 847e8f1de..6b19794bc 100644 --- a/src/main/java/forestry/plugins/PluginIC2.java +++ b/src/main/java/forestry/plugins/PluginIC2.java @@ -41,7 +41,6 @@ import forestry.core.config.ForestryBlock; import forestry.core.config.ForestryItem; import forestry.core.config.GameMode; import forestry.core.fluids.Fluids; -import forestry.core.fluids.LiquidRegistryHelper; import forestry.core.proxy.Proxies; import forestry.core.recipes.RecipeUtil; import forestry.core.recipes.ShapedRecipeCustom; @@ -295,13 +294,8 @@ public class PluginIC2 extends ForestryPlugin { FuelManager.bronzeEngineFuel.put(biogas.getFluid(), new EngineBronzeFuel(Fluids.BIOMASS.getFluid(), Constants.ENGINE_FUEL_VALUE_BIOMASS, (int) ((Constants.ENGINE_CYCLE_DURATION_BIOMASS * GameMode.getGameMode().getFloatSetting("fuel.biomass.biogas"))), 1)); } - if (lavaCell != null) { - LiquidRegistryHelper.registerTinContainer(Fluids.LAVA, Constants.BUCKET_VOLUME, lavaCell, emptyCell); - } if (waterCell != null) { - LiquidRegistryHelper.registerTinContainer(Fluids.WATER, Constants.BUCKET_VOLUME, waterCell, emptyCell); - ItemStack bogEarthCan = GameMode.getGameMode().getStackSetting("recipe.output.bogearth.can"); if (bogEarthCan.stackSize > 0) { Proxies.common.addRecipe(bogEarthCan, "#Y#", "YXY", "#Y#", '#', Blocks.dirt, 'X', waterCell, 'Y', "sand");