Work on Chemical Infuser & Chemical Formulator recipe system

This commit is contained in:
Aidan Brady 2013-12-11 17:08:15 -05:00
parent 7e48fa2743
commit 2d626f2279
8 changed files with 101 additions and 14 deletions

View file

@ -0,0 +1,38 @@
package mekanism.common;
import mekanism.api.Object3D;
import mekanism.api.gas.Gas;
public class ChemicalInput
{
public Gas leftGas;
public Gas rightGas;
public ChemicalInput(Gas left, Gas right)
{
leftGas = left;
rightGas = right;
}
public boolean isValid()
{
return leftGas != null && rightGas != null;
}
@Override
public boolean equals(Object obj)
{
return obj instanceof ChemicalInput &&
((ChemicalInput)obj).leftGas == leftGas &&
((ChemicalInput)obj).rightGas == rightGas;
}
@Override
public int hashCode()
{
int code = 1;
code = 31 * code + leftGas.getID();
code = 31 * code + rightGas.getID();
return code;
}
}

View file

@ -3,6 +3,7 @@ package mekanism.common;
import java.util.HashMap;
import java.util.Map;
import mekanism.api.gas.GasStack;
import mekanism.api.infuse.InfusionInput;
import mekanism.api.infuse.InfusionOutput;
import mekanism.common.util.StackUtils;
@ -80,6 +81,16 @@ public final class RecipeHandler
Recipe.METALLURGIC_INFUSER.put(input, InfusionOutput.getInfusion(input, output));
}
public static void addChemicalInfuserRecipe(ChemicalInput input, GasStack output)
{
Recipe.CHEMICAL_INFUSER.put(input, output);
}
public static void addChemicalFormulatorRecipe(ItemStack input, GasStack output)
{
Recipe.CHEMICAL_FORMULATOR.put(input, output);
}
/**
* Gets the InfusionOutput of the InfusionInput in the parameters.
* @param infusion - input Infusion
@ -87,11 +98,13 @@ public final class RecipeHandler
* @param recipes - Map of recipes
* @return InfusionOutput
*/
public static InfusionOutput getOutput(InfusionInput infusion, boolean stackDecrease, Map<InfusionInput, InfusionOutput> recipes)
{
public static InfusionOutput getOutput(InfusionInput infusion, boolean stackDecrease)
{
if(infusion != null && infusion.inputStack != null)
{
for(Map.Entry entry : recipes.entrySet())
HashMap<InfusionInput, InfusionOutput> recipes = Recipe.METALLURGIC_INFUSER.get();
for(Map.Entry<InfusionInput, InfusionOutput> entry : recipes.entrySet())
{
InfusionInput input = (InfusionInput)entry.getKey();
@ -113,6 +126,42 @@ public final class RecipeHandler
return null;
}
public static GasStack getOutput(ChemicalInput input)
{
if(input != null && input.isValid())
{
HashMap<ChemicalInput, GasStack> recipes = Recipe.CHEMICAL_INFUSER.get();
return recipes.get(input);
}
return null;
}
public GasStack getOutput(ItemStack itemstack, boolean stackDecrease)
{
if(itemstack != null)
{
HashMap<ItemStack, GasStack> recipes = Recipe.CHEMICAL_FORMULATOR.get();
for(Map.Entry<ItemStack, GasStack> entry : recipes.entrySet())
{
ItemStack stack = (ItemStack)entry.getKey();
if(StackUtils.equalsWildcard(stack, itemstack) && itemstack.stackSize >= stack.stackSize)
{
if(stackDecrease)
{
itemstack.stackSize -= stack.stackSize;
}
return entry.getValue().copy();
}
}
}
return null;
}
/**
* Gets the output ItemStack of the ItemStack in the parameters.
* @param itemstack - input ItemStack
@ -150,7 +199,9 @@ public final class RecipeHandler
COMBINER(new HashMap<ItemStack, ItemStack>()),
CRUSHER(new HashMap<ItemStack, ItemStack>()),
PURIFICATION_CHAMBER(new HashMap<ItemStack, ItemStack>()),
METALLURGIC_INFUSER(new HashMap<InfusionInput, InfusionOutput>());
METALLURGIC_INFUSER(new HashMap<InfusionInput, InfusionOutput>()),
CHEMICAL_INFUSER(new HashMap<ChemicalInput, GasStack>()),
CHEMICAL_FORMULATOR(new HashMap<ItemStack, GasStack>());
private HashMap recipes;

View file

@ -18,11 +18,10 @@ public class ContainerChemicalFormulator extends Container
public ContainerChemicalFormulator(InventoryPlayer inventory, TileEntityChemicalInfuser tentity)
{
tileEntity = tentity;
addSlotToContainer(new SlotStorageTank(tentity, null, true, 0, 5, 25));
addSlotToContainer(new SlotStorageTank(tentity, null, true, 1, 5, 56));
addSlotToContainer(new SlotStorageTank(tentity, null, true, 2, 155, 25));
addSlotToContainer(new SlotStorageTank(tentity, null, true, 3, 155, 56));
addSlotToContainer(new SlotDischarge(tentity, 4, 155, 5));
addSlotToContainer(new SlotStorageTank(tentity, null, true, 0, 5, 56));
addSlotToContainer(new SlotStorageTank(tentity, null, true, 1, 80, 65));
addSlotToContainer(new SlotStorageTank(tentity, null, true, 2, 155, 56));
addSlotToContainer(new SlotDischarge(tentity, 3, 155, 5));
int slotX;

View file

@ -24,7 +24,6 @@ public class ContainerChemicalInfuser extends Container
addSlotToContainer(new Slot(tentity, 0, 26, 36));
addSlotToContainer(new SlotDischarge(tentity, 1, 155, 5));
addSlotToContainer(new SlotStorageTank(tentity, null, true, 2, 155, 25));
addSlotToContainer(new SlotStorageTank(tentity, null, true, 3, 155, 56));
int slotX;

View file

@ -156,7 +156,7 @@ public class ContainerMetallurgicInfuser extends Container
{
if(tileEntity.type != null)
{
if(RecipeHandler.getOutput(InfusionInput.getInfusion(tileEntity.type, tileEntity.infuseStored, itemStack), false, Recipe.METALLURGIC_INFUSER.get()) != null)
if(RecipeHandler.getOutput(InfusionInput.getInfusion(tileEntity.type, tileEntity.infuseStored, itemStack), false) != null)
{
return true;
}

View file

@ -226,7 +226,7 @@ public class TileEntityMetallurgicInfuser extends TileEntityElectricBlock implem
{
if(type != null)
{
if(RecipeHandler.getOutput(InfusionInput.getInfusion(type, infuseStored, itemstack), false, Recipe.METALLURGIC_INFUSER.get()) != null)
if(RecipeHandler.getOutput(InfusionInput.getInfusion(type, infuseStored, itemstack), false) != null)
{
return true;
}
@ -257,7 +257,7 @@ public class TileEntityMetallurgicInfuser extends TileEntityElectricBlock implem
return;
}
InfusionOutput output = RecipeHandler.getOutput(InfusionInput.getInfusion(type, infuseStored, inventory[2]), true, Recipe.METALLURGIC_INFUSER.get());
InfusionOutput output = RecipeHandler.getOutput(InfusionInput.getInfusion(type, infuseStored, inventory[2]), true);
infuseStored -= output.getInfuseRequired();
@ -284,7 +284,7 @@ public class TileEntityMetallurgicInfuser extends TileEntityElectricBlock implem
return false;
}
InfusionOutput output = RecipeHandler.getOutput(InfusionInput.getInfusion(type, infuseStored, inventory[2]), false, Recipe.METALLURGIC_INFUSER.get());
InfusionOutput output = RecipeHandler.getOutput(InfusionInput.getInfusion(type, infuseStored, inventory[2]), false);
if(output == null)
{

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4 KiB

After

Width:  |  Height:  |  Size: 4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB