diff --git a/common/mekanism/common/IFactory.java b/common/mekanism/common/IFactory.java index 7b2f5a190..7b6a1138e 100644 --- a/common/mekanism/common/IFactory.java +++ b/common/mekanism/common/IFactory.java @@ -10,6 +10,7 @@ import mekanism.common.tile.TileEntityAdvancedElectricMachine; import mekanism.common.util.MekanismUtils; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.FurnaceRecipes; +import net.minecraftforge.common.ForgeDirection; /** * Internal interface for managing various Factory types. @@ -102,6 +103,36 @@ public interface IFactory return 0; } + public boolean canReceiveGas(ForgeDirection side, Gas type) + { + if(usesFuel) + { + return getTile().canReceiveGas(side, type); + } + + return false; + } + + public boolean canTubeConnect(ForgeDirection side) + { + if(usesFuel) + { + return getTile().canTubeConnect(side); + } + + return false; + } + + public boolean isValidGas(Gas gas) + { + if(usesFuel) + { + return getTile().isValidGas(gas); + } + + return false; + } + public TileEntityAdvancedElectricMachine getTile() { if(cacheTile == null) diff --git a/common/mekanism/common/tile/TileEntityAdvancedElectricMachine.java b/common/mekanism/common/tile/TileEntityAdvancedElectricMachine.java index f937055b8..03b98c246 100644 --- a/common/mekanism/common/tile/TileEntityAdvancedElectricMachine.java +++ b/common/mekanism/common/tile/TileEntityAdvancedElectricMachine.java @@ -79,6 +79,8 @@ public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicM * @return fuel ticks */ public abstract GasStack getItemGas(ItemStack itemstack); + + public abstract boolean isValidGas(Gas gas); @Override public void onUpdate() diff --git a/common/mekanism/common/tile/TileEntityChemicalInjectionChamber.java b/common/mekanism/common/tile/TileEntityChemicalInjectionChamber.java index 812827b29..e245510d8 100644 --- a/common/mekanism/common/tile/TileEntityChemicalInjectionChamber.java +++ b/common/mekanism/common/tile/TileEntityChemicalInjectionChamber.java @@ -66,7 +66,7 @@ public class TileEntityChemicalInjectionChamber extends TileEntityAdvancedElectr if(isValidGas(gas)) { - GasStack removed = GasTransmission.removeGas(inventory[1], gas, gasTank.getNeeded()); + GasStack removed = GasTransmission.removeGas(inventory[1], gasTank.getGas() != null ? gasTank.getGas().getGas() : null, gasTank.getNeeded()); gasTank.receive(removed, true); } @@ -82,6 +82,7 @@ public class TileEntityChemicalInjectionChamber extends TileEntityAdvancedElectr return true; } + @Override public boolean isValidGas(Gas gas) { return gas == GasRegistry.getGas("sulfuricAcid") || gas == GasRegistry.getGas("water") || gas == GasRegistry.getGas("hydrogenChloride"); diff --git a/common/mekanism/common/tile/TileEntityCombiner.java b/common/mekanism/common/tile/TileEntityCombiner.java index f7776976f..fbcd8372b 100644 --- a/common/mekanism/common/tile/TileEntityCombiner.java +++ b/common/mekanism/common/tile/TileEntityCombiner.java @@ -2,6 +2,7 @@ package mekanism.common.tile; import java.util.Map; +import mekanism.api.gas.Gas; import mekanism.api.gas.GasRegistry; import mekanism.api.gas.GasStack; import mekanism.common.Mekanism; @@ -35,4 +36,10 @@ public class TileEntityCombiner extends TileEntityAdvancedElectricMachine return null; } + + @Override + public boolean isValidGas(Gas gas) + { + return false; + } } diff --git a/common/mekanism/common/tile/TileEntityFactory.java b/common/mekanism/common/tile/TileEntityFactory.java index d2db034b8..162b16bf5 100644 --- a/common/mekanism/common/tile/TileEntityFactory.java +++ b/common/mekanism/common/tile/TileEntityFactory.java @@ -343,25 +343,17 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IPerip { if(inventory[4] != null && RecipeType.values()[recipeType].usesFuel() && gasTank.getNeeded() > 0) { - if(recipeType == RecipeType.PURIFYING.ordinal()) + if(inventory[4].getItem() instanceof IGasItem) { - if(inventory[4].getItem() instanceof IGasItem) + Gas gas = ((IGasItem)inventory[4].getItem()).getGas(inventory[4]).getGas(); + + if(RecipeType.values()[recipeType].isValidGas(gas)) { - GasStack removed = GasTransmission.removeGas(inventory[4], GasRegistry.getGas("oxygen"), gasTank.getNeeded()); + GasStack removed = GasTransmission.removeGas(inventory[4], gasTank.getGas() != null ? gasTank.getGas().getGas() : null, gasTank.getNeeded()); gasTank.receive(removed, true); - - return; - } - } - else if(recipeType == RecipeType.INJECTING.ordinal()) - { - if(inventory[4].getItem() instanceof IGasItem) - { - GasStack removed = GasTransmission.removeGas(inventory[4], GasRegistry.getGas("sulfuricAcid"), gasTank.getNeeded()); - gasTank.receive(removed, true); - - return; } + + return; } GasStack stack = RecipeType.values()[recipeType].getItemGas(inventory[4]); @@ -897,8 +889,7 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IPerip @Override public int receiveGas(ForgeDirection side, GasStack stack) { - if(recipeType == RecipeType.PURIFYING.ordinal() && stack.getGas() == GasRegistry.getGas("oxygen") || - recipeType == RecipeType.INJECTING.ordinal() && stack.getGas() == GasRegistry.getGas("sulfuricAcid")) + if(canReceiveGas(side, stack.getGas())) { return gasTank.receive(stack, true); } @@ -909,14 +900,13 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IPerip @Override public boolean canReceiveGas(ForgeDirection side, Gas type) { - return recipeType == RecipeType.PURIFYING.ordinal() && type == GasRegistry.getGas("oxygen") || - recipeType == RecipeType.INJECTING.ordinal() && type == GasRegistry.getGas("sulfuricAcid"); + return RecipeType.values()[recipeType].canReceiveGas(side, type); } @Override public boolean canTubeConnect(ForgeDirection side) { - return recipeType == RecipeType.PURIFYING.ordinal() || recipeType == RecipeType.INJECTING.ordinal(); + return RecipeType.values()[recipeType].canTubeConnect(side); } @Override diff --git a/common/mekanism/common/tile/TileEntityGasTank.java b/common/mekanism/common/tile/TileEntityGasTank.java index 6585961ad..876aa3194 100644 --- a/common/mekanism/common/tile/TileEntityGasTank.java +++ b/common/mekanism/common/tile/TileEntityGasTank.java @@ -50,7 +50,7 @@ public class TileEntityGasTank extends TileEntityContainerBlock implements IGasH if(inventory[1] != null && (gasTank.getGas() == null || gasTank.getGas().amount < gasTank.getMaxGas())) { - gasTank.receive(GasTransmission.removeGas(inventory[1], null, gasTank.getNeeded()), true); + gasTank.receive(GasTransmission.removeGas(inventory[1], gasTank.getGas() != null ? gasTank.getGas().getGas() : null, gasTank.getNeeded()), true); } if(!worldObj.isRemote && gasTank.getGas() != null && MekanismUtils.canFunction(this)) diff --git a/common/mekanism/common/tile/TileEntityOsmiumCompressor.java b/common/mekanism/common/tile/TileEntityOsmiumCompressor.java index 43f586400..4884c6aa6 100644 --- a/common/mekanism/common/tile/TileEntityOsmiumCompressor.java +++ b/common/mekanism/common/tile/TileEntityOsmiumCompressor.java @@ -2,6 +2,7 @@ package mekanism.common.tile; import java.util.Map; +import mekanism.api.gas.Gas; import mekanism.api.gas.GasRegistry; import mekanism.api.gas.GasStack; import mekanism.common.Mekanism; @@ -47,4 +48,10 @@ public class TileEntityOsmiumCompressor extends TileEntityAdvancedElectricMachin return null; } + + @Override + public boolean isValidGas(Gas gas) + { + return false; + } } diff --git a/common/mekanism/common/tile/TileEntityPurificationChamber.java b/common/mekanism/common/tile/TileEntityPurificationChamber.java index e180207ee..129cb752f 100644 --- a/common/mekanism/common/tile/TileEntityPurificationChamber.java +++ b/common/mekanism/common/tile/TileEntityPurificationChamber.java @@ -75,4 +75,10 @@ public class TileEntityPurificationChamber extends TileEntityAdvancedElectricMac { return true; } + + @Override + public boolean isValidGas(Gas gas) + { + return gas == GasRegistry.getGas("oxygen"); + } }