More work in the quest for greater recipe efficiency.

This commit is contained in:
Ben Spiers 2014-09-05 04:20:12 +01:00
parent c6a77f9cfa
commit c7a429177b
87 changed files with 1416 additions and 1106 deletions

View file

@ -0,0 +1 @@
package mekanism.api.energy;

View file

@ -0,0 +1 @@
package mekanism.api.gas;

View file

@ -0,0 +1 @@
package mekanism.api.infuse;

View file

@ -0,0 +1 @@
package mekanism.api.lasers;

View file

@ -0,0 +1 @@
package mekanism.api;

View file

@ -0,0 +1 @@
package mekanism.api.reactor;

View file

@ -181,15 +181,16 @@ public final class RecipeHelper
/**
* Add an Electrolytic Separator recipe.
* @param input - input FluidStack
* @param energy - required energy
* @param leftOutput - left output GasStack
* @param rightOutput - right output GasStack
*/
public static void addElectrolyticSeparatorRecipe(FluidStack input, GasStack leftOutput, GasStack rightOutput)
public static void addElectrolyticSeparatorRecipe(FluidStack input, double energy, GasStack leftOutput, GasStack rightOutput)
{
try {
Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler");
Method m = recipeClass.getMethod("addElectrolyticSeparatorRecipe", FluidStack.class, GasStack.class, GasStack.class);
m.invoke(null, input, leftOutput, rightOutput);
Method m = recipeClass.getMethod("addElectrolyticSeparatorRecipe", FluidStack.class, Double.TYPE, GasStack.class, GasStack.class);
m.invoke(null, input, energy, leftOutput, rightOutput);
} catch(Exception e) {
System.err.println("Error while adding recipe: " + e.getMessage());
}

View file

@ -0,0 +1 @@
package mekanism.api.recipe;

View file

@ -0,0 +1 @@
package mekanism.api.transmitters;

View file

@ -55,6 +55,10 @@ public final class StackUtils
public static boolean equalsWildcard(ItemStack wild, ItemStack check)
{
if(wild == null || check == null)
{
return check == wild;
}
return wild.getItem() == check.getItem() && (wild.getItemDamage() == OreDictionary.WILDCARD_VALUE || wild.getItemDamage() == check.getItemDamage());
}
@ -231,6 +235,11 @@ public final class StackUtils
}
}
public static boolean contains(ItemStack container, ItemStack contained)
{
return equalsWildcardWithNBT(contained, container) && container.stackSize >= contained.stackSize;
}
public static int hashItemStack(ItemStack stack)
{
return Item.getIdFromItem(stack.getItem()) << 8 | stack.getItemDamage();

View file

@ -0,0 +1 @@
package mekanism.api.util;

View file

@ -53,7 +53,7 @@ public class GuiFactory extends GuiMekanism
fontRendererObj.drawString(tileEntity.getInventoryName(), 48, 4, 0x404040);
fontRendererObj.drawString(MekanismUtils.localize("container.inventory"), 8, (ySize - 93) + 2, 0x404040);
fontRendererObj.drawString(RecipeType.values()[tileEntity.recipeType].getName(), 104, (ySize - 93) + 2, 0x404040);
fontRendererObj.drawString(tileEntity.recipeType.getName(), 104, (ySize - 93) + 2, 0x404040);
if(xAxis >= 165 && xAxis <= 169 && yAxis >= 17 && yAxis <= 69)
{

View file

@ -73,7 +73,7 @@ public class GuiMetallurgicInfuser extends GuiMekanism
if(xAxis >= 7 && xAxis <= 11 && yAxis >= 17 && yAxis <= 69)
{
drawCreativeTabHoveringText(tileEntity.type != null ? tileEntity.type.getLocalizedName() + ": " + tileEntity.infuseStored : MekanismUtils.localize("gui.empty"), xAxis, yAxis);
drawCreativeTabHoveringText(tileEntity.infuseStored.type != null ? tileEntity.infuseStored.type.getLocalizedName() + ": " + tileEntity.infuseStored : MekanismUtils.localize("gui.empty"), xAxis, yAxis);
}
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
@ -88,14 +88,11 @@ public class GuiMetallurgicInfuser extends GuiMekanism
int guiHeight = (height - ySize) / 2;
drawTexturedModalRect(guiWidth, guiHeight, 0, 0, xSize, ySize);
int xAxis = mouseX - guiWidth;
int yAxis = mouseY - guiHeight;
if(tileEntity.type != null)
if(tileEntity.infuseStored.type != null)
{
int displayInt = tileEntity.getScaledInfuseLevel(52);
mc.renderEngine.bindTexture(tileEntity.type.texture);
drawTexturedModalRect(guiWidth + 7, guiHeight + 17 + 52 - displayInt, tileEntity.type.texX, tileEntity.type.texY + 52 - displayInt, 4, displayInt);
mc.renderEngine.bindTexture(tileEntity.infuseStored.type.texture);
drawTexturedModalRect(guiWidth + 7, guiHeight + 17 + 52 - displayInt, tileEntity.infuseStored.type.texX, tileEntity.infuseStored.type.texY + 52 - displayInt, 4, displayInt);
}
super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY);

View file

@ -119,7 +119,7 @@ public abstract class AdvancedMachineRecipeHandler extends BaseRecipeHandler
{
if(outputId.equals(getRecipeId()))
{
for(AdvancedMachineRecipe irecipe : getRecipes())
for(AdvancedMachineRecipe<?> irecipe : getRecipes())
{
arecipes.add(new CachedIORecipe(irecipe, getFuelStacks(irecipe.getInput().gasType)));
}
@ -132,7 +132,7 @@ public abstract class AdvancedMachineRecipeHandler extends BaseRecipeHandler
@Override
public void loadCraftingRecipes(ItemStack result)
{
for(AdvancedMachineRecipe irecipe : getRecipes())
for(AdvancedMachineRecipe<?> irecipe : getRecipes())
{
if(NEIServerUtils.areStacksSameTypeCrafting(irecipe.getOutput().output, result))
{
@ -152,7 +152,7 @@ public abstract class AdvancedMachineRecipeHandler extends BaseRecipeHandler
{
if(inputId.equals("gas") && ingredients.length == 1 && ingredients[0] instanceof GasStack)
{
for(AdvancedMachineRecipe irecipe : getRecipes())
for(AdvancedMachineRecipe<?> irecipe : getRecipes())
{
if(irecipe.getInput().gasType == ((GasStack)ingredients[0]).getGas())
{
@ -168,7 +168,7 @@ public abstract class AdvancedMachineRecipeHandler extends BaseRecipeHandler
@Override
public void loadUsageRecipes(ItemStack ingredient)
{
for(AdvancedMachineRecipe irecipe : getRecipes())
for(AdvancedMachineRecipe<?> irecipe : getRecipes())
{
if(NEIServerUtils.areStacksSameTypeCrafting(irecipe.getInput().itemStack, ingredient))
{
@ -301,7 +301,7 @@ public abstract class AdvancedMachineRecipeHandler extends BaseRecipeHandler
fuelStacks = fuels;
}
public CachedIORecipe(AdvancedMachineRecipe recipe, List<ItemStack> fuels)
public CachedIORecipe(AdvancedMachineRecipe<?> recipe, List<ItemStack> fuels)
{
this(recipe.getInput(), recipe.getOutput().output, fuels);
}

View file

@ -122,7 +122,7 @@ public abstract class ChanceMachineRecipeHandler extends BaseRecipeHandler
@Override
public void loadCraftingRecipes(ItemStack result)
{
for(ChanceMachineRecipe irecipe : getRecipes())
for(ChanceMachineRecipe<?> irecipe : getRecipes())
{
if(irecipe.getOutput().hasPrimary() && NEIServerUtils.areStacksSameTypeCrafting(irecipe.getOutput().primaryOutput, result))
{
@ -144,7 +144,7 @@ public abstract class ChanceMachineRecipeHandler extends BaseRecipeHandler
@Override
public void loadUsageRecipes(ItemStack ingredient)
{
for(ChanceMachineRecipe irecipe : getRecipes())
for(ChanceMachineRecipe<?> irecipe : getRecipes())
{
if(NEIServerUtils.areStacksSameTypeCrafting((ItemStack)irecipe.getInput().ingredient, ingredient))
{
@ -192,7 +192,7 @@ public abstract class ChanceMachineRecipeHandler extends BaseRecipeHandler
output = chance;
}
public CachedIORecipe(ChanceMachineRecipe recipe)
public CachedIORecipe(ChanceMachineRecipe<?> recipe)
{
this(recipe.getInput().ingredient, recipe.getOutput());
}

View file

@ -108,7 +108,7 @@ public abstract class MachineRecipeHandler extends BaseRecipeHandler
@Override
public void loadCraftingRecipes(ItemStack result)
{
for(BasicMachineRecipe irecipe : getRecipes())
for(BasicMachineRecipe<?> irecipe : getRecipes())
{
if(NEIServerUtils.areStacksSameTypeCrafting(irecipe.getOutput().output, result))
{
@ -126,7 +126,7 @@ public abstract class MachineRecipeHandler extends BaseRecipeHandler
@Override
public void loadUsageRecipes(ItemStack ingredient)
{
for(BasicMachineRecipe irecipe : getRecipes())
for(BasicMachineRecipe<?> irecipe : getRecipes())
{
if(NEIServerUtils.areStacksSameTypeCrafting(irecipe.getInput().ingredient, ingredient))
{
@ -160,7 +160,7 @@ public abstract class MachineRecipeHandler extends BaseRecipeHandler
output = new PositionedStack(itemstack1, 100, 30);
}
public CachedIORecipe(BasicMachineRecipe recipe)
public CachedIORecipe(BasicMachineRecipe<?> recipe)
{
this(recipe.getInput().ingredient, recipe.getOutput().output);
}

View file

@ -2,6 +2,7 @@ package mekanism.client.nei;
import java.awt.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@ -10,8 +11,7 @@ import java.util.Set;
import mekanism.api.infuse.InfuseObject;
import mekanism.api.infuse.InfuseRegistry;
import mekanism.api.infuse.InfuseType;
import mekanism.common.recipe.inputs.InfusionInput;
import mekanism.common.recipe.outputs.InfusionOutput;
import mekanism.common.recipe.machines.MetallurgicInfuserRecipe;
import mekanism.client.gui.GuiElement;
import mekanism.client.gui.GuiMetallurgicInfuser;
import mekanism.client.gui.GuiPowerBar;
@ -109,9 +109,9 @@ public class MetallurgicInfuserRecipeHandler extends BaseRecipeHandler
return ret;
}
public Set<Entry<InfusionInput, InfusionOutput>> getRecipes()
public Collection<MetallurgicInfuserRecipe> getRecipes()
{
return Recipe.METALLURGIC_INFUSER.get().entrySet();
return Recipe.METALLURGIC_INFUSER.get().values();
}
@Override
@ -158,9 +158,9 @@ public class MetallurgicInfuserRecipeHandler extends BaseRecipeHandler
{
if(outputId.equals(getRecipeId()))
{
for(Map.Entry irecipe : getRecipes())
for(MetallurgicInfuserRecipe irecipe : getRecipes())
{
arecipes.add(new CachedIORecipe(irecipe, getInfuseStacks(((InfusionInput)irecipe.getKey()).infusionType), ((InfusionInput)irecipe.getKey()).infusionType));
arecipes.add(new CachedIORecipe(irecipe, getInfuseStacks(irecipe.getInput().infuse.type), irecipe.getInput().infuse.type));
}
}
else {
@ -177,11 +177,11 @@ public class MetallurgicInfuserRecipeHandler extends BaseRecipeHandler
@Override
public void loadCraftingRecipes(ItemStack result)
{
for(Map.Entry irecipe : getRecipes())
for(MetallurgicInfuserRecipe irecipe : getRecipes())
{
if(NEIServerUtils.areStacksSameTypeCrafting(((InfusionOutput)irecipe.getValue()).resource, result))
if(NEIServerUtils.areStacksSameTypeCrafting(irecipe.getOutput().output, result))
{
arecipes.add(new CachedIORecipe(irecipe, getInfuseStacks(((InfusionInput)irecipe.getKey()).infusionType), ((InfusionInput)irecipe.getKey()).infusionType));
arecipes.add(new CachedIORecipe(irecipe, getInfuseStacks(irecipe.getInput().infuse.type), irecipe.getInput().infuse.type));
}
}
}
@ -189,11 +189,11 @@ public class MetallurgicInfuserRecipeHandler extends BaseRecipeHandler
@Override
public void loadUsageRecipes(ItemStack ingredient)
{
for(Map.Entry irecipe : getRecipes())
for(MetallurgicInfuserRecipe irecipe : getRecipes())
{
if(NEIServerUtils.areStacksSameTypeCrafting(((InfusionInput)irecipe.getKey()).inputStack, ingredient))
if(NEIServerUtils.areStacksSameTypeCrafting(irecipe.getInput().inputStack, ingredient))
{
arecipes.add(new CachedIORecipe(irecipe, getInfuseStacks(((InfusionInput)irecipe.getKey()).infusionType), ((InfusionInput)irecipe.getKey()).infusionType));
arecipes.add(new CachedIORecipe(irecipe, getInfuseStacks(irecipe.getInput().infuse.type), irecipe.getInput().infuse.type));
}
}
}
@ -237,9 +237,9 @@ public class MetallurgicInfuserRecipeHandler extends BaseRecipeHandler
infusionType = type;
}
public CachedIORecipe(Map.Entry recipe, List<ItemStack> infuses, InfuseType type)
public CachedIORecipe(MetallurgicInfuserRecipe recipe, List<ItemStack> infuses, InfuseType type)
{
this(((InfusionInput)recipe.getKey()).inputStack, ((InfusionOutput)recipe.getValue()).resource, infuses, type);
this(recipe.getInput().inputStack, recipe.getOutput().output, infuses, type);
}
}
}

View file

@ -7,7 +7,7 @@ import java.util.Map.Entry;
import java.util.Set;
import mekanism.api.gas.GasStack;
import mekanism.common.recipe.inputs.PressurizedReactants;
import mekanism.common.recipe.inputs.PressurizedInput;
import mekanism.common.recipe.machines.PressurizedRecipe;
import mekanism.client.gui.GuiElement;
import mekanism.client.gui.GuiFluidGauge;
@ -88,7 +88,7 @@ public class PRCRecipeHandler extends BaseRecipeHandler
return ProgressBar.MEDIUM;
}
public Set<Entry<PressurizedReactants, PressurizedRecipe>> getRecipes()
public Set<Entry<PressurizedInput, PressurizedRecipe>> getRecipes()
{
return Recipe.PRESSURIZED_REACTION_CHAMBER.get().entrySet();
}
@ -190,7 +190,7 @@ public class PRCRecipeHandler extends BaseRecipeHandler
}
else if(outputId.equals("gas") && results.length == 1 && results[0] instanceof GasStack)
{
for(Map.Entry<PressurizedReactants, PressurizedRecipe> irecipe : getRecipes())
for(Map.Entry<PressurizedInput, PressurizedRecipe> irecipe : getRecipes())
{
if(irecipe.getValue().getInput().containsType((GasStack)results[0]))
{
@ -206,7 +206,7 @@ public class PRCRecipeHandler extends BaseRecipeHandler
@Override
public void loadCraftingRecipes(ItemStack result)
{
for(Map.Entry<PressurizedReactants, PressurizedRecipe> irecipe : getRecipes())
for(Map.Entry<PressurizedInput, PressurizedRecipe> irecipe : getRecipes())
{
if(NEIServerUtils.areStacksSameTypeCrafting(irecipe.getValue().getOutput().getItemOutput(), result))
{
@ -220,7 +220,7 @@ public class PRCRecipeHandler extends BaseRecipeHandler
{
if(inputId.equals("gas") && ingredients.length == 1 && ingredients[0] instanceof GasStack)
{
for(Map.Entry<PressurizedReactants, PressurizedRecipe> irecipe : getRecipes())
for(Map.Entry<PressurizedInput, PressurizedRecipe> irecipe : getRecipes())
{
if(irecipe.getKey().containsType((GasStack)ingredients[0]))
{
@ -230,7 +230,7 @@ public class PRCRecipeHandler extends BaseRecipeHandler
}
else if(inputId.equals("fluid") && ingredients.length == 1 && ingredients[0] instanceof FluidStack)
{
for(Map.Entry<PressurizedReactants, PressurizedRecipe> irecipe : getRecipes())
for(Map.Entry<PressurizedInput, PressurizedRecipe> irecipe : getRecipes())
{
if(irecipe.getKey().containsType((FluidStack)ingredients[0]))
{
@ -246,7 +246,7 @@ public class PRCRecipeHandler extends BaseRecipeHandler
@Override
public void loadUsageRecipes(ItemStack ingredient)
{
for(Map.Entry<PressurizedReactants, PressurizedRecipe> irecipe : getRecipes())
for(Map.Entry<PressurizedInput, PressurizedRecipe> irecipe : getRecipes())
{
if(NEIServerUtils.areStacksSameTypeCrafting(irecipe.getKey().getSolid(), ingredient))
{

View file

@ -0,0 +1,34 @@
package mekanism.common;
import mekanism.api.infuse.InfuseType;
public class InfuseStorage
{
public InfuseType type;
public int amount;
public InfuseStorage() {}
public InfuseStorage(InfuseType infuseType, int infuseAmount)
{
type = infuseType;
amount = infuseAmount;
}
public boolean contains(InfuseStorage storage)
{
return type == storage.type && amount >= storage.amount;
}
public void subtract(InfuseStorage storage)
{
if(contains(storage))
{
amount -= storage.amount;
} else if(type == storage.type)
{
amount = 0;
}
}
}

View file

@ -22,12 +22,6 @@ import mekanism.api.gas.OreGas;
import mekanism.api.infuse.InfuseObject;
import mekanism.api.infuse.InfuseRegistry;
import mekanism.api.infuse.InfuseType;
import mekanism.common.recipe.inputs.InfusionInput;
import mekanism.common.recipe.inputs.ChemicalPairInput;
import mekanism.common.recipe.outputs.ChanceOutput;
import mekanism.common.recipe.outputs.ChemicalPairOutput;
import mekanism.common.recipe.outputs.PressurizedProducts;
import mekanism.common.recipe.inputs.PressurizedReactants;
import mekanism.api.transmitters.DynamicNetwork.ClientTickUpdate;
import mekanism.api.transmitters.DynamicNetwork.NetworkClientRequest;
import mekanism.api.transmitters.TransmitterNetworkRegistry;
@ -716,8 +710,8 @@ public class Mekanism
RecipeHandler.addChemicalInfuserRecipe(new GasStack(GasRegistry.getGas("hydrogen"), 1), new GasStack(GasRegistry.getGas("chlorine"), 1), new GasStack(GasRegistry.getGas("hydrogenChloride"), 1));
//Electrolytic Separator Recipes
RecipeHandler.addElectrolyticSeparatorRecipe(FluidRegistry.getFluidStack("water", 2), new GasStack(GasRegistry.getGas("hydrogen"), 2), new GasStack(GasRegistry.getGas("oxygen"), 1));
RecipeHandler.addElectrolyticSeparatorRecipe(FluidRegistry.getFluidStack("brine", 10), new GasStack(GasRegistry.getGas("sodium"), 1), new GasStack(GasRegistry.getGas("chlorine"), 1));
RecipeHandler.addElectrolyticSeparatorRecipe(FluidRegistry.getFluidStack("water", 2), 2 * general.FROM_H2, new GasStack(GasRegistry.getGas("hydrogen"), 2), new GasStack(GasRegistry.getGas("oxygen"), 1));
RecipeHandler.addElectrolyticSeparatorRecipe(FluidRegistry.getFluidStack("brine", 10), 2 * general.FROM_H2, new GasStack(GasRegistry.getGas("sodium"), 1), new GasStack(GasRegistry.getGas("chlorine"), 1));
//T4 Processing Recipes
for(Gas gas : GasRegistry.getRegisteredGasses())

View file

@ -2,13 +2,17 @@ package mekanism.common.base;
import java.util.Map;
import mekanism.common.recipe.inputs.MachineInput;
import mekanism.common.recipe.machines.MachineRecipe;
import mekanism.common.recipe.outputs.MachineOutput;
/**
* Internal interface containing methods that are shared by many core Mekanism machines. TODO: remove next minor MC
* version.
* @author AidanBrady
*
*/
public interface IElectricMachine
public interface IElectricMachine<INPUT extends MachineInput<INPUT>, OUTPUT extends MachineOutput<OUTPUT>, RECIPE extends MachineRecipe<INPUT, OUTPUT, RECIPE>>
{
/**
* Update call for machines. Use instead of updateEntity() - it's called every tick.
@ -19,15 +23,19 @@ public interface IElectricMachine
* Whether or not this machine can operate.
* @return can operate
*/
public boolean canOperate();
public boolean canOperate(RECIPE recipe);
/**
* Runs this machine's operation -- or smelts the item.
*/
public void operate();
public void operate(RECIPE recipe);
/**
* Gets this machine's recipes.
*/
public Map getRecipes();
public Map<INPUT, RECIPE> getRecipes();
public RECIPE getRecipe();
public INPUT getInput();
}

View file

@ -9,6 +9,13 @@ import mekanism.api.util.StackUtils;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.recipe.RecipeHandler;
import mekanism.common.recipe.RecipeHandler.Recipe;
import mekanism.common.recipe.inputs.ItemStackInput;
import mekanism.common.recipe.inputs.MachineInput;
import mekanism.common.recipe.machines.AdvancedMachineRecipe;
import mekanism.common.recipe.machines.BasicMachineRecipe;
import mekanism.common.recipe.machines.MachineRecipe;
import mekanism.common.recipe.outputs.ItemStackOutput;
import mekanism.common.recipe.outputs.MachineOutput;
import mekanism.common.tile.TileEntityAdvancedElectricMachine;
import mekanism.common.util.MekanismUtils;
@ -56,37 +63,38 @@ public interface IFactory
private Recipe recipe;
private TileEntityAdvancedElectricMachine cacheTile;
public ItemStack getCopiedOutput(ItemStack input, Gas gas, boolean stackDecrease)
public BasicMachineRecipe getRecipe(ItemStackInput input)
{
if(input == null)
{
return null;
}
if(this == SMELTING)
{
if(FurnaceRecipes.smelting().getSmeltingResult(input) != null)
{
ItemStack toReturn = FurnaceRecipes.smelting().getSmeltingResult(input).copy();
if(stackDecrease)
{
input.stackSize--;
}
return toReturn;
}
return null;
}
return RecipeHandler.getRecipe(input, recipe.get());
}
public BasicMachineRecipe getRecipe(ItemStack input)
{
return getRecipe(new ItemStackInput(input));
}
public AdvancedMachineRecipe getRecipe(AdvancedMachineInput input)
{
return RecipeHandler.getRecipe(input, recipe.get());
}
public AdvancedMachineRecipe getRecipe(ItemStack input, Gas gas)
{
return getRecipe(new AdvancedMachineInput(input, gas));
}
public MachineRecipe getAnyRecipe(ItemStack slotStack, Gas gasType)
{
if(usesFuel())
{
return RecipeHandler.getOutput(new AdvancedMachineInput(input, gas), stackDecrease, recipe.get());
}
else {
return RecipeHandler.getOutput(input, stackDecrease, recipe.get());
return getRecipe(slotStack,gasType);
}
return getRecipe(slotStack);
}
public GasStack getItemGas(ItemStack itemstack)

View file

@ -923,7 +923,7 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds, IPer
if(tileEntity instanceof TileEntityFactory)
{
IFactory factoryItem = (IFactory)itemStack.getItem();
factoryItem.setRecipeType(((TileEntityFactory)tileEntity).recipeType, itemStack);
factoryItem.setRecipeType(((TileEntityFactory)tileEntity).recipeType.ordinal(), itemStack);
}
return itemStack;

View file

@ -3,6 +3,7 @@ package mekanism.common.inventory.container;
import mekanism.common.inventory.slot.SlotEnergy.SlotDischarge;
import mekanism.common.inventory.slot.SlotOutput;
import mekanism.common.recipe.RecipeHandler;
import mekanism.common.recipe.inputs.ItemStackInput;
import mekanism.common.tile.TileEntityChanceMachine;
import mekanism.common.util.ChargeUtils;
@ -92,7 +93,7 @@ public class ContainerChanceMachine extends Container
}
}
}
else if(RecipeHandler.getChanceOutput(slotStack, false, tileEntity.getRecipes()) != null)
else if(RecipeHandler.getChanceRecipe(new ItemStackInput(slotStack), tileEntity.getRecipes()) != null)
{
if(slotID != 0 && slotID != 1 && slotID != 2 && slotID != 3)
{

View file

@ -4,7 +4,7 @@ import mekanism.api.gas.IGasItem;
import mekanism.common.inventory.slot.SlotEnergy.SlotDischarge;
import mekanism.common.inventory.slot.SlotStorageTank;
import mekanism.common.recipe.RecipeHandler;
import mekanism.common.recipe.RecipeHandler.Recipe;
import mekanism.common.recipe.inputs.ItemStackInput;
import mekanism.common.tile.TileEntityChemicalDissolutionChamber;
import mekanism.common.util.ChargeUtils;
@ -71,7 +71,7 @@ public class ContainerChemicalDissolutionChamber extends Container
ItemStack slotStack = currentSlot.getStack();
stack = slotStack.copy();
if(RecipeHandler.getDissolutionOutput(slotStack, false) != null)
if(RecipeHandler.getDissolutionRecipe(new ItemStackInput(slotStack)) != null)
{
if(slotID != 1)
{

View file

@ -4,7 +4,7 @@ import mekanism.api.gas.IGasItem;
import mekanism.common.inventory.slot.SlotEnergy.SlotDischarge;
import mekanism.common.inventory.slot.SlotStorageTank;
import mekanism.common.recipe.RecipeHandler;
import mekanism.common.recipe.RecipeHandler.Recipe;
import mekanism.common.recipe.inputs.ItemStackInput;
import mekanism.common.tile.TileEntityChemicalOxidizer;
import mekanism.common.util.ChargeUtils;
@ -70,7 +70,7 @@ public class ContainerChemicalOxidizer extends Container
ItemStack slotStack = currentSlot.getStack();
stack = slotStack.copy();
if(RecipeHandler.getOxidizerOutput(slotStack, false) != null)
if(RecipeHandler.getOxidizerRecipe(new ItemStackInput(slotStack)) != null)
{
if(slotID != 0)
{

View file

@ -3,6 +3,7 @@ package mekanism.common.inventory.container;
import mekanism.common.inventory.slot.SlotEnergy.SlotDischarge;
import mekanism.common.inventory.slot.SlotOutput;
import mekanism.common.recipe.RecipeHandler;
import mekanism.common.recipe.inputs.ItemStackInput;
import mekanism.common.tile.TileEntityElectricMachine;
import mekanism.common.util.ChargeUtils;
@ -74,7 +75,7 @@ public class ContainerElectricMachine extends Container
return null;
}
}
else if(RecipeHandler.getOutput(slotStack, false, tileEntity.getRecipes()) != null)
else if(RecipeHandler.getRecipe(new ItemStackInput(slotStack), tileEntity.getRecipes()) != null)
{
if(slotID != 0 && slotID != 1 && slotID != 2)
{

View file

@ -143,7 +143,7 @@ public class ContainerFactory extends Container
return null;
}
}
else if(RecipeType.values()[tileEntity.recipeType].getCopiedOutput(slotStack, tileEntity.gasTank.getGas() != null ? tileEntity.gasTank.getGas().getGas() : null, false) != null)
else if(tileEntity.recipeType.getAnyRecipe(slotStack, tileEntity.gasTank.getGasType()) != null)
{
if(!isInputSlot(slotID))
{
@ -176,7 +176,7 @@ public class ContainerFactory extends Container
}
}
}
else if(RecipeType.values()[tileEntity.recipeType].getItemGas(slotStack) != null)
else if(tileEntity.recipeType.getItemGas(slotStack) != null)
{
if(slotID > tileEntity.inventory.length-1)
{

View file

@ -73,7 +73,7 @@ public class ContainerMetallurgicInfuser extends Container
if(slotID != 0 && slotID != 1 && slotID != 2 && slotID != 3)
{
if(InfuseRegistry.getObject(slotStack) != null && (tileEntity.type == null || tileEntity.type == InfuseRegistry.getObject(slotStack).type))
if(InfuseRegistry.getObject(slotStack) != null && (tileEntity.infuseStored.type == null || tileEntity.infuseStored.type == InfuseRegistry.getObject(slotStack).type))
{
if(!mergeItemStack(slotStack, 1, 2, false))
{
@ -145,9 +145,9 @@ public class ContainerMetallurgicInfuser extends Container
public boolean isInputItem(ItemStack itemStack)
{
if(tileEntity.type != null)
if(tileEntity.infuseStored.type != null)
{
if(RecipeHandler.getMetallurgicInfuserOutput(InfusionInput.getInfusion(tileEntity.type, tileEntity.infuseStored, itemStack), false) != null)
if(RecipeHandler.getMetallurgicInfuserRecipe(new InfusionInput(tileEntity.infuseStored, itemStack)) != null)
{
return true;
}

View file

@ -298,7 +298,7 @@ public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, ISpec
if(tileEntity instanceof TileEntityFactory)
{
((TileEntityFactory)tileEntity).recipeType = getRecipeType(stack);
((TileEntityFactory)tileEntity).recipeType = RecipeType.values()[getRecipeType(stack)];
world.notifyBlocksOfNeighborChange(x, y, z, tileEntity.getBlockType());
}

View file

@ -7,6 +7,7 @@ import java.util.Set;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasTank;
import mekanism.api.infuse.InfuseType;
import mekanism.api.util.StackUtils;
import mekanism.common.recipe.inputs.AdvancedMachineInput;
import mekanism.common.recipe.inputs.ChemicalPairInput;
import mekanism.common.recipe.inputs.FluidInput;
@ -15,12 +16,7 @@ import mekanism.common.recipe.inputs.InfusionInput;
import mekanism.common.recipe.inputs.IntegerInput;
import mekanism.common.recipe.inputs.ItemStackInput;
import mekanism.common.recipe.inputs.MachineInput;
import mekanism.common.recipe.inputs.PressurizedReactants;
import mekanism.common.recipe.outputs.ChanceOutput;
import mekanism.common.recipe.outputs.ChemicalPairOutput;
import mekanism.common.recipe.outputs.InfusionOutput;
import mekanism.common.recipe.outputs.MachineOutput;
import mekanism.api.util.StackUtils;
import mekanism.common.recipe.inputs.PressurizedInput;
import mekanism.common.recipe.machines.AdvancedMachineRecipe;
import mekanism.common.recipe.machines.AmbientGasRecipe;
import mekanism.common.recipe.machines.BasicMachineRecipe;
@ -45,11 +41,10 @@ import mekanism.common.recipe.machines.WasherRecipe;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
/**
* Class used to handle machine recipes. This is used for both adding recipes and checking outputs.
* @author AidanBrady
* Class used to handle machine recipes. This is used for both adding and fetching recipes.
* @author AidanBrady, unpairedbracket
*
*/
public final class RecipeHandler
@ -158,9 +153,9 @@ public final class RecipeHandler
* @param leftOutput - left gas to produce when the fluid is electrolyzed
* @param rightOutput - right gas to produce when the fluid is electrolyzed
*/
public static void addElectrolyticSeparatorRecipe(FluidStack fluid, GasStack leftOutput, GasStack rightOutput)
public static void addElectrolyticSeparatorRecipe(FluidStack fluid, double energy, GasStack leftOutput, GasStack rightOutput)
{
addRecipe(Recipe.ELECTROLYTIC_SEPARATOR, new SeparatorRecipe(fluid, leftOutput, rightOutput));
addRecipe(Recipe.ELECTROLYTIC_SEPARATOR, new SeparatorRecipe(fluid, energy, leftOutput, rightOutput));
}
/**
@ -236,370 +231,216 @@ public final class RecipeHandler
}
/**
* Gets the InfusionOutput of the InfusionInput in the parameters.
* @param infusion - input Infusion
* @param stackDecrease - whether or not to decrease the input slot's stack size AND the infuse amount
* @return InfusionOutput
* Gets the Metallurgic Infuser Recipe for the InfusionInput in the parameters.
* @param input - input Infusion
* @return MetallurgicInfuserRecipe
*/
public static InfusionOutput getMetallurgicInfuserOutput(InfusionInput infusion, boolean stackDecrease)
public static MetallurgicInfuserRecipe getMetallurgicInfuserRecipe(InfusionInput input)
{
if(infusion != null && infusion.inputStack != null)
if(input.isValid())
{
HashMap<InfusionInput, MetallurgicInfuserRecipe> recipes = Recipe.METALLURGIC_INFUSER.get();
MetallurgicInfuserRecipe recipe = recipes.get(infusion);
if(recipe != null)
{
if(StackUtils.equalsWildcard(recipe.getInput().inputStack, infusion.inputStack) && infusion.inputStack.stackSize >= recipe.getInput().inputStack.stackSize)
{
if(infusion.infusionType == recipe.getInput().infusionType)
{
if(stackDecrease)
{
infusion.inputStack.stackSize -= recipe.getInput().inputStack.stackSize;
}
return recipe.getOutput().copy();
}
}
}
MetallurgicInfuserRecipe recipe = recipes.get(input);
return recipe == null ? null : recipe.copy();
}
return null;
}
/**
* Gets the GasStack of the ChemicalInput in the parameters.
* @param leftTank - first GasTank
* @param rightTank - second GasTank
* @param doRemove - actually remove the gases
* @return output GasStack
* Gets the Chemical Infuser Recipe of the ChemicalPairInput in the parameters.
* @param input - the pair of gases to infuse
* @return ChemicalInfuserRecipe
*/
public static GasStack getChemicalInfuserOutput(GasTank leftTank, GasTank rightTank, boolean doRemove)
public static ChemicalInfuserRecipe getChemicalInfuserRecipe(ChemicalPairInput input)
{
ChemicalPairInput input = new ChemicalPairInput(leftTank.getGas(), rightTank.getGas());
if(input.isValid())
{
HashMap<ChemicalPairInput, ChemicalInfuserRecipe> recipes = Recipe.CHEMICAL_INFUSER.get();
ChemicalInfuserRecipe recipe = recipes.get(input);
if(recipe != null)
{
ChemicalPairInput required = recipe.getInput();
if(required.meetsInput(input))
{
if(doRemove)
{
required.draw(leftTank, rightTank);
}
return recipe.getOutput().output.copy();
}
}
return recipe == null ? null : recipe.copy();
}
return null;
}
/**
* Gets the Chemical Crystallizer ItemStack output of the defined GasTank input.
* @param gasTank - input GasTank
* @param removeGas - whether or not to use gas in the gas tank
* @return output ItemStack
* Gets the Chemical Crystallizer Recipe for the defined Gas input.
* @param input - GasInput
* @return CrystallizerRecipe
*/
public static ItemStack getChemicalCrystallizerOutput(GasTank gasTank, boolean removeGas)
public static CrystallizerRecipe getChemicalCrystallizerRecipe(GasInput input)
{
GasInput input = new GasInput(gasTank.getGas());
if(input.ingredient != null)
if(input.isValid())
{
HashMap<GasInput, CrystallizerRecipe> recipes = Recipe.CHEMICAL_CRYSTALLIZER.get();
CrystallizerRecipe recipe = recipes.get(input);
if(recipe != null)
{
GasStack key = recipe.getInput().ingredient;
if(key != null && key.getGas() == input.ingredient.getGas() && input.ingredient.amount >= key.amount)
{
gasTank.draw(key.amount, removeGas);
return recipe.getOutput().output.copy();
}
}
return recipe == null ? null : recipe.copy();
}
return null;
}
/**
* Gets the Chemical Washer GasStack output of the defined GasTank input.
* @param gasTank - input GasTank
* @param removeGas - whether or not to use gas in the gas tank
* @return output GasStack
* Gets the Chemical Washer Recipe for the defined Gas input.
* @param input - GasInput
* @return WasherRecipe
*/
public static GasStack getChemicalWasherOutput(GasTank gasTank, boolean removeGas)
public static WasherRecipe getChemicalWasherRecipe(GasInput input)
{
GasInput input = new GasInput(gasTank.getGas());
if(input.ingredient != null)
if(input.isValid())
{
HashMap<GasInput, WasherRecipe> recipes = Recipe.CHEMICAL_WASHER.get();
WasherRecipe recipe = recipes.get(input);
if(recipe != null)
{
GasStack key = recipe.getInput().ingredient;
if(key != null && key.getGas() == input.ingredient.getGas() && input.ingredient.amount >= key.amount)
{
gasTank.draw(key.amount, removeGas);
return recipe.getOutput().output.copy();
}
}
return recipe == null ? null : recipe.copy();
}
return null;
}
/**
* Gets the GasStack of the ItemStack in the parameters using a defined map.
* @param itemstack - input ItemStack
* @param stackDecrease - whether or not to decrease the input slot's stack size
* @return output GasStack
* Gets the Chemical Dissolution Chamber of the ItemStackInput in the parameters
* @param input - ItemStackInput
* @return DissolutionRecipe
*/
public static GasStack getDissolutionOutput(ItemStack itemstack, boolean stackDecrease)
public static DissolutionRecipe getDissolutionRecipe(ItemStackInput input)
{
if(itemstack != null)
if(input.isValid())
{
HashMap<ItemStackInput, DissolutionRecipe> recipes = Recipe.CHEMICAL_DISSOLUTION_CHAMBER.get();
DissolutionRecipe recipe = getRecipeTryWildcard(itemstack, recipes);
if(recipe != null)
{
ItemStack stack = recipe.getInput().ingredient;
if(StackUtils.equalsWildcard(stack, itemstack) && itemstack.stackSize >= stack.stackSize)
{
if(stackDecrease)
{
itemstack.stackSize -= stack.stackSize;
}
return recipe.getOutput().output.copy();
}
}
DissolutionRecipe recipe = getRecipeTryWildcard(input, recipes);
return recipe == null ? null : recipe.copy();
}
return null;
}
/**
* Gets the GasStack of the ItemStack in the parameters using a defined map.
* @param itemstack - input ItemStack
* @param stackDecrease - whether or not to decrease the input slot's stack size
* @return output GasStack
* Gets the Chemical Oxidizer Recipe for the ItemStackInput in the parameters.
* @param input - ItemStackInput
* @return OxidationRecipe
*/
public static GasStack getOxidizerOutput(ItemStack itemstack, boolean stackDecrease)
public static OxidationRecipe getOxidizerRecipe(ItemStackInput input)
{
if(itemstack != null)
if(input.isValid())
{
HashMap<ItemStackInput, OxidationRecipe> recipes = Recipe.CHEMICAL_OXIDIZER.get();
OxidationRecipe recipe = getRecipeTryWildcard(itemstack, recipes);
if(recipe != null)
{
ItemStack stack = recipe.getInput().ingredient;
if(StackUtils.equalsWildcard(stack, itemstack) && itemstack.stackSize >= stack.stackSize)
{
if(stackDecrease)
{
itemstack.stackSize -= stack.stackSize;
}
return recipe.getOutput().output.copy();
}
}
OxidationRecipe recipe = getRecipeTryWildcard(input, recipes);
return recipe == null ? null : recipe.copy();
}
return null;
}
/**
* Gets the output ChanceOutput of the ItemStack in the parameters.
* @param itemstack - input ItemStack
* @param stackDecrease - whether or not to decrease the input slot's stack size
* Gets the ChanceMachineRecipe of the ItemStackInput in the parameters, using the map in the parameters.
* @param input - ItemStackInput
* @param recipes - Map of recipes
* @return output ChanceOutput
* @return ChanceRecipe
*/
public static ChanceOutput getChanceOutput(ItemStack itemstack, boolean stackDecrease, Map<ItemStackInput, ? extends ChanceMachineRecipe> recipes)
public static <RECIPE extends ChanceMachineRecipe<RECIPE>> RECIPE getChanceRecipe(ItemStackInput input, Map<ItemStackInput, RECIPE> recipes)
{
if(itemstack != null)
if(input.isValid())
{
ChanceMachineRecipe recipe = getRecipeTryWildcard(itemstack, recipes);
if(recipe != null)
{
ItemStack stack = recipe.getInput().ingredient;
if(StackUtils.equalsWildcard(stack, itemstack) && itemstack.stackSize >= stack.stackSize)
{
if(stackDecrease)
{
itemstack.stackSize -= stack.stackSize;
}
return recipe.getOutput().copy();
}
}
RECIPE recipe = getRecipeTryWildcard(input, recipes);
return recipe == null ? null : recipe.copy();
}
return null;
}
/**
* Gets the output ItemStack of the ItemStack in the parameters.
* @param itemstack - input ItemStack
* @param stackDecrease - whether or not to decrease the input slot's stack size
* Gets the BasicMachineRecipe of the ItemStackInput in the parameters, using the map in the parameters.
* @param input - ItemStackInput
* @param recipes - Map of recipes
* @return output ItemStack
* @return BasicMachineRecipe
*/
public static ItemStack getOutput(ItemStack itemstack, boolean stackDecrease, Map<ItemStackInput, ? extends BasicMachineRecipe> recipes)
public static <RECIPE extends BasicMachineRecipe<RECIPE>> RECIPE getRecipe(ItemStackInput input, Map<ItemStackInput, RECIPE> recipes)
{
if(itemstack != null)
if(input.isValid())
{
BasicMachineRecipe recipe = getRecipeTryWildcard(itemstack, recipes);
if(recipe != null)
{
ItemStack stack = recipe.getInput().ingredient;
if(StackUtils.equalsWildcard(stack, itemstack) && itemstack.stackSize >= stack.stackSize)
{
if(stackDecrease)
{
itemstack.stackSize -= stack.stackSize;
}
return recipe.getOutput().output.copy();
}
}
RECIPE recipe = getRecipeTryWildcard(input, recipes);
return recipe == null ? null : recipe.copy();
}
return null;
}
/**
* Gets the output ItemStack of the AdvancedInput in the parameters.
* @param input - input AdvancedInput
* @param stackDecrease - whether or not to decrease the input slot's stack size
* Gets the AdvancedMachineRecipe of the AdvancedInput in the parameters, using the map in the paramaters.
* @param input - AdvancedInput
* @param recipes - Map of recipes
* @return output ItemStack
* @return AdvancedMachineRecipe
*/
public static ItemStack getOutput(AdvancedMachineInput input, boolean stackDecrease, Map<AdvancedMachineInput, ? extends AdvancedMachineRecipe> recipes)
public static <RECIPE extends AdvancedMachineRecipe<RECIPE>> RECIPE getRecipe(AdvancedMachineInput input, Map<AdvancedMachineInput, RECIPE> recipes)
{
if(input != null && input.isValid())
if(input.isValid())
{
AdvancedMachineRecipe recipe = recipes.get(input);
if(recipe != null && recipe.getInput().matches(input))
{
if(stackDecrease)
{
input.itemStack.stackSize -= recipe.getInput().itemStack.stackSize;
}
return recipe.getOutput().output.copy();
}
RECIPE recipe = recipes.get(input);
return recipe == null ? null : recipe.copy();
}
return null;
}
/**
* Get the result of electrolysing a given fluid
* @param fluidTank - the FluidTank to electrolyse fluid from
* Get the Electrolytic Separator Recipe corresponding to electrolysing a given fluid.
* @param input - the FluidInput to electrolyse fluid from
* @return SeparatorRecipe
*/
public static ChemicalPairOutput getElectrolyticSeparatorOutput(FluidTank fluidTank, boolean doRemove)
public static SeparatorRecipe getElectrolyticSeparatorRecipe(FluidInput input)
{
FluidStack fluid = fluidTank.getFluid();
if(fluid != null)
if(input.isValid())
{
FluidInput input = new FluidInput(fluid);
HashMap<FluidInput, SeparatorRecipe> recipes = Recipe.ELECTROLYTIC_SEPARATOR.get();
SeparatorRecipe recipe = recipes.get(input);
if(recipe != null)
{
FluidStack key = recipe.getInput().ingredient;
if(fluid.containsFluid(key))
{
fluidTank.drain(key.amount, doRemove);
return recipe.getOutput().copy();
}
}
return recipe == null ? null : recipe.copy();
}
return null;
}
public static PressurizedRecipe getPRCOutput(ItemStack inputItem, FluidTank inputFluidTank, GasTank inputGasTank)
public static PressurizedRecipe getPRCRecipe(PressurizedInput input)
{
FluidStack inputFluid = inputFluidTank.getFluid();
GasStack inputGas = inputGasTank.getGas();
if(inputItem != null && inputFluid != null && inputGas != null)
if(input.isValid())
{
PressurizedReactants input = new PressurizedReactants(inputItem, inputFluid, inputGas);
HashMap<PressurizedReactants, PressurizedRecipe> recipes = Recipe.PRESSURIZED_REACTION_CHAMBER.get();
HashMap<PressurizedInput, PressurizedRecipe> recipes = Recipe.PRESSURIZED_REACTION_CHAMBER.get();
PressurizedRecipe recipe = recipes.get(input);
if(recipe.getInput().meets(input))
{
return recipe.copy();
}
return recipe == null ? null : recipe.copy();
}
return null;
}
public static GasStack getDimensionGas(Integer dimensionID)
public static AmbientGasRecipe getDimensionGas(IntegerInput input)
{
HashMap<IntegerInput, AmbientGasRecipe> recipes = Recipe.AMBIENT_ACCUMULATOR.get();
return recipes.get(new IntegerInput(dimensionID)).getOutput().output;
AmbientGasRecipe recipe = recipes.get(input);
return recipe == null ? null : recipe.copy();
}
/**
* Gets the output ItemStack of the ItemStack in the parameters.
* Gets the whether the input ItemStack is in a recipe
* @param itemstack - input ItemStack
* @param recipes - Map of recipes
* @return whether the item can be used in a recipe
*/
public static boolean isInRecipe(ItemStack itemstack, Map<ItemStack, ItemStack> recipes)
public static <RECIPE extends MachineRecipe<ItemStackInput, ?, RECIPE>> boolean isInRecipe(ItemStack itemstack, Map<ItemStackInput, RECIPE> recipes)
{
if(itemstack != null)
{
for(Map.Entry entry : recipes.entrySet())
for(RECIPE recipe : recipes.values())
{
ItemStack stack = (ItemStack)entry.getKey();
ItemStackInput required = recipe.getInput();
if(StackUtils.equalsWildcard(stack, itemstack))
if(required.useItemStackFromInventory(new ItemStack[]{itemstack}, 0, false))
{
return true;
}
@ -613,7 +454,7 @@ public final class RecipeHandler
{
if(stack != null)
{
for(PressurizedReactants key : (Set<PressurizedReactants>)Recipe.PRESSURIZED_REACTION_CHAMBER.get().keySet())
for(PressurizedInput key : (Set<PressurizedInput>)Recipe.PRESSURIZED_REACTION_CHAMBER.get().keySet())
{
if(key.containsType(stack))
{
@ -625,9 +466,13 @@ public final class RecipeHandler
return false;
}
public static <RECIPE extends MachineRecipe<ItemStackInput, ?>> RECIPE getRecipeTryWildcard(ItemStack stack, Map<ItemStackInput, RECIPE> recipes)
public static <RECIPE extends MachineRecipe<ItemStackInput, ?, RECIPE>> RECIPE getRecipeTryWildcard(ItemStack stack, Map<ItemStackInput, RECIPE> recipes)
{
return getRecipeTryWildcard(new ItemStackInput(stack), recipes);
}
public static <RECIPE extends MachineRecipe<ItemStackInput, ?, RECIPE>> RECIPE getRecipeTryWildcard(ItemStackInput input, Map<ItemStackInput, RECIPE> recipes)
{
ItemStackInput input = new ItemStackInput(stack);
RECIPE recipe = recipes.get(input);
if(recipe == null)
{
@ -652,17 +497,17 @@ public final class RecipeHandler
CHEMICAL_DISSOLUTION_CHAMBER(new HashMap<ItemStackInput, DissolutionRecipe>()),
CHEMICAL_WASHER(new HashMap<GasInput, WasherRecipe>()),
CHEMICAL_CRYSTALLIZER(new HashMap<GasInput, CrystallizerRecipe>()),
PRESSURIZED_REACTION_CHAMBER(new HashMap<PressurizedReactants, PressurizedRecipe>()),
PRESSURIZED_REACTION_CHAMBER(new HashMap<PressurizedInput, PressurizedRecipe>()),
AMBIENT_ACCUMULATOR(new HashMap<IntegerInput, AmbientGasRecipe>());
private HashMap recipes;
private Recipe(HashMap<? extends MachineInput, ? extends MachineRecipe> map)
private <INPUT extends MachineInput<INPUT>, RECIPE extends MachineRecipe<INPUT, ?, RECIPE>> Recipe(HashMap<INPUT, RECIPE> map)
{
recipes = map;
}
public void put(MachineRecipe<? extends MachineInput, ? extends MachineOutput> recipe)
public <RECIPE extends MachineRecipe<?, ?, RECIPE>>void put(RECIPE recipe)
{
recipes.put(recipe.getInput(), recipe);
}

View file

@ -1,11 +1,12 @@
package mekanism.common.recipe.inputs;
import mekanism.api.gas.Gas;
import mekanism.api.gas.GasTank;
import mekanism.api.util.StackUtils;
import net.minecraft.item.ItemStack;
public class AdvancedMachineInput extends MachineInput
public class AdvancedMachineInput extends MachineInput<AdvancedMachineInput>
{
public ItemStack itemStack;
@ -17,11 +18,41 @@ public class AdvancedMachineInput extends MachineInput
gasType = gas;
}
@Override
public AdvancedMachineInput copy()
{
return new AdvancedMachineInput(itemStack.copy(), gasType);
}
@Override
public boolean isValid()
{
return itemStack != null && gasType != null;
}
public boolean useItem(ItemStack[] inventory, int index, boolean deplete)
{
if(StackUtils.contains(inventory[index], itemStack))
{
if(deplete)
{
inventory[index] = StackUtils.subtract(inventory[index], itemStack);
}
return true;
}
return false;
}
public boolean useSecondary(GasTank gasTank, int amountToUse, boolean deplete)
{
if(gasTank.getGasType() == gasType && gasTank.getStored() >= amountToUse)
{
gasTank.draw(amountToUse, deplete);
return true;
}
return false;
}
public boolean matches(AdvancedMachineInput input)
{
return StackUtils.equalsWildcard(itemStack, input.itemStack) && input.itemStack.stackSize >= itemStack.stackSize;
@ -30,12 +61,19 @@ public class AdvancedMachineInput extends MachineInput
@Override
public int hashIngredients()
{
return StackUtils.hashItemStack(itemStack) << 8 | gasType.getID();
int hash = StackUtils.hashItemStack(itemStack) << 8 | gasType.getID();
return hash;
}
@Override
public boolean testEquality(MachineInput other)
public boolean testEquality(AdvancedMachineInput other)
{
return other instanceof AdvancedMachineInput && StackUtils.equalsWildcardWithNBT(itemStack, ((AdvancedMachineInput)other).itemStack) && gasType.getID() == ((AdvancedMachineInput)other).gasType.getID();
return StackUtils.equalsWildcardWithNBT(itemStack, other.itemStack) && gasType.getID() == other.gasType.getID();
}
@Override
public boolean isInstance(Object other)
{
return other instanceof AdvancedMachineInput;
}
}

View file

@ -8,7 +8,7 @@ import mekanism.api.gas.GasTank;
* @author aidancbrady
*
*/
public class ChemicalPairInput extends MachineInput
public class ChemicalPairInput extends MachineInput<ChemicalPairInput>
{
/** The left gas of this chemical input */
public GasStack leftGas;
@ -27,10 +27,33 @@ public class ChemicalPairInput extends MachineInput
rightGas = right;
}
public boolean useGas(GasTank leftTank, GasTank rightTank, boolean deplete)
{
if(leftTank.canDraw(leftGas.getGas()) && rightTank.canDraw(rightGas.getGas()))
{
if(leftTank.getStored() >= leftGas.amount && rightTank.getStored() >= rightGas.amount)
{
leftTank.draw(leftGas.amount, deplete);
rightTank.draw(rightGas.amount, deplete);
return true;
}
} else if(leftTank.canDraw(rightGas.getGas()) && rightTank.canDraw(leftGas.getGas()))
{
if(leftTank.getStored() >= rightGas.amount && rightTank.getStored() >= leftGas.amount)
{
leftTank.draw(rightGas.amount, deplete);
rightTank.draw(leftGas.amount, deplete);
return true;
}
}
return false;
}
/**
* If this is a valid ChemicalPair
* @return
*/
@Override
public boolean isValid()
{
return leftGas != null && rightGas != null;
@ -109,6 +132,7 @@ public class ChemicalPairInput extends MachineInput
return input.leftGas.amount >= leftGas.amount && input.rightGas.amount >= rightGas.amount;
}
@Override
public ChemicalPairInput copy()
{
return new ChemicalPairInput(leftGas.copy(), rightGas.copy());
@ -121,14 +145,15 @@ public class ChemicalPairInput extends MachineInput
}
@Override
public boolean testEquality(MachineInput other)
public boolean testEquality(ChemicalPairInput other)
{
if(other instanceof ChemicalPairInput)
{
int leftID = ((ChemicalPairInput)other).leftGas.hashCode();
int rightID = ((ChemicalPairInput)other).rightGas.hashCode();
return (leftID == leftGas.hashCode() && rightID == rightGas.hashCode()) || (leftID == rightGas.hashCode() && rightID == leftGas.hashCode());
}
return false;
return (other.leftGas.hashCode() == leftGas.hashCode() && other.rightGas.hashCode() == rightGas.hashCode())
|| (other.leftGas.hashCode() == rightGas.hashCode() && other.rightGas.hashCode() == leftGas.hashCode());
}
@Override
public boolean isInstance(Object other)
{
return other instanceof ChemicalPairInput;
}
}

View file

@ -1,8 +1,9 @@
package mekanism.common.recipe.inputs;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
public class FluidInput extends MachineInput
public class FluidInput extends MachineInput<FluidInput>
{
public FluidStack ingredient;
@ -11,6 +12,28 @@ public class FluidInput extends MachineInput
ingredient = stack;
}
@Override
public FluidInput copy()
{
return new FluidInput(ingredient.copy());
}
@Override
public boolean isValid()
{
return ingredient != null;
}
public boolean useFluid(FluidTank fluidTank, boolean deplete)
{
if(fluidTank.getFluid().containsFluid(ingredient))
{
fluidTank.drain(ingredient.amount, deplete);
return true;
}
return false;
}
@Override
public int hashIngredients()
{
@ -18,8 +41,14 @@ public class FluidInput extends MachineInput
}
@Override
public boolean testEquality(MachineInput other)
public boolean testEquality(FluidInput other)
{
return other instanceof FluidInput && ingredient.equals(((FluidInput)other).ingredient);
return ingredient.equals(other.ingredient);
}
@Override
public boolean isInstance(Object other)
{
return other instanceof FluidInput;
}
}

View file

@ -1,8 +1,9 @@
package mekanism.common.recipe.inputs;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasTank;
public class GasInput extends MachineInput
public class GasInput extends MachineInput<GasInput>
{
public GasStack ingredient;
@ -11,6 +12,28 @@ public class GasInput extends MachineInput
ingredient = stack;
}
@Override
public GasInput copy()
{
return new GasInput(ingredient.copy());
}
@Override
public boolean isValid()
{
return ingredient != null;
}
public boolean useGas(GasTank gasTank, boolean deplete)
{
if(gasTank.getGasType() == ingredient.getGas() && gasTank.getStored() >= ingredient.amount)
{
gasTank.draw(ingredient.amount, deplete);
return true;
}
return false;
}
@Override
public int hashIngredients()
{
@ -18,8 +41,14 @@ public class GasInput extends MachineInput
}
@Override
public boolean testEquality(MachineInput other)
public boolean testEquality(GasInput other)
{
return other instanceof GasInput && ((GasInput)other).ingredient.hashCode() == ingredient.hashCode();
return other.ingredient.hashCode() == ingredient.hashCode();
}
@Override
public boolean isInstance(Object other)
{
return other instanceof GasInput;
}
}

View file

@ -1,52 +1,78 @@
package mekanism.common.recipe.inputs;
import mekanism.api.gas.GasTank;
import mekanism.api.infuse.InfuseType;
import mekanism.api.util.StackUtils;
import mekanism.common.InfuseStorage;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidTank;
/**
* An infusion input, containing the type of and amount of infuse the operation requires, as well as the input ItemStack.
* @author AidanBrady
*
*/
public class InfusionInput extends MachineInput
public class InfusionInput extends MachineInput<InfusionInput>
{
/** The type of this infusion */
public InfuseType infusionType;
/** How much infuse it takes to perform this operation */
public int infuseAmount;
public InfuseStorage infuse;
/** The input ItemStack */
public ItemStack inputStack;
public InfusionInput(InfuseType infusiontype, int required, ItemStack itemstack)
public InfusionInput(InfuseStorage storage, ItemStack itemStack)
{
infusionType = infusiontype;
infuseAmount = required;
inputStack = itemstack;
infuse = new InfuseStorage(storage.type, storage.amount);
inputStack = itemStack;
}
public static InfusionInput getInfusion(InfuseType type, int stored, ItemStack itemstack)
public InfusionInput(InfuseType infusionType, int required, ItemStack itemStack)
{
return new InfusionInput(type, stored, itemstack);
infuse = new InfuseStorage(infusionType, required);
inputStack = itemStack;
}
@Override
public InfusionInput copy()
{
return new InfusionInput(infuse.type, infuse.amount, inputStack.copy());
}
@Override
public boolean isValid()
{
return infuse.type != null && inputStack != null;
}
public boolean use(ItemStack[] inventory, int index, InfuseStorage infuseStorage, boolean deplete)
{
if(StackUtils.contains(inventory[index], inputStack) && infuseStorage.contains(infuse))
{
if(deplete)
{
inventory[index] = StackUtils.subtract(inventory[index], inputStack);
infuseStorage.subtract(infuse);
}
return true;
}
return false;
}
@Override
public int hashIngredients()
{
return infusionType.unlocalizedName.hashCode() << 8 | StackUtils.hashItemStack(inputStack);
return infuse.type.unlocalizedName.hashCode() << 8 | StackUtils.hashItemStack(inputStack);
}
@Override
public boolean testEquality(MachineInput other)
public boolean testEquality(InfusionInput other)
{
if(other instanceof InfusionInput)
{
InfusionInput ii = (InfusionInput)other;
return infusionType == ii.infusionType && StackUtils.equalsWildcardWithNBT(inputStack, ii.inputStack);
}
return false;
return infuse.type == other.infuse.type && StackUtils.equalsWildcardWithNBT(inputStack, other.inputStack);
}
@Override
public boolean isInstance(Object other)
{
return other instanceof InfusionInput;
}
}

View file

@ -1,6 +1,6 @@
package mekanism.common.recipe.inputs;
public class IntegerInput extends MachineInput
public class IntegerInput extends MachineInput<IntegerInput>
{
public int ingredient;
@ -9,6 +9,17 @@ public class IntegerInput extends MachineInput
ingredient = integer;
}
@Override
public IntegerInput copy()
{
return new IntegerInput(ingredient);
}
@Override
public boolean isValid()
{
return true;
}
@Override
public int hashIngredients()
@ -17,8 +28,14 @@ public class IntegerInput extends MachineInput
}
@Override
public boolean testEquality(MachineInput other)
public boolean testEquality(IntegerInput other)
{
return other instanceof IntegerInput && ingredient == ((IntegerInput)other).ingredient;
return ingredient == other.ingredient;
}
@Override
public boolean isInstance(Object other)
{
return other instanceof IntegerInput;
}
}

View file

@ -5,7 +5,7 @@ import mekanism.api.util.StackUtils;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
public class ItemStackInput extends MachineInput
public class ItemStackInput extends MachineInput<ItemStackInput>
{
public ItemStack ingredient;
@ -14,11 +14,36 @@ public class ItemStackInput extends MachineInput
ingredient = stack;
}
@Override
public ItemStackInput copy()
{
return new ItemStackInput(ingredient.copy());
}
@Override
public boolean isValid()
{
return ingredient != null;
}
public ItemStackInput wildCopy()
{
return new ItemStackInput(new ItemStack(ingredient.getItem(), ingredient.stackSize, OreDictionary.WILDCARD_VALUE));
}
public boolean useItemStackFromInventory(ItemStack[] inventory, int index, boolean deplete)
{
if(StackUtils.contains(inventory[index], ingredient))
{
if(deplete)
{
inventory[index] = StackUtils.subtract(inventory[index], ingredient);
}
return true;
}
return false;
}
@Override
public int hashIngredients()
{
@ -26,8 +51,14 @@ public class ItemStackInput extends MachineInput
}
@Override
public boolean testEquality(MachineInput other)
public boolean testEquality(ItemStackInput other)
{
return other instanceof ItemStackInput && StackUtils.equalsWildcardWithNBT(ingredient, ((ItemStackInput)other).ingredient);
return StackUtils.equalsWildcardWithNBT(ingredient, other.ingredient);
}
@Override
public boolean isInstance(Object other)
{
return other instanceof ItemStackInput;
}
}

View file

@ -1,7 +1,11 @@
package mekanism.common.recipe.inputs;
public abstract class MachineInput
public abstract class MachineInput<INPUT extends MachineInput<INPUT>>
{
public abstract boolean isValid();
public abstract INPUT copy();
public abstract int hashIngredients();
/**
@ -12,7 +16,7 @@ public abstract class MachineInput
* @param other
* @return
*/
public abstract boolean testEquality(MachineInput other);
public abstract boolean testEquality(INPUT other);
@Override
public int hashCode()
@ -23,12 +27,12 @@ public abstract class MachineInput
@Override
public boolean equals(Object other)
{
if(other instanceof MachineInput)
if(isInstance(other))
{
return testEquality((MachineInput)other);
return testEquality((INPUT)other);
}
return false;
}
public abstract boolean isInstance(Object other);
}

View file

@ -1,5 +1,7 @@
package mekanism.common.recipe.inputs;
import java.util.Stack;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasTank;
import mekanism.api.util.StackUtils;
@ -11,13 +13,13 @@ import net.minecraftforge.fluids.FluidTank;
/**
* An input of a gas, a fluid and an item for the pressurized reaction chamber
*/
public class PressurizedReactants extends MachineInput
public class PressurizedInput extends MachineInput<PressurizedInput>
{
private ItemStack theSolid;
private FluidStack theFluid;
private GasStack theGas;
public PressurizedReactants(ItemStack solid, FluidStack fluid, GasStack gas)
public PressurizedInput(ItemStack solid, FluidStack fluid, GasStack gas)
{
theSolid = solid;
theFluid = fluid;
@ -27,25 +29,25 @@ public class PressurizedReactants extends MachineInput
/**
* If this is a valid PressurizedReactants
*/
@Override
public boolean isValid()
{
return theSolid != null && theFluid != null && theGas != null;
}
/**
* Draws the needed amount of gas from each tank.
* @param item - ItemStack to draw from
* @param fluidTank - fluid tank to draw from
* @param gasTank - gas tank to draw from
*/
public void use(ItemStack item, FluidTank fluidTank, GasTank gasTank)
public boolean use(ItemStack[] inventory, int index, FluidTank fluidTank, GasTank gasTank, boolean deplete)
{
if(meets(new PressurizedReactants(item, fluidTank.getFluid(), gasTank.getGas())))
if(meets(new PressurizedInput(inventory[index], fluidTank.getFluid(), gasTank.getGas())))
{
item.stackSize -= theSolid.stackSize;
fluidTank.drain(theFluid.amount, true);
gasTank.draw(theGas.amount, true);
if(deplete)
{
inventory[index] = StackUtils.subtract(inventory[index], theSolid);
fluidTank.drain(theFluid.amount, true);
gasTank.draw(theGas.amount, true);
}
return true;
}
return false;
}
/**
@ -93,17 +95,12 @@ public class PressurizedReactants extends MachineInput
return stack.isGasEqual(theGas);
}
public boolean meetsInput(ItemStack itemStack, FluidStack fluidStack, GasStack gasStack)
{
return meets(new PressurizedReactants(itemStack, fluidStack, gasStack));
}
/**
* Actual implementation of meetsInput(), performs the checks.
* @param input - input to check
* @return if the input meets this input's requirements
*/
public boolean meets(PressurizedReactants input)
public boolean meets(PressurizedInput input)
{
if(input == null || !input.isValid())
{
@ -118,9 +115,10 @@ public class PressurizedReactants extends MachineInput
return input.theSolid.stackSize >= theSolid.stackSize && input.theFluid.amount >= theFluid.amount && input.theGas.amount >= theGas.amount;
}
public PressurizedReactants copy()
@Override
public PressurizedInput copy()
{
return new PressurizedReactants(theSolid.copy(), theFluid.copy(), theGas.copy());
return new PressurizedInput(theSolid.copy(), theFluid.copy(), theGas.copy());
}
public ItemStack getSolid()
@ -145,13 +143,14 @@ public class PressurizedReactants extends MachineInput
}
@Override
public boolean testEquality(MachineInput other)
public boolean testEquality(PressurizedInput other)
{
if(other instanceof PressurizedReactants)
{
PressurizedReactants pr = (PressurizedReactants)other;
return pr.containsType(theSolid) && pr.containsType(theFluid) && pr.containsType(theGas);
}
return false;
return other.containsType(theSolid) && other.containsType(theFluid) && other.containsType(theGas);
}
@Override
public boolean isInstance(Object other)
{
return other instanceof PressurizedInput;
}
}

View file

@ -2,20 +2,41 @@ package mekanism.common.recipe.machines;
import mekanism.api.gas.Gas;
import mekanism.api.gas.GasRegistry;
import mekanism.api.gas.GasTank;
import mekanism.common.recipe.inputs.AdvancedMachineInput;
import mekanism.common.recipe.outputs.ItemStackOutput;
import mekanism.common.util.MekanismUtils;
import net.minecraft.item.ItemStack;
public class AdvancedMachineRecipe extends MachineRecipe<AdvancedMachineInput, ItemStackOutput>
public abstract class AdvancedMachineRecipe<RECIPE extends AdvancedMachineRecipe<RECIPE>> extends MachineRecipe<AdvancedMachineInput, ItemStackOutput, RECIPE>
{
public AdvancedMachineRecipe(AdvancedMachineInput input, ItemStackOutput output)
{
super(input, output);
}
public AdvancedMachineRecipe(ItemStack input, String gasName, ItemStack output)
{
super(new AdvancedMachineInput(input, GasRegistry.getGas(gasName)), new ItemStackOutput(output));
this(new AdvancedMachineInput(input, GasRegistry.getGas(gasName)), new ItemStackOutput(output));
}
public AdvancedMachineRecipe(ItemStack input, Gas gas, ItemStack output)
{
super(new AdvancedMachineInput(input, gas), new ItemStackOutput(output));
this(new AdvancedMachineInput(input, gas), new ItemStackOutput(output));
}
public boolean canOperate(ItemStack[] inventory, int inputIndex, int outputIndex, GasTank gasTank, int amount)
{
return getInput().useItem(inventory, inputIndex, false) && getInput().useSecondary(gasTank, amount, false) && getOutput().applyOutputs(inventory, outputIndex, false);
}
public void operate(ItemStack[] inventory, int inputIndex, int outputIndex, GasTank gasTank, int needed)
{
if(getInput().useItem(inventory, inputIndex, true) && getInput().useSecondary(gasTank, needed, true))
{
getOutput().applyOutputs(inventory, outputIndex, true);
}
}
}

View file

@ -5,10 +5,20 @@ import mekanism.api.gas.GasStack;
import mekanism.common.recipe.inputs.IntegerInput;
import mekanism.common.recipe.outputs.GasOutput;
public class AmbientGasRecipe extends MachineRecipe<IntegerInput, GasOutput>
public class AmbientGasRecipe extends MachineRecipe<IntegerInput, GasOutput, AmbientGasRecipe>
{
public AmbientGasRecipe(IntegerInput input, GasOutput output)
{
super(input, output);
}
public AmbientGasRecipe(int input, String output)
{
super(new IntegerInput(input), new GasOutput(new GasStack(GasRegistry.getGas(output), 1)));
this(new IntegerInput(input), new GasOutput(new GasStack(GasRegistry.getGas(output), 1)));
}
public AmbientGasRecipe copy()
{
return new AmbientGasRecipe(getInput().copy(), getOutput().copy());
}
}

View file

@ -5,10 +5,30 @@ import mekanism.common.recipe.outputs.ItemStackOutput;
import net.minecraft.item.ItemStack;
public class BasicMachineRecipe extends MachineRecipe<ItemStackInput, ItemStackOutput>
public abstract class BasicMachineRecipe<RECIPE extends BasicMachineRecipe<RECIPE>> extends MachineRecipe<ItemStackInput, ItemStackOutput, RECIPE>
{
public BasicMachineRecipe(ItemStackInput input, ItemStackOutput output)
{
super(input, output);
}
public BasicMachineRecipe(ItemStack input, ItemStack output)
{
super(new ItemStackInput(input), new ItemStackOutput(output));
this(new ItemStackInput(input), new ItemStackOutput(output));
}
public boolean canOperate(ItemStack[] inventory, int inputIndex, int outputIndex)
{
return getInput().useItemStackFromInventory(inventory, inputIndex, false) && getOutput().applyOutputs(inventory, outputIndex, false);
}
public void operate(ItemStack[] inventory, int inputIndex, int outputIndex)
{
if(getInput().useItemStackFromInventory(inventory, inputIndex, true))
{
getOutput().applyOutputs(inventory, outputIndex, true);
}
}
}

View file

@ -3,10 +3,17 @@ package mekanism.common.recipe.machines;
import mekanism.common.recipe.inputs.ItemStackInput;
import mekanism.common.recipe.outputs.ChanceOutput;
public class ChanceMachineRecipe extends MachineRecipe<ItemStackInput, ChanceOutput>
import net.minecraft.item.ItemStack;
public abstract class ChanceMachineRecipe<RECIPE extends ChanceMachineRecipe<RECIPE>> extends MachineRecipe<ItemStackInput, ChanceOutput, RECIPE>
{
public ChanceMachineRecipe(ItemStackInput input, ChanceOutput output)
{
super(input, output);
}
public boolean canOperate(ItemStack[] inventory, int inputIndex, int primaryIndex, int secondaryIndex)
{
return getInput().useItemStackFromInventory(inventory, inputIndex, false) && getOutput().applyOutputs(inventory, primaryIndex, secondaryIndex, false);
}
}

View file

@ -1,13 +1,37 @@
package mekanism.common.recipe.machines;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasTank;
import mekanism.common.recipe.inputs.ChemicalPairInput;
import mekanism.common.recipe.outputs.GasOutput;
public class ChemicalInfuserRecipe extends MachineRecipe<ChemicalPairInput, GasOutput>
public class ChemicalInfuserRecipe extends MachineRecipe<ChemicalPairInput, GasOutput, ChemicalInfuserRecipe>
{
public ChemicalInfuserRecipe(ChemicalPairInput input, GasOutput output)
{
super(input, output);
}
public ChemicalInfuserRecipe(GasStack leftInput, GasStack rightInput, GasStack output)
{
super(new ChemicalPairInput(leftInput, rightInput), new GasOutput(output));
this(new ChemicalPairInput(leftInput, rightInput), new GasOutput(output));
}
public ChemicalInfuserRecipe copy()
{
return new ChemicalInfuserRecipe(getInput().copy(), getOutput().copy());
}
public boolean canOperate(GasTank leftTank, GasTank rightTank, GasTank outputTank)
{
return getInput().useGas(leftTank, rightTank, false) && getOutput().applyOutputs(outputTank, false);
}
public void operate(GasTank leftInput, GasTank rightInput, GasTank outputTank)
{
if(getInput().useGas(leftInput, rightInput, true))
{
getOutput().applyOutputs(outputTank, true);
}
}
}

View file

@ -1,11 +1,25 @@
package mekanism.common.recipe.machines;
import mekanism.common.recipe.inputs.AdvancedMachineInput;
import mekanism.common.recipe.outputs.ItemStackOutput;
import net.minecraft.item.ItemStack;
public class CombinerRecipe extends AdvancedMachineRecipe
public class CombinerRecipe extends AdvancedMachineRecipe<CombinerRecipe>
{
public CombinerRecipe(AdvancedMachineInput input, ItemStackOutput output)
{
super(input, output);
}
public CombinerRecipe(ItemStack input, ItemStack output)
{
super(input, "liquidStone", output);
}
@Override
public CombinerRecipe copy()
{
return new CombinerRecipe(getInput().copy(), getOutput().copy());
}
}

View file

@ -1,11 +1,25 @@
package mekanism.common.recipe.machines;
import mekanism.common.recipe.inputs.ItemStackInput;
import mekanism.common.recipe.outputs.ItemStackOutput;
import net.minecraft.item.ItemStack;
public class CrusherRecipe extends BasicMachineRecipe
public class CrusherRecipe extends BasicMachineRecipe<CrusherRecipe>
{
public CrusherRecipe(ItemStackInput input, ItemStackOutput output)
{
super(input, output);
}
public CrusherRecipe(ItemStack input, ItemStack output)
{
super(input, output);
}
@Override
public CrusherRecipe copy()
{
return new CrusherRecipe(getInput().copy(), getOutput().copy());
}
}

View file

@ -1,15 +1,40 @@
package mekanism.common.recipe.machines;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasTank;
import mekanism.common.recipe.inputs.GasInput;
import mekanism.common.recipe.outputs.ItemStackOutput;
import net.minecraft.item.ItemStack;
public class CrystallizerRecipe extends MachineRecipe<GasInput, ItemStackOutput>
public class CrystallizerRecipe extends MachineRecipe<GasInput, ItemStackOutput, CrystallizerRecipe>
{
public CrystallizerRecipe(GasInput input, ItemStackOutput output)
{
super(input, output);
}
public CrystallizerRecipe(GasStack input, ItemStack output)
{
super(new GasInput(input), new ItemStackOutput(output));
this(new GasInput(input), new ItemStackOutput(output));
}
public boolean canOperate(GasTank gasTank, ItemStack[] inventory)
{
return getInput().useGas(gasTank, false) && getOutput().applyOutputs(inventory, 1, false);
}
public void operate(GasTank inputTank, ItemStack[] inventory)
{
if(getInput().useGas(inputTank, true))
{
getOutput().applyOutputs(inventory, 1, true);
}
}
@Override
public CrystallizerRecipe copy()
{
return new CrystallizerRecipe(getInput().copy(), getOutput().copy());
}
}

View file

@ -1,15 +1,40 @@
package mekanism.common.recipe.machines;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasTank;
import mekanism.common.recipe.inputs.ItemStackInput;
import mekanism.common.recipe.outputs.GasOutput;
import net.minecraft.item.ItemStack;
public class DissolutionRecipe extends MachineRecipe<ItemStackInput, GasOutput>
public class DissolutionRecipe extends MachineRecipe<ItemStackInput, GasOutput, DissolutionRecipe>
{
public DissolutionRecipe(ItemStackInput input, GasOutput output)
{
super(input, output);
}
public DissolutionRecipe(ItemStack input, GasStack output)
{
super(new ItemStackInput(input), new GasOutput(output));
this(new ItemStackInput(input), new GasOutput(output));
}
public boolean canOperate(ItemStack[] inventory, GasTank outputTank)
{
return getInput().useItemStackFromInventory(inventory, 1, false) && getOutput().applyOutputs(outputTank, false);
}
public void operate(ItemStack[] inventory, GasTank outputTank)
{
if(getInput().useItemStackFromInventory(inventory, 1, true))
{
getOutput().applyOutputs(outputTank, true);
}
}
@Override
public DissolutionRecipe copy()
{
return new DissolutionRecipe(getInput().copy(), getOutput().copy());
}
}

View file

@ -1,11 +1,25 @@
package mekanism.common.recipe.machines;
import mekanism.common.recipe.inputs.ItemStackInput;
import mekanism.common.recipe.outputs.ItemStackOutput;
import net.minecraft.item.ItemStack;
public class EnrichmentRecipe extends BasicMachineRecipe
public class EnrichmentRecipe extends BasicMachineRecipe<EnrichmentRecipe>
{
public EnrichmentRecipe(ItemStackInput input, ItemStackOutput output)
{
super(input, output);
}
public EnrichmentRecipe(ItemStack input, ItemStack output)
{
super(input, output);
}
@Override
public EnrichmentRecipe copy()
{
return new EnrichmentRecipe(getInput().copy(), getOutput().copy());
}
}

View file

@ -1,11 +1,25 @@
package mekanism.common.recipe.machines;
import mekanism.common.recipe.inputs.AdvancedMachineInput;
import mekanism.common.recipe.outputs.ItemStackOutput;
import net.minecraft.item.ItemStack;
public class InjectionRecipe extends AdvancedMachineRecipe
public class InjectionRecipe extends AdvancedMachineRecipe<InjectionRecipe>
{
public InjectionRecipe(AdvancedMachineInput input, ItemStackOutput output)
{
super(input, output);
}
public InjectionRecipe(ItemStack input, String gasName, ItemStack output)
{
super(input, gasName, output);
}
@Override
public InjectionRecipe copy()
{
return new InjectionRecipe(getInput().copy(), getOutput().copy());
}
}

View file

@ -3,7 +3,7 @@ package mekanism.common.recipe.machines;
import mekanism.common.recipe.inputs.MachineInput;
import mekanism.common.recipe.outputs.MachineOutput;
public abstract class MachineRecipe<INPUT extends MachineInput, OUTPUT extends MachineOutput>
public abstract class MachineRecipe<INPUT extends MachineInput, OUTPUT extends MachineOutput, RECIPE extends MachineRecipe<INPUT, OUTPUT, RECIPE>>
{
public INPUT recipeInput;
public OUTPUT recipeOutput;
@ -23,4 +23,6 @@ public abstract class MachineRecipe<INPUT extends MachineInput, OUTPUT extends M
{
return recipeOutput;
}
public abstract RECIPE copy();
}

View file

@ -1,14 +1,39 @@
package mekanism.common.recipe.machines;
import mekanism.common.InfuseStorage;
import mekanism.common.recipe.inputs.InfusionInput;
import mekanism.common.recipe.outputs.InfusionOutput;
import mekanism.common.recipe.outputs.ItemStackOutput;
import net.minecraft.item.ItemStack;
public class MetallurgicInfuserRecipe extends MachineRecipe<InfusionInput, InfusionOutput>
public class MetallurgicInfuserRecipe extends MachineRecipe<InfusionInput, ItemStackOutput, MetallurgicInfuserRecipe>
{
public MetallurgicInfuserRecipe(InfusionInput input, ItemStackOutput output)
{
super(input, output);
}
public MetallurgicInfuserRecipe(InfusionInput input, ItemStack output)
{
super(input, InfusionOutput.getInfusion(input, output));
this(input, new ItemStackOutput(output));
}
public boolean canOperate(ItemStack[] inventory, InfuseStorage infuse)
{
return getInput().use(inventory, 2, infuse, false) && getOutput().applyOutputs(inventory, 3, false);
}
@Override
public MetallurgicInfuserRecipe copy()
{
return new MetallurgicInfuserRecipe(getInput(), getOutput());
}
public void output(ItemStack[] inventory, InfuseStorage infuseStored)
{
if(getInput().use(inventory, 2, infuseStored, true))
{
getOutput().applyOutputs(inventory, 3, true);
}
}
}

View file

@ -1,11 +1,25 @@
package mekanism.common.recipe.machines;
import mekanism.common.recipe.inputs.AdvancedMachineInput;
import mekanism.common.recipe.outputs.ItemStackOutput;
import net.minecraft.item.ItemStack;
public class OsmiumCompressorRecipe extends AdvancedMachineRecipe
public class OsmiumCompressorRecipe extends AdvancedMachineRecipe<OsmiumCompressorRecipe>
{
public OsmiumCompressorRecipe(AdvancedMachineInput input, ItemStackOutput output)
{
super(input, output);
}
public OsmiumCompressorRecipe(ItemStack input, ItemStack output)
{
super(input, "liquidOsmium", output);
}
@Override
public OsmiumCompressorRecipe copy()
{
return new OsmiumCompressorRecipe(getInput().copy(), getOutput().copy());
}
}

View file

@ -1,15 +1,40 @@
package mekanism.common.recipe.machines;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasTank;
import mekanism.common.recipe.inputs.ItemStackInput;
import mekanism.common.recipe.outputs.GasOutput;
import net.minecraft.item.ItemStack;
public class OxidationRecipe extends MachineRecipe<ItemStackInput, GasOutput>
public class OxidationRecipe extends MachineRecipe<ItemStackInput, GasOutput, OxidationRecipe>
{
public OxidationRecipe(ItemStackInput input, GasOutput output)
{
super(input, output);
}
public OxidationRecipe(ItemStack input, GasStack output)
{
super(new ItemStackInput(input), new GasOutput(output));
this(new ItemStackInput(input), new GasOutput(output));
}
@Override
public OxidationRecipe copy()
{
return new OxidationRecipe(getInput().copy(), getOutput().copy());
}
public boolean canOperate(ItemStack[] inventory, GasTank outputTank)
{
return getInput().useItemStackFromInventory(inventory, 0, false) && getOutput().applyOutputs(outputTank, false);
}
public void operate(ItemStack[] inventory, GasTank outputTank)
{
if(getInput().useItemStackFromInventory(inventory, 0, true))
{
getOutput().applyOutputs(outputTank, true);
}
}
}

View file

@ -1,13 +1,15 @@
package mekanism.common.recipe.machines;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasTank;
import mekanism.common.recipe.inputs.PressurizedInput;
import mekanism.common.recipe.outputs.PressurizedProducts;
import mekanism.common.recipe.inputs.PressurizedReactants;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
public class PressurizedRecipe extends MachineRecipe<PressurizedReactants, PressurizedProducts>
public class PressurizedRecipe extends MachineRecipe<PressurizedInput, PressurizedProducts, PressurizedRecipe>
{
public double extraEnergy;
@ -15,12 +17,12 @@ public class PressurizedRecipe extends MachineRecipe<PressurizedReactants, Press
public PressurizedRecipe(ItemStack inputSolid, FluidStack inputFluid, GasStack inputGas, ItemStack outputSolid, GasStack outputGas, double energy, int duration)
{
this(new PressurizedReactants(inputSolid, inputFluid, inputGas), new PressurizedProducts(outputSolid, outputGas), energy, duration);
this(new PressurizedInput(inputSolid, inputFluid, inputGas), new PressurizedProducts(outputSolid, outputGas), energy, duration);
}
public PressurizedRecipe(PressurizedReactants pressurizedReactants, PressurizedProducts pressurizedProducts, double energy, int duration)
public PressurizedRecipe(PressurizedInput pressurizedInput, PressurizedProducts pressurizedProducts, double energy, int duration)
{
super(pressurizedReactants, pressurizedProducts);
super(pressurizedInput, pressurizedProducts);
extraEnergy = energy;
ticks = duration;
@ -30,4 +32,17 @@ public class PressurizedRecipe extends MachineRecipe<PressurizedReactants, Press
{
return new PressurizedRecipe(getInput().copy(), getOutput().copy(), extraEnergy, ticks);
}
public boolean canOperate(ItemStack[] inventory, FluidTank inputFluidTank, GasTank inputGasTank, GasTank outputGasTank)
{
return getInput().use(inventory, 0, inputFluidTank, inputGasTank, false) && getOutput().applyOutputs(inventory, 2, outputGasTank, false);
}
public void operate(ItemStack[] inventory, FluidTank inputFluidTank, GasTank inputGasTank, GasTank outputGasTank)
{
if(getInput().use(inventory, 0, inputFluidTank, inputGasTank, true))
{
getOutput().applyOutputs(inventory, 2, outputGasTank, true);
}
}
}

View file

@ -1,11 +1,25 @@
package mekanism.common.recipe.machines;
import mekanism.common.recipe.inputs.AdvancedMachineInput;
import mekanism.common.recipe.outputs.ItemStackOutput;
import net.minecraft.item.ItemStack;
public class PurificationRecipe extends AdvancedMachineRecipe
public class PurificationRecipe extends AdvancedMachineRecipe<PurificationRecipe>
{
public PurificationRecipe(AdvancedMachineInput input, ItemStackOutput output)
{
super(input, output);
}
public PurificationRecipe(ItemStack input, ItemStack output)
{
super(input, "oxygen", output);
}
@Override
public PurificationRecipe copy()
{
return new PurificationRecipe(getInput().copy(), getOutput().copy());
}
}

View file

@ -5,15 +5,26 @@ import mekanism.common.recipe.outputs.ChanceOutput;
import net.minecraft.item.ItemStack;
public class SawmillRecipe extends ChanceMachineRecipe
public class SawmillRecipe extends ChanceMachineRecipe<SawmillRecipe>
{
public SawmillRecipe(ItemStackInput input, ChanceOutput output)
{
super(input, output);
}
public SawmillRecipe(ItemStack input, ItemStack primaryOutput, ItemStack secondaryOutput, double chance)
{
super(new ItemStackInput(input), new ChanceOutput(primaryOutput, secondaryOutput, chance));
this(new ItemStackInput(input), new ChanceOutput(primaryOutput, secondaryOutput, chance));
}
public SawmillRecipe(ItemStack input, ItemStack primaryOutput)
{
super(new ItemStackInput(input), new ChanceOutput(primaryOutput));
this(new ItemStackInput(input), new ChanceOutput(primaryOutput));
}
@Override
public SawmillRecipe copy()
{
return new SawmillRecipe(getInput().copy(), getOutput().copy());
}
}

View file

@ -1,15 +1,44 @@
package mekanism.common.recipe.machines;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasTank;
import mekanism.common.recipe.inputs.FluidInput;
import mekanism.common.recipe.outputs.ChemicalPairOutput;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
public class SeparatorRecipe extends MachineRecipe<FluidInput, ChemicalPairOutput>
public class SeparatorRecipe extends MachineRecipe<FluidInput, ChemicalPairOutput, SeparatorRecipe>
{
public SeparatorRecipe(FluidStack input, GasStack left, GasStack right)
public double extraEnergy;
public SeparatorRecipe(FluidInput input, double energy, ChemicalPairOutput output)
{
super(new FluidInput(input), new ChemicalPairOutput(left, right));
super(input, output);
extraEnergy = energy;
}
public SeparatorRecipe(FluidStack input, double energy, GasStack left, GasStack right)
{
this(new FluidInput(input), energy, new ChemicalPairOutput(left, right));
}
@Override
public SeparatorRecipe copy()
{
return new SeparatorRecipe(getInput().copy(), extraEnergy, getOutput().copy());
}
public boolean canOperate(FluidTank fluidTank, GasTank leftTank, GasTank rightTank)
{
return getInput().useFluid(fluidTank, false) && getOutput().applyOutputs(leftTank, rightTank, false);
}
public void operate(FluidTank fluidTank, GasTank leftTank, GasTank rightTank)
{
if(getInput().useFluid(fluidTank, true))
{
getOutput().applyOutputs(leftTank, rightTank, true);
}
}
}

View file

@ -1,13 +1,47 @@
package mekanism.common.recipe.machines;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasTank;
import mekanism.common.recipe.inputs.FluidInput;
import mekanism.common.recipe.inputs.GasInput;
import mekanism.common.recipe.outputs.GasOutput;
import mekanism.common.tile.TileEntityChemicalWasher;
public class WasherRecipe extends MachineRecipe<GasInput, GasOutput>
import net.minecraftforge.fluids.FluidEvent.FluidDrainingEvent;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
public class WasherRecipe extends MachineRecipe<GasInput, GasOutput, WasherRecipe>
{
public FluidInput waterInput = new FluidInput(new FluidStack(FluidRegistry.WATER, TileEntityChemicalWasher.WATER_USAGE));
public WasherRecipe(GasInput input, GasOutput output)
{
super(input, output);
}
public WasherRecipe(GasStack input, GasStack output)
{
super(new GasInput(input), new GasOutput(output));
this(new GasInput(input), new GasOutput(output));
}
@Override
public WasherRecipe copy()
{
return new WasherRecipe(getInput().copy(), getOutput().copy());
}
public boolean canOperate(GasTank inputTank, FluidTank fluidTank, GasTank outputTank)
{
return getInput().useGas(inputTank, false) && waterInput.useFluid(fluidTank, false) && getOutput().applyOutputs(outputTank, false);
}
public void operate(GasTank inputTank, FluidTank fluidTank, GasTank outputTank)
{
if(getInput().useGas(inputTank, true) && waterInput.useFluid(fluidTank, true))
{
getOutput().applyOutputs(outputTank, true);
}
}
}

View file

@ -6,7 +6,7 @@ import mekanism.api.util.StackUtils;
import net.minecraft.item.ItemStack;
public class ChanceOutput extends MachineOutput
public class ChanceOutput extends MachineOutput<ChanceOutput>
{
private static Random rand = new Random();
@ -43,6 +43,51 @@ public class ChanceOutput extends MachineOutput
return secondaryOutput != null;
}
public boolean applyOutputs(ItemStack[] inventory, int primaryIndex, int secondaryIndex, boolean doEmit)
{
if(hasPrimary())
{
if(inventory[primaryIndex] == null)
{
if(doEmit)
{
inventory[primaryIndex] = primaryOutput.copy();
}
return true;
} else if(inventory[primaryIndex].isItemEqual(primaryOutput) && inventory[primaryIndex].stackSize + primaryOutput.stackSize <= inventory[primaryIndex].getMaxStackSize())
{
if(doEmit)
{
inventory[primaryIndex].stackSize += primaryOutput.stackSize;
}
return true;
}
return false;
}
if(hasSecondary() && (!doEmit || checkSecondary()))
{
if(inventory[secondaryIndex] == null)
{
if(doEmit)
{
inventory[secondaryIndex] = secondaryOutput.copy();
}
return true;
} else if(inventory[secondaryIndex].isItemEqual(secondaryOutput) && inventory[secondaryIndex].stackSize + primaryOutput.stackSize <= inventory[secondaryIndex].getMaxStackSize())
{
if(doEmit)
{
inventory[secondaryIndex].stackSize += secondaryOutput.stackSize;
}
return true;
}
return false;
}
return true;
}
public ChanceOutput copy()
{
return new ChanceOutput(StackUtils.copy(primaryOutput), StackUtils.copy(secondaryOutput), secondaryChance);

View file

@ -8,7 +8,7 @@ import mekanism.api.gas.GasTank;
* @author aidancbrady
*
*/
public class ChemicalPairOutput extends MachineOutput
public class ChemicalPairOutput extends MachineOutput<ChemicalPairOutput>
{
/** The left gas of this chemical input */
public GasStack leftGas;
@ -55,6 +55,28 @@ public class ChemicalPairOutput extends MachineOutput
return new ChemicalPairOutput(rightGas, leftGas);
}
public boolean applyOutputs(GasTank leftTank, GasTank rightTank, boolean doEmit)
{
if(leftTank.canReceive(leftGas.getGas()) && rightTank.canReceive(rightGas.getGas()))
{
if(leftTank.getNeeded() >= leftGas.amount && rightTank.getNeeded() >= rightGas.amount)
{
leftTank.receive(leftGas, doEmit);
rightTank.receive(rightGas, doEmit);
return true;
}
} else if(leftTank.canReceive(rightGas.getGas()) && rightTank.canReceive(leftGas.getGas()))
{
if(leftTank.getNeeded() >= rightGas.amount && rightTank.getNeeded() >= leftGas.amount)
{
leftTank.receive(rightGas, doEmit);
rightTank.receive(leftGas, doEmit);
return true;
}
}
return false;
}
/**
* Draws the needed amount of gas from each tank.
* @param leftTank - left tank to draw from

View file

@ -1,8 +1,9 @@
package mekanism.common.recipe.outputs;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasTank;
public class GasOutput extends MachineOutput
public class GasOutput extends MachineOutput<GasOutput>
{
public GasStack output;
@ -10,4 +11,20 @@ public class GasOutput extends MachineOutput
{
output = stack;
}
@Override
public GasOutput copy()
{
return new GasOutput(output.copy());
}
public boolean applyOutputs(GasTank gasTank, boolean doEmit)
{
if(gasTank.canReceive(output.getGas()) && gasTank.getNeeded() >= output.amount)
{
gasTank.receive(output.copy(), doEmit);
return true;
}
return false;
}
}

View file

@ -1,40 +0,0 @@
package mekanism.common.recipe.outputs;
import mekanism.common.recipe.inputs.InfusionInput;
import net.minecraft.item.ItemStack;
/**
* An infusion output, containing a reference to it's input as well as the output resource.
* @author AidanBrady
*
*/
public class InfusionOutput extends MachineOutput
{
/** The input infusion */
public InfusionInput infusionInput;
/** The output resource of this infusion */
public ItemStack resource;
public InfusionOutput(InfusionInput input, ItemStack itemstack)
{
infusionInput = input;
resource = itemstack;
}
public static InfusionOutput getInfusion(InfusionInput input, ItemStack itemstack)
{
return new InfusionOutput(input, itemstack);
}
public int getInfuseRequired()
{
return infusionInput.infuseAmount;
}
public InfusionOutput copy()
{
return new InfusionOutput(infusionInput, resource);
}
}

View file

@ -2,7 +2,7 @@ package mekanism.common.recipe.outputs;
import net.minecraft.item.ItemStack;
public class ItemStackOutput extends MachineOutput
public class ItemStackOutput extends MachineOutput<ItemStackOutput>
{
public ItemStack output;
@ -10,4 +10,30 @@ public class ItemStackOutput extends MachineOutput
{
output = stack;
}
public boolean applyOutputs(ItemStack[] inventory, int index, boolean doEmit)
{
if(inventory[index] == null)
{
if(doEmit)
{
inventory[index] = output.copy();
}
return true;
} else if(inventory[index].isItemEqual(output) && inventory[index].stackSize + output.stackSize <= inventory[index].getMaxStackSize())
{
if(doEmit)
{
inventory[index].stackSize += output.stackSize;
}
return true;
}
return false;
}
@Override
public ItemStackOutput copy()
{
return new ItemStackOutput(output.copy());
}
}

View file

@ -1,5 +1,6 @@
package mekanism.common.recipe.outputs;
public class MachineOutput
public abstract class MachineOutput<OUTPUT extends MachineOutput<OUTPUT>>
{
public abstract OUTPUT copy();
}

View file

@ -5,7 +5,7 @@ import mekanism.api.gas.GasTank;
import net.minecraft.item.ItemStack;
public class PressurizedProducts extends MachineOutput
public class PressurizedProducts extends MachineOutput<PressurizedProducts>
{
private ItemStack itemOutput;
private GasStack gasOutput;
@ -16,6 +16,16 @@ public class PressurizedProducts extends MachineOutput
gasOutput = gas;
}
public boolean canFillTank(GasTank tank)
{
return tank.canReceive(gasOutput.getGas()) && tank.getNeeded() >= gasOutput.amount;
}
public boolean canAddProducts(ItemStack[] inventory, int index)
{
return inventory[index] == null || (inventory[index].isItemEqual(itemOutput) && inventory[index].stackSize + itemOutput.stackSize <= inventory[index].getMaxStackSize());
}
public void fillTank(GasTank tank)
{
tank.receive(gasOutput, true);
@ -33,6 +43,20 @@ public class PressurizedProducts extends MachineOutput
}
}
public boolean applyOutputs(ItemStack[] inventory, int index, GasTank tank, boolean doEmit)
{
if(canFillTank(tank) && canAddProducts(inventory, index))
{
if(doEmit)
{
fillTank(tank);
addProducts(inventory, index);
}
return true;
}
return false;
}
public ItemStack getItemOutput()
{
return itemOutput;

View file

@ -1,5 +0,0 @@
package mekanism.common.recipe.outputs;
public class StringOutput extends MachineOutput
{
}

View file

@ -15,6 +15,9 @@ import mekanism.common.Mekanism;
import mekanism.common.MekanismItems;
import mekanism.common.SideData;
import mekanism.common.recipe.RecipeHandler;
import mekanism.common.recipe.inputs.ItemStackInput;
import mekanism.common.recipe.machines.AdvancedMachineRecipe;
import mekanism.common.recipe.outputs.ItemStackOutput;
import mekanism.common.tile.component.TileComponentEjector;
import mekanism.common.tile.component.TileComponentUpgrade;
import mekanism.common.util.ChargeUtils;
@ -32,7 +35,7 @@ import io.netty.buffer.ByteBuf;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.peripheral.IComputerAccess;
public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicMachine implements IGasHandler, ITubeConnection
public abstract class TileEntityAdvancedElectricMachine<RECIPE extends AdvancedMachineRecipe<RECIPE>> extends TileEntityBasicMachine<AdvancedMachineInput, ItemStackOutput, RECIPE> implements IGasHandler, ITubeConnection
{
/** How much secondary energy (fuel) this machine uses per tick. */
public int SECONDARY_ENERGY_PER_TICK;
@ -98,7 +101,9 @@ public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicM
boolean changed = false;
if(canOperate() && MekanismUtils.canFunction(this) && getEnergy() >= MekanismUtils.getEnergyPerTick(this, ENERGY_PER_TICK) && gasTank.getStored() >= (int)MekanismUtils.getSecondaryEnergyPerTick(this, SECONDARY_ENERGY_PER_TICK))
RECIPE recipe = RecipeHandler.getRecipe(getInput(), getRecipes());
if(canOperate(recipe) && MekanismUtils.canFunction(this) && getEnergy() >= MekanismUtils.getEnergyPerTick(this, ENERGY_PER_TICK) && gasTank.getStored() >= (int)MekanismUtils.getSecondaryEnergyPerTick(this, SECONDARY_ENERGY_PER_TICK))
{
setActive(true);
@ -106,7 +111,7 @@ public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicM
if(operatingTicks >= MekanismUtils.getTicks(this, TICKS_REQUIRED))
{
operate();
operate(recipe);
operatingTicks = 0;
}
@ -122,7 +127,7 @@ public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicM
}
}
if(changed && !canOperate() && !hasRecipe(inventory[0]))
if(changed && !canOperate(recipe) && RecipeHandler.getRecipe(getInput(), getRecipes()) == null)
{
operatingTicks = 0;
}
@ -131,31 +136,6 @@ public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicM
}
}
private boolean hasRecipe(ItemStack itemStack)
{
if(itemStack == null)
{
return false;
}
for(Object obj : getRecipes().entrySet())
{
if(((Map.Entry)obj).getKey() instanceof AdvancedMachineInput)
{
Map.Entry entry = (Map.Entry)obj;
ItemStack stack = ((AdvancedMachineInput)entry.getKey()).itemStack;
if(StackUtils.equalsWildcard(stack, itemStack))
{
return true;
}
}
}
return false;
}
public void handleSecondaryFuel()
{
if(inventory[1] != null)
@ -190,7 +170,7 @@ public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicM
}
else if(slotID == 0)
{
return hasRecipe(itemstack);
return RecipeHandler.getRecipe(new AdvancedMachineInput(itemstack, gasTank.getGasType()), getRecipes()) != null;
}
else if(slotID == 3)
{
@ -205,54 +185,30 @@ public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicM
}
@Override
public void operate()
public AdvancedMachineInput getInput()
{
ItemStack itemstack = RecipeHandler.getOutput(new AdvancedMachineInput(inventory[0], gasTank.getGas().getGas()), true, getRecipes());
return new AdvancedMachineInput(inventory[0], gasTank.getGasType());
}
if(inventory[0].stackSize <= 0)
{
inventory[0] = null;
}
@Override
public RECIPE getRecipe()
{
return RecipeHandler.getRecipe(getInput(), getRecipes());
}
if(inventory[2] == null)
{
inventory[2] = itemstack;
}
else {
inventory[2].stackSize += itemstack.stackSize;
}
@Override
public void operate(RECIPE recipe)
{
recipe.operate(inventory, 0, 2, gasTank, MekanismUtils.getSecondaryEnergyPerTick(this, SECONDARY_ENERGY_PER_TICK));
markDirty();
ejectorComponent.onOutput();
}
@Override
public boolean canOperate()
public boolean canOperate(RECIPE recipe)
{
if(inventory[0] == null || gasTank.getGas() == null)
{
return false;
}
ItemStack itemstack = RecipeHandler.getOutput(new AdvancedMachineInput(inventory[0], gasTank.getGas().getGas()), false, getRecipes());
if(itemstack == null)
{
return false;
}
if(inventory[2] == null)
{
return true;
}
if(!inventory[2].isItemEqual(itemstack))
{
return false;
}
else {
return inventory[2].stackSize + itemstack.stackSize <= inventory[2].getMaxStackSize();
}
return recipe != null && recipe.canOperate(inventory, 0, 2, gasTank, MekanismUtils.getSecondaryEnergyPerTick(this, SECONDARY_ENERGY_PER_TICK));
}
@Override
@ -382,7 +338,7 @@ public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicM
case 4:
return new Object[] {facing};
case 5:
return new Object[] {canOperate()};
return new Object[] {canOperate(RecipeHandler.getRecipe(getInput(), getRecipes()))};
case 6:
return new Object[] {MekanismUtils.getMaxEnergy(this, getMaxEnergy())};
case 7:

View file

@ -13,6 +13,8 @@ import mekanism.api.gas.IGasHandler;
import mekanism.api.gas.ITubeConnection;
import mekanism.common.recipe.RecipeHandler;
import mekanism.common.recipe.RecipeHandler.Recipe;
import mekanism.common.recipe.inputs.IntegerInput;
import mekanism.common.recipe.machines.AmbientGasRecipe;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection;
@ -24,7 +26,7 @@ public class TileEntityAmbientAccumulator extends TileEntityContainerBlock imple
public GasTank collectedGas = new GasTank(1000);
public int cachedDimensionId = 0;
public GasStack cachedGas;
public AmbientGasRecipe cachedRecipe;
public static Random gasRand = new Random();
@ -39,15 +41,15 @@ public class TileEntityAmbientAccumulator extends TileEntityContainerBlock imple
{
if(!worldObj.isRemote)
{
if(cachedGas == null || worldObj.provider.dimensionId != cachedDimensionId)
if(cachedRecipe == null || worldObj.provider.dimensionId != cachedDimensionId)
{
cachedDimensionId = worldObj.provider.dimensionId;
cachedGas = RecipeHandler.getDimensionGas(cachedDimensionId);
cachedRecipe = RecipeHandler.getDimensionGas(new IntegerInput(cachedDimensionId));
}
if(cachedGas != null && gasRand.nextDouble() < 0.05)
if(cachedRecipe != null && gasRand.nextDouble() < 0.05 && cachedRecipe.getOutput().applyOutputs(collectedGas, false))
{
collectedGas.receive(cachedGas, true);
cachedRecipe.getOutput().applyOutputs(collectedGas, true);
}
}
}

View file

@ -13,6 +13,9 @@ import mekanism.common.base.IInvConfiguration;
import mekanism.common.base.IRedstoneControl;
import mekanism.common.base.IUpgradeTile;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.recipe.inputs.MachineInput;
import mekanism.common.recipe.machines.MachineRecipe;
import mekanism.common.recipe.outputs.MachineOutput;
import mekanism.common.tile.component.TileComponentEjector;
import mekanism.common.tile.component.TileComponentUpgrade;
import mekanism.common.util.MekanismUtils;
@ -28,7 +31,7 @@ import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.peripheral.IPeripheral;
@Interface(iface = "dan200.computercraft.api.peripheral.IPeripheral", modid = "ComputerCraft")
public abstract class TileEntityBasicMachine extends TileEntityNoisyElectricBlock implements IElectricMachine, IPeripheral, IInvConfiguration, IUpgradeTile, IRedstoneControl
public abstract class TileEntityBasicMachine<INPUT extends MachineInput<INPUT>, OUTPUT extends MachineOutput<OUTPUT>, RECIPE extends MachineRecipe<INPUT, OUTPUT, RECIPE>> extends TileEntityNoisyElectricBlock implements IElectricMachine<INPUT, OUTPUT, RECIPE>, IPeripheral, IInvConfiguration, IUpgradeTile, IRedstoneControl
{
/** This machine's side configuration. */
public byte[] sideConfig;

View file

@ -3,6 +3,8 @@ package mekanism.common.tile;
import java.util.Map;
import mekanism.api.EnumColor;
import mekanism.common.recipe.inputs.ItemStackInput;
import mekanism.common.recipe.machines.ChanceMachineRecipe;
import mekanism.common.recipe.outputs.ChanceOutput;
import mekanism.common.MekanismItems;
import mekanism.common.SideData;
@ -21,7 +23,7 @@ import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.peripheral.IComputerAccess;
public abstract class TileEntityChanceMachine extends TileEntityBasicMachine
public abstract class TileEntityChanceMachine<RECIPE extends ChanceMachineRecipe<RECIPE>> extends TileEntityBasicMachine<ItemStackInput, ChanceOutput, RECIPE>
{
public TileEntityChanceMachine(String soundPath, String name, ResourceLocation location, double perTick, int ticksRequired, double maxEnergy)
{
@ -50,7 +52,9 @@ public abstract class TileEntityChanceMachine extends TileEntityBasicMachine
{
ChargeUtils.discharge(1, this);
if(canOperate() && MekanismUtils.canFunction(this) && getEnergy() >= MekanismUtils.getEnergyPerTick(this, ENERGY_PER_TICK))
RECIPE recipe = getRecipe();
if(canOperate(recipe) && MekanismUtils.canFunction(this) && getEnergy() >= MekanismUtils.getEnergyPerTick(this, ENERGY_PER_TICK))
{
setActive(true);
@ -61,7 +65,7 @@ public abstract class TileEntityChanceMachine extends TileEntityBasicMachine
}
else if((operatingTicks+1) >= MekanismUtils.getTicks(this, TICKS_REQUIRED))
{
operate();
operate(recipe);
operatingTicks = 0;
electricityStored -= MekanismUtils.getEnergyPerTick(this, ENERGY_PER_TICK);
@ -74,7 +78,7 @@ public abstract class TileEntityChanceMachine extends TileEntityBasicMachine
}
}
if(!canOperate())
if(!canOperate(recipe))
{
operatingTicks = 0;
}
@ -103,35 +107,17 @@ public abstract class TileEntityChanceMachine extends TileEntityBasicMachine
}
@Override
public void operate()
public ItemStackInput getInput()
{
ChanceOutput output = RecipeHandler.getChanceOutput(inventory[0], true, getRecipes());
return new ItemStackInput(inventory[0]);
}
if(inventory[0].stackSize <= 0)
@Override
public void operate(RECIPE recipe)
{
if(recipe.getInput().useItemStackFromInventory(inventory, 0, true))
{
inventory[0] = null;
}
if(output.hasPrimary())
{
if(inventory[2] == null)
{
inventory[2] = output.primaryOutput;
}
else {
inventory[2].stackSize += output.primaryOutput.stackSize;
}
}
if(output.hasSecondary() && output.checkSecondary())
{
if(inventory[4] == null)
{
inventory[4] = output.secondaryOutput;
}
else {
inventory[4].stackSize += output.secondaryOutput.stackSize;
}
recipe.getOutput().applyOutputs(inventory, 2, 4, true);
}
markDirty();
@ -139,55 +125,9 @@ public abstract class TileEntityChanceMachine extends TileEntityBasicMachine
}
@Override
public boolean canOperate()
public boolean canOperate(RECIPE recipe)
{
if(inventory[0] == null)
{
return false;
}
ChanceOutput output = RecipeHandler.getChanceOutput(inventory[0], false, getRecipes());
if(output == null)
{
return false;
}
if(output.hasPrimary())
{
if(inventory[2] != null)
{
if(!inventory[2].isItemEqual(output.primaryOutput))
{
return false;
}
else {
if(inventory[2].stackSize + output.primaryOutput.stackSize > inventory[2].getMaxStackSize())
{
return false;
}
}
}
}
if(output.hasSecondary())
{
if(inventory[4] != null)
{
if(!inventory[4].isItemEqual(output.secondaryOutput))
{
return false;
}
else {
if(inventory[4].stackSize + output.secondaryOutput.stackSize > inventory[4].getMaxStackSize())
{
return false;
}
}
}
}
return true;
return recipe != null && recipe.canOperate(inventory, 0, 2, 4);
}
@Override
@ -206,7 +146,13 @@ public abstract class TileEntityChanceMachine extends TileEntityBasicMachine
}
@Override
public Map getRecipes()
public RECIPE getRecipe()
{
return RecipeHandler.getChanceRecipe(getInput(), getRecipes());
}
@Override
public Map<ItemStackInput, RECIPE> getRecipes()
{
return null;
}

View file

@ -24,6 +24,8 @@ import mekanism.common.base.IUpgradeTile;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.recipe.RecipeHandler;
import mekanism.common.recipe.inputs.GasInput;
import mekanism.common.recipe.machines.CrystallizerRecipe;
import mekanism.common.tile.component.TileComponentEjector;
import mekanism.common.tile.component.TileComponentUpgrade;
import mekanism.common.util.ChargeUtils;
@ -108,6 +110,8 @@ public class TileEntityChemicalCrystallizer extends TileEntityNoisyElectricBlock
if(!worldObj.isRemote)
{
CrystallizerRecipe recipe = getRecipe();
if(updateDelay > 0)
{
updateDelay--;
@ -125,21 +129,19 @@ public class TileEntityChemicalCrystallizer extends TileEntityNoisyElectricBlock
inputTank.receive(GasTransmission.removeGas(inventory[0], inputTank.getGasType(), inputTank.getNeeded()), true);
}
if(canOperate() && MekanismUtils.canFunction(this) && getEnergy() >= MekanismUtils.getEnergyPerTick(this, ENERGY_USAGE))
if(canOperate(recipe) && MekanismUtils.canFunction(this) && getEnergy() >= MekanismUtils.getEnergyPerTick(this, ENERGY_USAGE))
{
setActive(true);
setEnergy(getEnergy() - MekanismUtils.getEnergyPerTick(this, ENERGY_USAGE));
if((operatingTicks+1) < MekanismUtils.getTicks(this, TICKS_REQUIRED))
{
operatingTicks++;
setEnergy(getEnergy() - MekanismUtils.getEnergyPerTick(this, ENERGY_USAGE));
}
else if((operatingTicks+1) >= MekanismUtils.getTicks(this, TICKS_REQUIRED))
else
{
operate();
operate(recipe);
operatingTicks = 0;
setEnergy(getEnergy() - MekanismUtils.getEnergyPerTick(this, ENERGY_USAGE));
}
}
else {
@ -149,7 +151,7 @@ public class TileEntityChemicalCrystallizer extends TileEntityNoisyElectricBlock
}
}
if(!canOperate())
if(!canOperate(recipe))
{
operatingTicks = 0;
}
@ -158,45 +160,24 @@ public class TileEntityChemicalCrystallizer extends TileEntityNoisyElectricBlock
}
}
public boolean canOperate()
public GasInput getInput()
{
if(inputTank.getGas() == null)
{
return false;
}
ItemStack itemstack = RecipeHandler.getChemicalCrystallizerOutput(inputTank, false);
if(itemstack == null)
{
return false;
}
if(inventory[1] == null)
{
return true;
}
if(!inventory[1].isItemEqual(itemstack))
{
return false;
}
else {
return inventory[1].stackSize + itemstack.stackSize <= inventory[1].getMaxStackSize();
}
return new GasInput(inputTank.getGas());
}
public void operate()
public CrystallizerRecipe getRecipe()
{
ItemStack itemstack = RecipeHandler.getChemicalCrystallizerOutput(inputTank, true);
return RecipeHandler.getChemicalCrystallizerRecipe(getInput());
}
if(inventory[1] == null)
{
inventory[1] = itemstack;
}
else {
inventory[1].stackSize += itemstack.stackSize;
}
public boolean canOperate(CrystallizerRecipe recipe)
{
return recipe != null && recipe.canOperate(inputTank, inventory);
}
public void operate(CrystallizerRecipe recipe)
{
recipe.operate(inputTank, inventory);
markDirty();
ejectorComponent.onOutput();

View file

@ -20,7 +20,8 @@ import mekanism.common.base.IUpgradeTile;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.recipe.RecipeHandler;
import mekanism.common.recipe.RecipeHandler.Recipe;
import mekanism.common.recipe.inputs.ItemStackInput;
import mekanism.common.recipe.machines.DissolutionRecipe;
import mekanism.common.tile.component.TileComponentUpgrade;
import mekanism.common.util.ChargeUtils;
import mekanism.common.util.InventoryUtils;
@ -84,6 +85,8 @@ public class TileEntityChemicalDissolutionChamber extends TileEntityNoisyElectri
if(!worldObj.isRemote)
{
DissolutionRecipe recipe = getRecipe();
if(updateDelay > 0)
{
updateDelay--;
@ -108,30 +111,19 @@ public class TileEntityChemicalDissolutionChamber extends TileEntityNoisyElectri
boolean changed = false;
if(canOperate() && getEnergy() >= MekanismUtils.getEnergyPerTick(this, ENERGY_USAGE) && injectTank.getStored() >= INJECT_USAGE && MekanismUtils.canFunction(this))
if(canOperate(recipe) && getEnergy() >= MekanismUtils.getEnergyPerTick(this, ENERGY_USAGE) && injectTank.getStored() >= INJECT_USAGE && MekanismUtils.canFunction(this))
{
setActive(true);
setEnergy(getEnergy() - MekanismUtils.getEnergyPerTick(this, ENERGY_USAGE));
minorOperate();
if(operatingTicks < MekanismUtils.getTicks(this, TICKS_REQUIRED))
if((operatingTicks+1) < MekanismUtils.getTicks(this, TICKS_REQUIRED))
{
operatingTicks++;
injectTank.draw(INJECT_USAGE, true);
}
else {
GasStack stack = RecipeHandler.getDissolutionOutput(inventory[1], true);
outputTank.receive(stack, true);
injectTank.draw(INJECT_USAGE, true);
operate(recipe);
operatingTicks = 0;
if(inventory[1].stackSize <= 0)
{
inventory[1] = null;
}
markDirty();
}
}
else {
@ -142,7 +134,7 @@ public class TileEntityChemicalDissolutionChamber extends TileEntityNoisyElectri
}
}
if(changed && !canOperate())
if(changed && !canOperate(recipe))
{
operatingTicks = 0;
}
@ -171,7 +163,7 @@ public class TileEntityChemicalDissolutionChamber extends TileEntityNoisyElectri
{
if(slotID == 1)
{
return RecipeHandler.getDissolutionOutput(itemstack, false) != null;
return RecipeHandler.getDissolutionRecipe(new ItemStackInput(itemstack)) != null;
}
else if(slotID == 3)
{
@ -216,21 +208,31 @@ public class TileEntityChemicalDissolutionChamber extends TileEntityNoisyElectri
return ((double)operatingTicks) / ((double)TICKS_REQUIRED);
}
public boolean canOperate()
public DissolutionRecipe getRecipe()
{
if(inventory[1] == null)
{
return false;
}
return RecipeHandler.getDissolutionRecipe(getInput());
}
GasStack stack = RecipeHandler.getDissolutionOutput(inventory[1], false);
public ItemStackInput getInput()
{
return new ItemStackInput(inventory[1]);
}
if(stack == null || (outputTank.getGas() != null && (outputTank.getGas().getGas() != stack.getGas() || outputTank.getNeeded() < stack.amount)))
{
return false;
}
public boolean canOperate(DissolutionRecipe recipe)
{
return recipe != null && recipe.canOperate(inventory, outputTank);
}
return true;
public void operate(DissolutionRecipe recipe)
{
recipe.operate(inventory, outputTank);
markDirty();
}
public void minorOperate()
{
injectTank.draw(INJECT_USAGE, true);
}
@Override

View file

@ -19,6 +19,8 @@ import mekanism.common.base.ISustainedData;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.recipe.RecipeHandler;
import mekanism.common.recipe.inputs.ChemicalPairInput;
import mekanism.common.recipe.machines.ChemicalInfuserRecipe;
import mekanism.common.util.ChargeUtils;
import mekanism.common.util.InventoryUtils;
import mekanism.common.util.MekanismUtils;
@ -77,6 +79,8 @@ public class TileEntityChemicalInfuser extends TileEntityNoisyElectricBlock impl
if(!worldObj.isRemote)
{
ChemicalInfuserRecipe recipe = getRecipe();
if(updateDelay > 0)
{
updateDelay--;
@ -104,14 +108,12 @@ public class TileEntityChemicalInfuser extends TileEntityNoisyElectricBlock impl
centerTank.draw(GasTransmission.addGas(inventory[2], centerTank.getGas()), true);
}
if(canOperate() && getEnergy() >= ENERGY_USAGE && MekanismUtils.canFunction(this))
if(canOperate(recipe) && getEnergy() >= ENERGY_USAGE && MekanismUtils.canFunction(this))
{
setActive(true);
GasStack stack = RecipeHandler.getChemicalInfuserOutput(leftTank, rightTank, true);
centerTank.receive(stack, true);
setEnergy(getEnergy() - ENERGY_USAGE);
operate(recipe);
}
else {
if(prevEnergy >= getEnergy())
@ -139,26 +141,26 @@ public class TileEntityChemicalInfuser extends TileEntityNoisyElectricBlock impl
}
}
public boolean canOperate()
public ChemicalPairInput getInput()
{
if(leftTank.getGas() == null || rightTank.getGas() == null || centerTank.getNeeded() == 0)
{
return false;
}
return new ChemicalPairInput(leftTank.getGas(), rightTank.getGas());
}
GasStack out = RecipeHandler.getChemicalInfuserOutput(leftTank, rightTank, false);
public ChemicalInfuserRecipe getRecipe()
{
return RecipeHandler.getChemicalInfuserRecipe(getInput());
}
if(out == null || centerTank.getGas() != null && centerTank.getGas().getGas() != out.getGas())
{
return false;
}
public boolean canOperate(ChemicalInfuserRecipe recipe)
{
return recipe != null && recipe.canOperate(leftTank, rightTank, centerTank);
}
if(centerTank.getNeeded() < out.amount)
{
return false;
}
public void operate(ChemicalInfuserRecipe recipe)
{
recipe.operate(leftTank, rightTank, centerTank);
return true;
markDirty();
}
@Override

View file

@ -13,13 +13,14 @@ import mekanism.api.gas.ITubeConnection;
import mekanism.common.MekanismBlocks;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.recipe.RecipeHandler.Recipe;
import mekanism.common.recipe.machines.InjectionRecipe;
import mekanism.common.util.MekanismUtils;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityChemicalInjectionChamber extends TileEntityAdvancedElectricMachine implements IGasHandler, ITubeConnection
public class TileEntityChemicalInjectionChamber extends TileEntityAdvancedElectricMachine<InjectionRecipe> implements IGasHandler, ITubeConnection
{
public TileEntityChemicalInjectionChamber()
{

View file

@ -19,7 +19,8 @@ import mekanism.common.base.IUpgradeTile;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.recipe.RecipeHandler;
import mekanism.common.recipe.RecipeHandler.Recipe;
import mekanism.common.recipe.inputs.ItemStackInput;
import mekanism.common.recipe.machines.OxidationRecipe;
import mekanism.common.tile.component.TileComponentUpgrade;
import mekanism.common.util.ChargeUtils;
import mekanism.common.util.InventoryUtils;
@ -80,6 +81,7 @@ public class TileEntityChemicalOxidizer extends TileEntityNoisyElectricBlock imp
if(!worldObj.isRemote)
{
OxidationRecipe recipe = getRecipe();
if(updateDelay > 0)
{
updateDelay--;
@ -97,7 +99,7 @@ public class TileEntityChemicalOxidizer extends TileEntityNoisyElectricBlock imp
gasTank.draw(GasTransmission.addGas(inventory[2], gasTank.getGas()), true);
}
if(canOperate() && getEnergy() >= MekanismUtils.getEnergyPerTick(this, ENERGY_USAGE) && MekanismUtils.canFunction(this))
if(canOperate(recipe) && getEnergy() >= MekanismUtils.getEnergyPerTick(this, ENERGY_USAGE) && MekanismUtils.canFunction(this))
{
setActive(true);
setEnergy(getEnergy() - MekanismUtils.getEnergyPerTick(this, ENERGY_USAGE));
@ -107,16 +109,9 @@ public class TileEntityChemicalOxidizer extends TileEntityNoisyElectricBlock imp
operatingTicks++;
}
else {
GasStack stack = RecipeHandler.getOxidizerOutput(inventory[0], true);
operate(recipe);
gasTank.receive(stack, true);
operatingTicks = 0;
if(inventory[0].stackSize <= 0)
{
inventory[0] = null;
}
markDirty();
}
}
@ -151,7 +146,7 @@ public class TileEntityChemicalOxidizer extends TileEntityNoisyElectricBlock imp
{
if(slotID == 0)
{
return RecipeHandler.getOxidizerOutput(itemstack, false) != null;
return RecipeHandler.getOxidizerRecipe(new ItemStackInput(itemstack)) != null;
}
else if(slotID == 1)
{
@ -196,21 +191,26 @@ public class TileEntityChemicalOxidizer extends TileEntityNoisyElectricBlock imp
return ((double)operatingTicks) / ((double)MekanismUtils.getTicks(this, TICKS_REQUIRED));
}
public boolean canOperate()
public OxidationRecipe getRecipe()
{
if(inventory[0] == null)
{
return false;
}
return RecipeHandler.getOxidizerRecipe(getInput());
}
GasStack stack = RecipeHandler.getOxidizerOutput(inventory[0], false);
public ItemStackInput getInput()
{
return new ItemStackInput(inventory[0]);
}
if(stack == null || (gasTank.getGas() != null && (gasTank.getGas().getGas() != stack.getGas() || gasTank.getNeeded() < stack.amount)))
{
return false;
}
public boolean canOperate(OxidationRecipe recipe)
{
return recipe != null && recipe.canOperate(inventory, gasTank);
}
return true;
public void operate(OxidationRecipe recipe)
{
recipe.operate(inventory, gasTank);
markDirty();
}
@Override

View file

@ -19,6 +19,8 @@ import mekanism.common.base.ISustainedData;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.recipe.RecipeHandler;
import mekanism.common.recipe.inputs.GasInput;
import mekanism.common.recipe.machines.WasherRecipe;
import mekanism.common.util.ChargeUtils;
import mekanism.common.util.FluidContainerUtils;
import mekanism.common.util.InventoryUtils;
@ -90,6 +92,8 @@ public class TileEntityChemicalWasher extends TileEntityNoisyElectricBlock imple
if(!worldObj.isRemote)
{
WasherRecipe recipe = getRecipe();
if(updateDelay > 0)
{
updateDelay--;
@ -108,13 +112,11 @@ public class TileEntityChemicalWasher extends TileEntityNoisyElectricBlock imple
outputTank.draw(GasTransmission.addGas(inventory[2], outputTank.getGas()), true);
}
if(canOperate() && getEnergy() >= ENERGY_USAGE && MekanismUtils.canFunction(this))
if(canOperate(recipe) && getEnergy() >= ENERGY_USAGE && MekanismUtils.canFunction(this))
{
setActive(true);
GasStack stack = RecipeHandler.getChemicalWasherOutput(inputTank, true);
outputTank.receive(stack, true);
fluidTank.drain(WATER_USAGE, true);
operate(recipe);
setEnergy(getEnergy() - ENERGY_USAGE);
}
@ -144,26 +146,24 @@ public class TileEntityChemicalWasher extends TileEntityNoisyElectricBlock imple
}
}
public boolean canOperate()
public WasherRecipe getRecipe()
{
if(fluidTank.getFluidAmount() < WATER_USAGE || inputTank.getGas() == null || outputTank.getNeeded() == 0)
{
return false;
}
return RecipeHandler.getChemicalWasherRecipe(getInput());
}
GasStack out = RecipeHandler.getChemicalWasherOutput(inputTank, false);
public GasInput getInput()
{
return new GasInput(inputTank.getGas());
}
if(out == null || (outputTank.getGas() != null && outputTank.getGas().getGas() != out.getGas()))
{
return false;
}
public boolean canOperate(WasherRecipe recipe)
{
return recipe != null && recipe.canOperate(inputTank, fluidTank, outputTank);
}
if(outputTank.getNeeded() < out.amount)
{
return false;
}
return true;
public void operate(WasherRecipe recipe)
{
recipe.operate(inputTank, fluidTank, outputTank);
}
private void manageBuckets()

View file

@ -8,13 +8,14 @@ import mekanism.api.gas.GasRegistry;
import mekanism.api.gas.GasStack;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.recipe.RecipeHandler.Recipe;
import mekanism.common.recipe.machines.CombinerRecipe;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
public class TileEntityCombiner extends TileEntityAdvancedElectricMachine
public class TileEntityCombiner extends TileEntityAdvancedElectricMachine<CombinerRecipe>
{
public TileEntityCombiner()
{

View file

@ -5,8 +5,9 @@ import java.util.Map;
import mekanism.api.MekanismConfig.usage;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.recipe.RecipeHandler.Recipe;
import mekanism.common.recipe.machines.CrusherRecipe;
public class TileEntityCrusher extends TileEntityElectricMachine
public class TileEntityCrusher extends TileEntityElectricMachine<CrusherRecipe>
{
public TileEntityCrusher()
{

View file

@ -5,6 +5,9 @@ import mekanism.common.Mekanism;
import mekanism.common.MekanismItems;
import mekanism.common.SideData;
import mekanism.common.recipe.RecipeHandler;
import mekanism.common.recipe.inputs.ItemStackInput;
import mekanism.common.recipe.machines.BasicMachineRecipe;
import mekanism.common.recipe.outputs.ItemStackOutput;
import mekanism.common.tile.component.TileComponentEjector;
import mekanism.common.tile.component.TileComponentUpgrade;
import mekanism.common.util.ChargeUtils;
@ -18,7 +21,7 @@ import cpw.mods.fml.common.Optional.Method;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.peripheral.IComputerAccess;
public abstract class TileEntityElectricMachine extends TileEntityBasicMachine
public abstract class TileEntityElectricMachine<RECIPE extends BasicMachineRecipe<RECIPE>> extends TileEntityBasicMachine<ItemStackInput, ItemStackOutput, RECIPE>
{
/**
* A simple electrical machine. This has 3 slots - the input slot (0), the energy slot (1),
@ -57,7 +60,9 @@ public abstract class TileEntityElectricMachine extends TileEntityBasicMachine
{
ChargeUtils.discharge(1, this);
if(canOperate() && MekanismUtils.canFunction(this) && getEnergy() >= MekanismUtils.getEnergyPerTick(this, ENERGY_PER_TICK))
RECIPE recipe = getRecipe();
if(canOperate(recipe) && MekanismUtils.canFunction(this) && getEnergy() >= MekanismUtils.getEnergyPerTick(this, ENERGY_PER_TICK))
{
setActive(true);
@ -68,7 +73,7 @@ public abstract class TileEntityElectricMachine extends TileEntityBasicMachine
}
else if((operatingTicks+1) >= MekanismUtils.getTicks(this, TICKS_REQUIRED))
{
operate();
operate(recipe);
operatingTicks = 0;
electricityStored -= MekanismUtils.getEnergyPerTick(this, ENERGY_PER_TICK);
@ -81,7 +86,7 @@ public abstract class TileEntityElectricMachine extends TileEntityBasicMachine
}
}
if(!canOperate())
if(!canOperate(recipe))
{
operatingTicks = 0;
}
@ -113,55 +118,29 @@ public abstract class TileEntityElectricMachine extends TileEntityBasicMachine
return false;
}
@Override
public void operate()
public ItemStackInput getInput()
{
ItemStack itemstack = RecipeHandler.getOutput(inventory[0], true, getRecipes());
return new ItemStackInput(inventory[0]);
}
if(inventory[0].stackSize <= 0)
{
inventory[0] = null;
}
public RECIPE getRecipe()
{
return RecipeHandler.getRecipe(getInput(), getRecipes());
}
if(inventory[2] == null)
{
inventory[2] = itemstack;
}
else {
inventory[2].stackSize += itemstack.stackSize;
}
@Override
public void operate(RECIPE recipe)
{
recipe.operate(inventory, 0, 2);
markDirty();
ejectorComponent.onOutput();
}
@Override
public boolean canOperate()
public boolean canOperate(RECIPE recipe)
{
if(inventory[0] == null)
{
return false;
}
ItemStack itemstack = RecipeHandler.getOutput(inventory[0], false, getRecipes());
if(itemstack == null)
{
return false;
}
if(inventory[2] == null)
{
return true;
}
if(!inventory[2].isItemEqual(itemstack))
{
return false;
}
else {
return inventory[2].stackSize + itemstack.stackSize <= inventory[2].getMaxStackSize();
}
return recipe != null && recipe.canOperate(inventory, 0, 2);
}
@Override
@ -201,7 +180,7 @@ public abstract class TileEntityElectricMachine extends TileEntityBasicMachine
case 3:
return new Object[] {facing};
case 4:
return new Object[] {canOperate()};
return new Object[] {canOperate(getRecipe())};
case 5:
return new Object[] {getMaxEnergy()};
case 6:

View file

@ -13,6 +13,8 @@ import mekanism.api.gas.GasTransmission;
import mekanism.api.gas.IGasHandler;
import mekanism.api.gas.IGasItem;
import mekanism.api.gas.ITubeConnection;
import mekanism.common.recipe.inputs.FluidInput;
import mekanism.common.recipe.machines.SeparatorRecipe;
import mekanism.common.recipe.outputs.ChemicalPairOutput;
import mekanism.common.Mekanism;
import mekanism.common.base.ISustainedData;
@ -87,6 +89,8 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
{
ChargeUtils.discharge(3, this);
SeparatorRecipe recipe = getRecipe();
if(inventory[0] != null)
{
if(RecipeHandler.Recipe.ELECTROLYTIC_SEPARATOR.containsRecipe(inventory[0]))
@ -98,7 +102,7 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
else {
FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(inventory[0]);
if(fluid != null && fluidTank.getFluid() == null || fluid.isFluidEqual(fluidTank.getFluid()) && fluidTank.getFluid().amount+fluid.amount <= fluidTank.getCapacity())
if(fluid != null && (fluidTank.getFluid() == null || fluid.isFluidEqual(fluidTank.getFluid()) && fluidTank.getFluid().amount+fluid.amount <= fluidTank.getCapacity()))
{
fluidTank.fill(fluid, true);
@ -119,26 +123,23 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
}
}
if(!worldObj.isRemote)
if(inventory[1] != null && leftTank.getStored() > 0)
{
if(inventory[1] != null && leftTank.getStored() > 0)
{
leftTank.draw(GasTransmission.addGas(inventory[1], leftTank.getGas()), true);
MekanismUtils.saveChunk(this);
}
if(inventory[2] != null && rightTank.getStored() > 0)
{
rightTank.draw(GasTransmission.addGas(inventory[2], rightTank.getGas()), true);
MekanismUtils.saveChunk(this);
}
leftTank.draw(GasTransmission.addGas(inventory[1], leftTank.getGas()), true);
MekanismUtils.saveChunk(this);
}
if(canOperate())
if(inventory[2] != null && rightTank.getStored() > 0)
{
rightTank.draw(GasTransmission.addGas(inventory[2], rightTank.getGas()), true);
MekanismUtils.saveChunk(this);
}
if(canOperate(recipe) && getEnergy() >= recipe.extraEnergy)
{
setActive(true);
fillTanks(RecipeHandler.getElectrolyticSeparatorOutput(fluidTank, true));
setEnergy(getEnergy() - general.FROM_H2*2);
operate(recipe);
setEnergy(getEnergy() - recipe.extraEnergy);
}
else {
setActive(false);
@ -199,19 +200,24 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
}
}
public boolean canOperate()
public SeparatorRecipe getRecipe()
{
return canFillWithSwap(RecipeHandler.getElectrolyticSeparatorOutput(fluidTank, false)) && getEnergy() >= general.FROM_H2*2;
return RecipeHandler.getElectrolyticSeparatorRecipe(getInput());
}
public boolean canFillWithSwap(ChemicalPairOutput gases)
public FluidInput getInput()
{
if(gases == null)
{
return false;
}
return new FluidInput(fluidTank.getFluid());
}
return canFill(gases) || canFill(gases.swap());
public boolean canOperate(SeparatorRecipe recipe)
{
return recipe != null && recipe.canOperate(fluidTank, leftTank, rightTank);
}
public void operate(SeparatorRecipe recipe)
{
recipe.operate(fluidTank, leftTank, rightTank);
}
public boolean canFill(ChemicalPairOutput gases)
@ -220,22 +226,6 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
&& rightTank.canReceive(gases.rightGas.getGas()) && rightTank.getNeeded() >= gases.rightGas.amount);
}
public void fillTanks(ChemicalPairOutput gases)
{
if(gases == null) return;
if(canFill(gases))
{
leftTank.receive(gases.leftGas, true);
rightTank.receive(gases.rightGas, true);
}
else if(canFill(gases.swap()))
{
leftTank.receive(gases.rightGas, true);
rightTank.receive(gases.leftGas, true);
}
}
public void spawnParticle(int type)
{
if(type == 0)
@ -326,36 +316,6 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
return InventoryUtils.EMPTY;
}
/**
* Gets the scaled hydrogen level for the GUI.
* @param i - multiplier
* @return
*/
public int getLeftScaledLevel(int i)
{
return leftTank.getStored()*i / MAX_GAS;
}
/**
* Gets the scaled oxygen level for the GUI.
* @param i - multiplier
* @return
*/
public int getRightScaledLevel(int i)
{
return rightTank.getStored()*i / MAX_GAS;
}
/**
* Gets the scaled water level for the GUI.
* @param i - multiplier
* @return
*/
public int getScaledFluidLevel(int i)
{
return fluidTank.getFluid() != null ? fluidTank.getFluid().amount*i / fluidTank.getCapacity() : 0;
}
/**
* Gets the scaled energy level for the GUI.
* @param i - multiplier

View file

@ -5,8 +5,9 @@ import java.util.Map;
import mekanism.api.MekanismConfig.usage;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.recipe.RecipeHandler.Recipe;
import mekanism.common.recipe.machines.EnrichmentRecipe;
public class TileEntityEnrichmentChamber extends TileEntityElectricMachine
public class TileEntityEnrichmentChamber extends TileEntityElectricMachine<EnrichmentRecipe>
{
public TileEntityEnrichmentChamber()
{

View file

@ -27,6 +27,9 @@ import mekanism.common.base.IRedstoneControl;
import mekanism.common.base.IUpgradeTile;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.recipe.machines.AdvancedMachineRecipe;
import mekanism.common.recipe.machines.BasicMachineRecipe;
import mekanism.common.recipe.machines.MachineRecipe;
import mekanism.common.tile.component.TileComponentEjector;
import mekanism.common.tile.component.TileComponentUpgrade;
import mekanism.common.util.ChargeUtils;
@ -84,7 +87,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
public int updateDelay;
/** This machine's recipe type. */
public int recipeType;
public RecipeType recipeType;
/** This machine's previous amount of energy. */
public double prevEnergy;
@ -176,7 +179,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
}
}
if(toSet != null && recipeType != toSet.ordinal())
if(toSet != null && recipeType != toSet)
{
if(recipeTicks < RECIPE_TICKS_REQUIRED)
{
@ -198,7 +201,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
inventory[2] = null;
inventory[3] = returnStack;
recipeType = toSet.ordinal();
recipeType = toSet;
gasTank.setGas(null);
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, getBlockType());
@ -236,7 +239,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
if(!canOperate(getInputSlot(process), getOutputSlot(process)))
{
if(!RecipeType.values()[recipeType].usesFuel() || !RecipeType.values()[recipeType].hasRecipe(inventory[getInputSlot(process)]))
if(!recipeType.usesFuel() || !recipeType.hasRecipe(inventory[getInputSlot(process)]))
{
progress[process] = 0;
}
@ -349,18 +352,18 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
public int getSecondaryEnergyPerTick()
{
return MekanismUtils.getSecondaryEnergyPerTick(this, RecipeType.values()[recipeType].getSecondaryEnergyPerTick());
return MekanismUtils.getSecondaryEnergyPerTick(this, recipeType.getSecondaryEnergyPerTick());
}
public void handleSecondaryFuel()
{
if(inventory[4] != null && RecipeType.values()[recipeType].usesFuel() && gasTank.getNeeded() > 0)
if(inventory[4] != null && recipeType.usesFuel() && gasTank.getNeeded() > 0)
{
if(inventory[4].getItem() instanceof IGasItem)
{
GasStack gas = ((IGasItem)inventory[4].getItem()).getGas(inventory[4]);
if(gas != null && RecipeType.values()[recipeType].isValidGas(gas.getGas()))
if(gas != null && recipeType.isValidGas(gas.getGas()))
{
GasStack removed = GasTransmission.removeGas(inventory[4], gasTank.getGasType(), gasTank.getNeeded());
gasTank.receive(removed, true);
@ -369,7 +372,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
return;
}
GasStack stack = RecipeType.values()[recipeType].getItemGas(inventory[4]);
GasStack stack = recipeType.getItemGas(inventory[4]);
int gasNeeded = gasTank.getNeeded();
if(stack != null && stack.amount <= gasNeeded)
@ -388,7 +391,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
public ItemStack getMachineStack()
{
return RecipeType.values()[recipeType].getStack();
return recipeType.getStack();
}
@Override
@ -425,7 +428,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
}
else if(slotID >= 5 && slotID <= 7)
{
return RecipeType.values()[recipeType].getCopiedOutput(itemstack, gasTank.getGas() != null ? gasTank.getGas().getGas() : null, false) != null;
return recipeType.getAnyRecipe(itemstack, gasTank.getGasType()) != null;
}
}
else if(tier == FactoryTier.ADVANCED)
@ -436,7 +439,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
}
else if(slotID >= 5 && slotID <= 9)
{
return RecipeType.values()[recipeType].getCopiedOutput(itemstack, gasTank.getGas() != null ? gasTank.getGas().getGas() : null, false) != null;
return recipeType.getAnyRecipe(itemstack, gasTank.getGasType()) != null;
}
}
else if(tier == FactoryTier.ELITE)
@ -447,7 +450,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
}
else if(slotID >= 5 && slotID <= 11)
{
return RecipeType.values()[recipeType].getCopiedOutput(itemstack, gasTank.getGas() != null ? gasTank.getGas().getGas() : null, false) != null;
return recipeType.getAnyRecipe(itemstack, gasTank.getGasType()) != null;
}
}
@ -461,7 +464,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
}
else if(slotID == 4)
{
return RecipeType.values()[recipeType].getItemGas(itemstack) != null;
return recipeType.getItemGas(itemstack) != null;
}
return false;
@ -489,25 +492,26 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
return false;
}
ItemStack itemstack = RecipeType.values()[recipeType].getCopiedOutput(inventory[inputSlot], gasTank.getGas() != null ? gasTank.getGas().getGas() : null, false);
if(recipeType.usesFuel())
{
AdvancedMachineRecipe<?> recipe = recipeType.getRecipe(inventory[inputSlot], gasTank.getGasType());
if(itemstack == null)
if(recipe == null)
{
return false;
}
return recipe.canOperate(inventory, inputSlot, outputSlot, gasTank, MekanismUtils.getSecondaryEnergyPerTick(this, recipeType.getSecondaryEnergyPerTick()));
}
BasicMachineRecipe<?> recipe = recipeType.getRecipe(inventory[inputSlot]);
if(recipe == null)
{
return false;
}
if(inventory[outputSlot] == null)
{
return true;
}
if(!inventory[outputSlot].isItemEqual(itemstack))
{
return false;
}
else {
return inventory[outputSlot].stackSize + itemstack.stackSize <= inventory[outputSlot].getMaxStackSize();
}
return recipe.canOperate(inventory, inputSlot, outputSlot);
}
public void operate(int inputSlot, int outputSlot)
@ -517,19 +521,17 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
return;
}
ItemStack itemstack = RecipeType.values()[recipeType].getCopiedOutput(inventory[inputSlot], gasTank.getGas() != null ? gasTank.getGas().getGas() : null, true);
if(inventory[inputSlot].stackSize <= 0)
if(recipeType.usesFuel())
{
inventory[inputSlot] = null;
}
AdvancedMachineRecipe<?> recipe = recipeType.getRecipe(inventory[inputSlot], gasTank.getGasType());
if(inventory[outputSlot] == null)
{
inventory[outputSlot] = itemstack;
recipe.operate(inventory, inputSlot, outputSlot, gasTank, MekanismUtils.getSecondaryEnergyPerTick(this, recipeType.getSecondaryEnergyPerTick()));
}
else {
inventory[outputSlot].stackSize += itemstack.stackSize;
else
{
BasicMachineRecipe<?> recipe = recipeType.getRecipe(inventory[inputSlot]);
recipe.operate(inventory, inputSlot, outputSlot);
}
markDirty();
@ -554,7 +556,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
super.handlePacketData(dataStream);
clientActive = dataStream.readBoolean();
recipeType = dataStream.readInt();
recipeType = RecipeType.values()[dataStream.readInt()];
recipeTicks = dataStream.readInt();
controlType = RedstoneControl.values()[dataStream.readInt()];
sorting = dataStream.readBoolean();
@ -591,7 +593,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
super.readFromNBT(nbtTags);
clientActive = isActive = nbtTags.getBoolean("isActive");
recipeType = nbtTags.getInteger("recipeType");
recipeType = RecipeType.values()[nbtTags.getInteger("recipeType")];
recipeTicks = nbtTags.getInteger("recipeTicks");
controlType = RedstoneControl.values()[nbtTags.getInteger("controlType")];
sorting = nbtTags.getBoolean("sorting");
@ -618,7 +620,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
super.writeToNBT(nbtTags);
nbtTags.setBoolean("isActive", isActive);
nbtTags.setInteger("recipeType", recipeType);
nbtTags.setInteger("recipeType", recipeType.ordinal());
nbtTags.setInteger("recipeTicks", recipeTicks);
nbtTags.setInteger("controlType", controlType.ordinal());
nbtTags.setBoolean("sorting", sorting);
@ -816,7 +818,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
@Override
public ResourceLocation getSoundLocation()
{
return RecipeType.values()[recipeType].getSound();
return recipeType.getSound();
}
@Override
@ -870,13 +872,13 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
@Override
public boolean canReceiveGas(ForgeDirection side, Gas type)
{
return RecipeType.values()[recipeType].canReceiveGas(side, type);
return recipeType.canReceiveGas(side, type);
}
@Override
public boolean canTubeConnect(ForgeDirection side)
{
return RecipeType.values()[recipeType].canTubeConnect(side);
return recipeType.canTubeConnect(side);
}
@Override

View file

@ -9,9 +9,9 @@ import mekanism.api.MekanismConfig.usage;
import mekanism.api.Range4D;
import mekanism.api.infuse.InfuseObject;
import mekanism.api.infuse.InfuseRegistry;
import mekanism.api.infuse.InfuseType;
import mekanism.common.InfuseStorage;
import mekanism.common.recipe.inputs.InfusionInput;
import mekanism.common.recipe.outputs.InfusionOutput;
import mekanism.common.recipe.machines.MetallurgicInfuserRecipe;
import mekanism.common.Mekanism;
import mekanism.common.MekanismItems;
import mekanism.common.PacketHandler;
@ -50,9 +50,6 @@ public class TileEntityMetallurgicInfuser extends TileEntityNoisyElectricBlock i
/** An arraylist of SideData for this machine. */
public ArrayList<SideData> sideOutputs = new ArrayList<SideData>();
/** The type of infuse this machine stores. */
public InfuseType type = null;
/** The maxiumum amount of infuse this machine can store. */
public int MAX_INFUSE = 1000;
@ -63,7 +60,7 @@ public class TileEntityMetallurgicInfuser extends TileEntityNoisyElectricBlock i
public int TICKS_REQUIRED = 200;
/** The amount of infuse this machine has stored. */
public int infuseStored;
public InfuseStorage infuseStored = new InfuseStorage();
/** How many ticks this machine has been operating for. */
public int operatingTicks;
@ -137,12 +134,12 @@ public class TileEntityMetallurgicInfuser extends TileEntityNoisyElectricBlock i
{
InfuseObject infuse = InfuseRegistry.getObject(inventory[1]);
if(type == null || type == infuse.type)
if(infuseStored.type == null || infuseStored.type == infuse.type)
{
if(infuseStored+infuse.stored <= MAX_INFUSE)
if(infuseStored.amount + infuse.stored <= MAX_INFUSE)
{
infuseStored+=infuse.stored;
type = infuse.type;
infuseStored.amount += infuse.stored;
infuseStored.type = infuse.type;
inventory[1].stackSize--;
if(inventory[1].stackSize <= 0)
@ -154,21 +151,23 @@ public class TileEntityMetallurgicInfuser extends TileEntityNoisyElectricBlock i
}
}
if(canOperate() && MekanismUtils.canFunction(this) && getEnergy() >= MekanismUtils.getEnergyPerTick(this, ENERGY_PER_TICK))
MetallurgicInfuserRecipe recipe = RecipeHandler.getMetallurgicInfuserRecipe(getInput());
if(MekanismUtils.canFunction(this) && getEnergy() >= MekanismUtils.getEnergyPerTick(this, ENERGY_PER_TICK))
{
setActive(true);
if((operatingTicks+1) < MekanismUtils.getTicks(this, TICKS_REQUIRED))
if(canOperate(recipe))
{
operatingTicks++;
setActive(true);
setEnergy(getEnergy() - MekanismUtils.getEnergyPerTick(this, ENERGY_PER_TICK));
}
else if((operatingTicks+1) >= MekanismUtils.getTicks(this, TICKS_REQUIRED))
{
operate();
operatingTicks = 0;
setEnergy(getEnergy() - MekanismUtils.getEnergyPerTick(this, ENERGY_PER_TICK));
if((operatingTicks + 1) < MekanismUtils.getTicks(this, TICKS_REQUIRED))
{
operatingTicks++;
} else
{
operate(recipe);
operatingTicks = 0;
}
}
}
else {
@ -178,15 +177,15 @@ public class TileEntityMetallurgicInfuser extends TileEntityNoisyElectricBlock i
}
}
if(!canOperate())
if(!canOperate(recipe))
{
operatingTicks = 0;
}
if(infuseStored <= 0)
if(infuseStored.amount <= 0)
{
infuseStored = 0;
type = null;
infuseStored.amount = 0;
infuseStored.type = null;
}
prevEnergy = getEnergy();
@ -217,7 +216,7 @@ public class TileEntityMetallurgicInfuser extends TileEntityNoisyElectricBlock i
}
else if(slotID == 1)
{
return InfuseRegistry.getObject(itemstack) != null && (type == null || type == InfuseRegistry.getObject(itemstack).type);
return InfuseRegistry.getObject(itemstack) != null && (infuseStored.type == null || infuseStored.type == InfuseRegistry.getObject(itemstack).type);
}
else if(slotID == 0)
{
@ -225,9 +224,9 @@ public class TileEntityMetallurgicInfuser extends TileEntityNoisyElectricBlock i
}
else if(slotID == 2)
{
if(type != null)
if(infuseStored.type != null)
{
if(RecipeHandler.getMetallurgicInfuserOutput(InfusionInput.getInfusion(type, infuseStored, itemstack), false) != null)
if(RecipeHandler.getMetallurgicInfuserRecipe(new InfusionInput(infuseStored, itemstack)) != null)
{
return true;
}
@ -251,69 +250,27 @@ public class TileEntityMetallurgicInfuser extends TileEntityNoisyElectricBlock i
return false;
}
public void operate()
public InfusionInput getInput()
{
if(!canOperate())
{
return;
}
return new InfusionInput(infuseStored, inventory[2]);
}
InfusionOutput output = RecipeHandler.getMetallurgicInfuserOutput(InfusionInput.getInfusion(type, infuseStored, inventory[2]), true);
infuseStored -= output.getInfuseRequired();
if(inventory[2].stackSize <= 0)
{
inventory[2] = null;
}
if(inventory[3] == null)
{
inventory[3] = output.resource.copy();
}
else {
inventory[3].stackSize += output.resource.stackSize;
}
public void operate(MetallurgicInfuserRecipe recipe)
{
recipe.output(inventory, infuseStored);
markDirty();
ejectorComponent.onOutput();
}
public boolean canOperate()
public boolean canOperate(MetallurgicInfuserRecipe recipe)
{
if(inventory[2] == null)
{
return false;
}
InfusionOutput output = RecipeHandler.getMetallurgicInfuserOutput(InfusionInput.getInfusion(type, infuseStored, inventory[2]), false);
if(output == null)
{
return false;
}
if(infuseStored-output.getInfuseRequired() < 0)
{
return false;
}
if(inventory[3] == null)
{
return true;
}
if(!inventory[3].isItemEqual(output.resource))
{
return false;
}
else {
return inventory[3].stackSize + output.resource.stackSize <= inventory[3].getMaxStackSize();
}
return recipe != null && recipe.canOperate(inventory, infuseStored);
}
public int getScaledInfuseLevel(int i)
{
return infuseStored*i / MAX_INFUSE;
return infuseStored.amount * i / MAX_INFUSE;
}
public double getScaledProgress()
@ -328,9 +285,9 @@ public class TileEntityMetallurgicInfuser extends TileEntityNoisyElectricBlock i
clientActive = isActive = nbtTags.getBoolean("isActive");
operatingTicks = nbtTags.getInteger("operatingTicks");
infuseStored = nbtTags.getInteger("infuseStored");
infuseStored.amount = nbtTags.getInteger("infuseStored");
controlType = RedstoneControl.values()[nbtTags.getInteger("controlType")];
type = InfuseRegistry.get(nbtTags.getString("type"));
infuseStored.type = InfuseRegistry.get(nbtTags.getString("type"));
if(nbtTags.hasKey("sideDataStored"))
{
@ -348,12 +305,12 @@ public class TileEntityMetallurgicInfuser extends TileEntityNoisyElectricBlock i
nbtTags.setBoolean("isActive", isActive);
nbtTags.setInteger("operatingTicks", operatingTicks);
nbtTags.setInteger("infuseStored", infuseStored);
nbtTags.setInteger("infuseStored", infuseStored.amount);
nbtTags.setInteger("controlType", controlType.ordinal());
if(type != null)
if(infuseStored.type != null)
{
nbtTags.setString("type", type.name);
nbtTags.setString("type", infuseStored.type.name);
}
else {
nbtTags.setString("type", "null");
@ -372,7 +329,7 @@ public class TileEntityMetallurgicInfuser extends TileEntityNoisyElectricBlock i
{
if(!worldObj.isRemote)
{
infuseStored = dataStream.readInt();
infuseStored.amount = dataStream.readInt();
return;
}
@ -380,9 +337,9 @@ public class TileEntityMetallurgicInfuser extends TileEntityNoisyElectricBlock i
clientActive = dataStream.readBoolean();
operatingTicks = dataStream.readInt();
infuseStored = dataStream.readInt();
infuseStored.amount = dataStream.readInt();
controlType = RedstoneControl.values()[dataStream.readInt()];
type = InfuseRegistry.get(PacketHandler.readString(dataStream));
infuseStored.type = InfuseRegistry.get(PacketHandler.readString(dataStream));
for(int i = 0; i < 6; i++)
{
@ -407,9 +364,9 @@ public class TileEntityMetallurgicInfuser extends TileEntityNoisyElectricBlock i
data.add(infuseStored);
data.add(controlType.ordinal());
if(type != null)
if(infuseStored.type != null)
{
data.add(type.name);
data.add(infuseStored.type.name);
}
else {
data.add("null");
@ -446,7 +403,7 @@ public class TileEntityMetallurgicInfuser extends TileEntityNoisyElectricBlock i
case 2:
return new Object[] {facing};
case 3:
return new Object[] {canOperate()};
return new Object[] {canOperate(RecipeHandler.getMetallurgicInfuserRecipe(getInput()))};
case 4:
return new Object[] {getMaxEnergy()};
case 5:
@ -454,7 +411,7 @@ public class TileEntityMetallurgicInfuser extends TileEntityNoisyElectricBlock i
case 6:
return new Object[] {infuseStored};
case 7:
return new Object[] {MAX_INFUSE-infuseStored};
return new Object[] {MAX_INFUSE-infuseStored.amount};
default:
Mekanism.logger.error("Attempted to call unknown method with computer ID " + computer.getID());
return new Object[] {"Unknown command."};

View file

@ -12,6 +12,7 @@ import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasTank;
import mekanism.api.gas.IGasHandler;
import mekanism.api.gas.ITubeConnection;
import mekanism.common.recipe.inputs.PressurizedInput;
import mekanism.common.recipe.outputs.PressurizedProducts;
import mekanism.common.recipe.machines.PressurizedRecipe;
import mekanism.common.SideData;
@ -44,7 +45,7 @@ import io.netty.buffer.ByteBuf;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.peripheral.IComputerAccess;
public class TileEntityPRC extends TileEntityBasicMachine implements IFluidHandler, IGasHandler, ITubeConnection, ISustainedData
public class TileEntityPRC extends TileEntityBasicMachine<PressurizedInput, PressurizedProducts, PressurizedRecipe> implements IFluidHandler, IGasHandler, ITubeConnection, ISustainedData
{
public FluidTank inputFluidTank = new FluidTank(10000);
public GasTank inputGasTank = new GasTank(10000);
@ -76,11 +77,12 @@ public class TileEntityPRC extends TileEntityBasicMachine implements IFluidHandl
if(!worldObj.isRemote)
{
PressurizedRecipe recipe = getRecipe();
ChargeUtils.discharge(1, this);
if(canOperate() && MekanismUtils.canFunction(this) && getEnergy() >= MekanismUtils.getEnergyPerTick(this, ENERGY_PER_TICK))
if(canOperate(recipe) && MekanismUtils.canFunction(this) && getEnergy() >= MekanismUtils.getEnergyPerTick(this, ENERGY_PER_TICK))
{
PressurizedRecipe recipe = getRecipe();
TICKS_REQUIRED = recipe.ticks;
setActive(true);
@ -91,7 +93,7 @@ public class TileEntityPRC extends TileEntityBasicMachine implements IFluidHandl
}
else if((operatingTicks+1) >= MekanismUtils.getTicks(this, TICKS_REQUIRED) && electricityStored >= MekanismUtils.getEnergyPerTick(this, ENERGY_PER_TICK + recipe.extraEnergy))
{
operate();
operate(recipe);
operatingTicks = 0;
electricityStored -= MekanismUtils.getEnergyPerTick(this, ENERGY_PER_TICK + recipe.extraEnergy);
@ -106,7 +108,7 @@ public class TileEntityPRC extends TileEntityBasicMachine implements IFluidHandl
}
}
if(!canOperate())
if(!canOperate(recipe))
{
operatingTicks = 0;
}
@ -150,60 +152,30 @@ public class TileEntityPRC extends TileEntityBasicMachine implements IFluidHandl
}
@Override
public void operate()
public PressurizedRecipe getRecipe()
{
PressurizedRecipe recipe = getRecipe();
return RecipeHandler.getPRCRecipe(getInput());
}
recipe.getInput().use(inventory[0], inputFluidTank, inputGasTank);
@Override
public PressurizedInput getInput()
{
return new PressurizedInput(inventory[0], inputFluidTank.getFluid(), inputGasTank.getGas());
}
if(inventory[0].stackSize <= 0)
{
inventory[0] = null;
}
recipe.getOutput().fillTank(outputGasTank);
recipe.getOutput().addProducts(inventory, 2);
@Override
public void operate(PressurizedRecipe recipe)
{
recipe.operate(inventory, inputFluidTank, inputGasTank, outputGasTank);
markDirty();
ejectorComponent.onOutput();
}
@Override
public boolean canOperate()
public boolean canOperate(PressurizedRecipe recipe)
{
PressurizedRecipe recipe = getRecipe();
if(recipe == null)
{
return false;
}
PressurizedProducts products = recipe.getOutput();
if(products.getItemOutput() != null)
{
if(inventory[2] != null)
{
if(!inventory[2].isItemEqual(products.getItemOutput()))
{
return false;
}
else {
if(inventory[2].stackSize + products.getItemOutput().stackSize > inventory[2].getMaxStackSize())
{
return false;
}
}
}
}
if(products.getGasOutput() != null && outputGasTank.getGas() != null)
{
return products.getGasOutput().isGasEqual(outputGasTank.getGas()) && products.getGasOutput().amount <= outputGasTank.getNeeded();
}
return true;
return recipe != null && recipe.canOperate(inventory, inputFluidTank, inputGasTank, outputGasTank);
}
@Override
@ -212,16 +184,6 @@ public class TileEntityPRC extends TileEntityBasicMachine implements IFluidHandl
return MekanismUtils.getMaxEnergy(this, MAX_ELECTRICITY);
}
public PressurizedRecipe getRecipe()
{
if(inventory[0] == null)
{
return null;
}
return RecipeHandler.getPRCOutput(inventory[0], inputFluidTank, inputGasTank);
}
@Override
public boolean canExtractItem(int slotID, ItemStack itemstack, int side)
{

View file

@ -5,10 +5,12 @@ import java.util.Map;
import mekanism.api.MekanismConfig.usage;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.recipe.RecipeHandler.Recipe;
import mekanism.common.recipe.inputs.ItemStackInput;
import mekanism.common.recipe.machines.SawmillRecipe;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.MekanismUtils.ResourceType;
public class TileEntityPrecisionSawmill extends TileEntityChanceMachine
public class TileEntityPrecisionSawmill extends TileEntityChanceMachine<SawmillRecipe>
{
public TileEntityPrecisionSawmill()
{
@ -16,7 +18,7 @@ public class TileEntityPrecisionSawmill extends TileEntityChanceMachine
}
@Override
public Map getRecipes()
public Map<ItemStackInput, SawmillRecipe> getRecipes()
{
return Recipe.PRECISION_SAWMILL.get();
}