Don't hard code some machines to specific gas types

This commit is contained in:
pupnewfster authored and Dave Smith committed 2019-03-12 11:36:52 -06:00
1 parent f8b162bc31
commit d8b6dfbb78
21 files changed
+181 -282

No files matched your search

@@ -33,17 +33,13 @@ import mekanism.client.gui.GuiThermalEvaporationController;
import mekanism.client.gui.element.GuiProgress.ProgressBar;
import mekanism.client.jei.gas.GasStackRenderer;
import mekanism.client.jei.machine.AdvancedMachineRecipeCategory;
import mekanism.client.jei.machine.AdvancedMachineRecipeWrapper;
import mekanism.client.jei.machine.ChanceMachineRecipeCategory;
import mekanism.client.jei.machine.ChanceMachineRecipeWrapper;
import mekanism.client.jei.machine.DoubleMachineRecipeCategory;
import mekanism.client.jei.machine.DoubleMachineRecipeWrapper;
import mekanism.client.jei.machine.MachineRecipeCategory;
import mekanism.client.jei.machine.advanced.ChemicalInjectionChamberRecipeWrapper;
import mekanism.client.jei.machine.advanced.CombinerRecipeWrapper;
import mekanism.client.jei.machine.advanced.OsmiumCompressorRecipeWrapper;
import mekanism.client.jei.machine.advanced.PurificationChamberRecipeWrapper;
import mekanism.client.jei.machine.basic.CrusherRecipeWrapper;
import mekanism.client.jei.machine.basic.EnrichmentRecipeWrapper;
import mekanism.client.jei.machine.basic.SmeltingRecipeWrapper;
import mekanism.client.jei.machine.chance.PrecisionSawmillRecipeWrapper;
import mekanism.client.jei.machine.MachineRecipeWrapper;
import mekanism.client.jei.machine.chemical.ChemicalCrystallizerRecipeCategory;
import mekanism.client.jei.machine.chemical.ChemicalCrystallizerRecipeWrapper;
import mekanism.client.jei.machine.chemical.ChemicalDissolutionChamberRecipeCategory;
@@ -250,34 +246,34 @@ public class MekanismJEI implements IModPlugin {
registry.getJeiHelpers().getIngredientBlacklist()
.addIngredientToBlacklist(new ItemStack(MekanismBlocks.BoundingBlock));
registry.handleRecipes(EnrichmentRecipe.class, EnrichmentRecipeWrapper::new, "mekanism.enrichment_chamber");
addRecipes(registry, Recipe.ENRICHMENT_CHAMBER, BasicMachineRecipe.class, EnrichmentRecipeWrapper.class,
registry.handleRecipes(EnrichmentRecipe.class, MachineRecipeWrapper::new, "mekanism.enrichment_chamber");
addRecipes(registry, Recipe.ENRICHMENT_CHAMBER, BasicMachineRecipe.class, MachineRecipeWrapper.class,
"mekanism.enrichment_chamber");
registry.handleRecipes(CrusherRecipe.class, CrusherRecipeWrapper::new, "mekanism.crusher");
addRecipes(registry, Recipe.CRUSHER, BasicMachineRecipe.class, CrusherRecipeWrapper.class, "mekanism.crusher");
registry.handleRecipes(CrusherRecipe.class, MachineRecipeWrapper::new, "mekanism.crusher");
addRecipes(registry, Recipe.CRUSHER, BasicMachineRecipe.class, MachineRecipeWrapper.class, "mekanism.crusher");
registry.handleRecipes(CombinerRecipe.class, CombinerRecipeWrapper::new, "mekanism.combiner");
addRecipes(registry, Recipe.COMBINER, DoubleMachineRecipe.class, CombinerRecipeWrapper.class,
registry.handleRecipes(CombinerRecipe.class, DoubleMachineRecipeWrapper::new, "mekanism.combiner");
addRecipes(registry, Recipe.COMBINER, DoubleMachineRecipe.class, DoubleMachineRecipeWrapper.class,
"mekanism.combiner");
registry.handleRecipes(PurificationRecipe.class, PurificationChamberRecipeWrapper::new,
registry.handleRecipes(PurificationRecipe.class, AdvancedMachineRecipeWrapper::new,
"mekanism.purification_chamber");
addRecipes(registry, Recipe.PURIFICATION_CHAMBER, AdvancedMachineRecipe.class,
PurificationChamberRecipeWrapper.class, "mekanism.purification_chamber");
AdvancedMachineRecipeWrapper.class, "mekanism.purification_chamber");
registry.handleRecipes(OsmiumCompressorRecipe.class, OsmiumCompressorRecipeWrapper::new,
registry.handleRecipes(OsmiumCompressorRecipe.class, AdvancedMachineRecipeWrapper::new,
"mekanism.osmium_compressor");
addRecipes(registry, Recipe.OSMIUM_COMPRESSOR, AdvancedMachineRecipe.class, OsmiumCompressorRecipeWrapper.class,
addRecipes(registry, Recipe.OSMIUM_COMPRESSOR, AdvancedMachineRecipe.class, AdvancedMachineRecipeWrapper.class,
"mekanism.osmium_compressor");
registry.handleRecipes(InjectionRecipe.class, ChemicalInjectionChamberRecipeWrapper::new,
registry.handleRecipes(InjectionRecipe.class, AdvancedMachineRecipeWrapper::new,
"mekanism.chemical_injection_chamber");
addRecipes(registry, Recipe.CHEMICAL_INJECTION_CHAMBER, AdvancedMachineRecipe.class,
ChemicalInjectionChamberRecipeWrapper.class, "mekanism.chemical_injection_chamber");
AdvancedMachineRecipeWrapper.class, "mekanism.chemical_injection_chamber");
registry.handleRecipes(SawmillRecipe.class, PrecisionSawmillRecipeWrapper::new, "mekanism.precision_sawmill");
addRecipes(registry, Recipe.PRECISION_SAWMILL, ChanceMachineRecipe.class, PrecisionSawmillRecipeWrapper.class,
registry.handleRecipes(SawmillRecipe.class, ChanceMachineRecipeWrapper::new, "mekanism.precision_sawmill");
addRecipes(registry, Recipe.PRECISION_SAWMILL, ChanceMachineRecipe.class, ChanceMachineRecipeWrapper.class,
"mekanism.precision_sawmill");
registry.handleRecipes(MetallurgicInfuserRecipe.class, MetallurgicInfuserRecipeWrapper::new,
@@ -339,12 +335,12 @@ public class MekanismJEI implements IModPlugin {
registry.addRecipes(condensentratorRecipes, "mekanism.rotary_condensentrator_condensentrating");
registry.addRecipes(decondensentratorRecipes, "mekanism.rotary_condensentrator_decondensentrating");
registry.handleRecipes(SmeltingRecipe.class, SmeltingRecipeWrapper::new, "mekanism.energized_smelter");
registry.handleRecipes(SmeltingRecipe.class, MachineRecipeWrapper::new, "mekanism.energized_smelter");
if (CRAFTTWEAKER_LOADED && EnergizedSmelter.hasRemovedRecipe()) // Removed / Removed + Added
{
// Add all recipes
addRecipes(registry, Recipe.ENERGIZED_SMELTER, BasicMachineRecipe.class, SmeltingRecipeWrapper.class,
addRecipes(registry, Recipe.ENERGIZED_SMELTER, BasicMachineRecipe.class, MachineRecipeWrapper.class,
"mekanism.energized_smelter");
} else if (CRAFTTWEAKER_LOADED && EnergizedSmelter.hasAddedRecipe()) // Added but not removed
{
@@ -355,7 +351,7 @@ public class MekanismJEI implements IModPlugin {
.contains(entry.getKey().ingredient))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)).values();
addRecipes(registry, recipes, BasicMachineRecipe.class, SmeltingRecipeWrapper.class,
addRecipes(registry, recipes, BasicMachineRecipe.class, MachineRecipeWrapper.class,
"mekanism.energized_smelter");
}
// else - Only use furnace list, so no extra registration.
@@ -6,11 +6,12 @@ import mekanism.api.gas.GasStack;
import mekanism.common.recipe.inputs.AdvancedMachineInput;
import mekanism.common.recipe.machines.AdvancedMachineRecipe;
import mekanism.common.recipe.outputs.ItemStackOutput;
import mekanism.common.util.GasUtils;
import mezz.jei.api.ingredients.IIngredients;
import mezz.jei.api.recipe.IRecipeWrapper;
import net.minecraft.item.ItemStack;
public abstract class AdvancedMachineRecipeWrapper implements IRecipeWrapper {
public class AdvancedMachineRecipeWrapper implements IRecipeWrapper {
private final AdvancedMachineRecipe recipe;
@@ -25,7 +26,9 @@ public abstract class AdvancedMachineRecipeWrapper implements IRecipeWrapper {
ingredients.setOutput(ItemStack.class, ((ItemStackOutput) recipe.getOutput()).output);
}
public abstract List<ItemStack> getFuelStacks(Gas gasType);
public List<ItemStack> getFuelStacks(Gas gasType) {
return GasUtils.getStacksForGas(gasType);
}
public AdvancedMachineRecipe getRecipe() {
return recipe;
@@ -8,7 +8,7 @@ import mezz.jei.api.ingredients.IIngredients;
import mezz.jei.api.recipe.IRecipeWrapper;
import net.minecraft.item.ItemStack;
public abstract class DoubleMachineRecipeWrapper implements IRecipeWrapper {
public class DoubleMachineRecipeWrapper implements IRecipeWrapper {
private final DoubleMachineRecipe recipe;
@@ -1,39 +0,0 @@
package mekanism.client.jei.machine.advanced;
import java.util.ArrayList;
import java.util.List;
import mekanism.api.gas.Gas;
import mekanism.client.jei.machine.AdvancedMachineRecipeWrapper;
import mekanism.common.MekanismFluids;
import mekanism.common.Tier.GasTankTier;
import mekanism.common.recipe.machines.AdvancedMachineRecipe;
import mekanism.common.util.ListUtils;
import mekanism.common.util.MekanismUtils;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
public class ChemicalInjectionChamberRecipeWrapper extends AdvancedMachineRecipeWrapper {
public ChemicalInjectionChamberRecipeWrapper(AdvancedMachineRecipe r) {
super(r);
}
@Override
public List<ItemStack> getFuelStacks(Gas gasType) {
if (gasType == MekanismFluids.SulfuricAcid) {
List<ItemStack> fuels = new ArrayList<>(OreDictionary.getOres("dustSulfur"));
fuels.add(MekanismUtils.getFullGasTank(GasTankTier.BASIC, MekanismFluids.SulfuricAcid));
return fuels;
} else if (gasType == MekanismFluids.Water) {
return ListUtils.asList(MekanismUtils.getFullGasTank(GasTankTier.BASIC, MekanismFluids.Water));
} else if (gasType == MekanismFluids.HydrogenChloride) {
List<ItemStack> fuels = new ArrayList<>(OreDictionary.getOres("dustSalt"));
fuels.add(MekanismUtils.getFullGasTank(GasTankTier.BASIC, MekanismFluids.HydrogenChloride));
return fuels;
}
return new ArrayList<>();
}
}
@@ -1,11 +0,0 @@
package mekanism.client.jei.machine.advanced;
import mekanism.client.jei.machine.DoubleMachineRecipeWrapper;
import mekanism.common.recipe.machines.DoubleMachineRecipe;
public class CombinerRecipeWrapper extends DoubleMachineRecipeWrapper {
public CombinerRecipeWrapper(DoubleMachineRecipe r) {
super(r);
}
}
@@ -1,21 +0,0 @@
package mekanism.client.jei.machine.advanced;
import java.util.List;
import mekanism.api.gas.Gas;
import mekanism.client.jei.machine.AdvancedMachineRecipeWrapper;
import mekanism.common.MekanismItems;
import mekanism.common.recipe.machines.AdvancedMachineRecipe;
import mekanism.common.util.ListUtils;
import net.minecraft.item.ItemStack;
public class OsmiumCompressorRecipeWrapper extends AdvancedMachineRecipeWrapper {
public OsmiumCompressorRecipeWrapper(AdvancedMachineRecipe r) {
super(r);
}
@Override
public List<ItemStack> getFuelStacks(Gas gasType) {
return ListUtils.asList(new ItemStack(MekanismItems.Ingot, 1, 1));
}
}
@@ -1,30 +0,0 @@
package mekanism.client.jei.machine.advanced;
import java.util.ArrayList;
import java.util.List;
import mekanism.api.gas.Gas;
import mekanism.client.jei.machine.AdvancedMachineRecipeWrapper;
import mekanism.common.MekanismFluids;
import mekanism.common.Tier.GasTankTier;
import mekanism.common.recipe.machines.AdvancedMachineRecipe;
import mekanism.common.util.ListUtils;
import mekanism.common.util.MekanismUtils;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
public class PurificationChamberRecipeWrapper extends AdvancedMachineRecipeWrapper {
public PurificationChamberRecipeWrapper(AdvancedMachineRecipe r) {
super(r);
}
@Override
public List<ItemStack> getFuelStacks(Gas gasType) {
if (gasType == MekanismFluids.Oxygen) {
return ListUtils.asList(new ItemStack(Items.FLINT),
MekanismUtils.getFullGasTank(GasTankTier.BASIC, MekanismFluids.Oxygen));
}
return new ArrayList<>();
}
}
@@ -1,8 +0,0 @@
@ParametersAreNonnullByDefault
@FieldsAreNonnullByDefault
@MethodsReturnNonnullByDefault
package mekanism.client.jei.machine.advanced;
import javax.annotation.ParametersAreNonnullByDefault;
import mcp.MethodsReturnNonnullByDefault;
import mekanism.common.util.FieldsAreNonnullByDefault;
@@ -1,11 +0,0 @@
package mekanism.client.jei.machine.basic;
import mekanism.client.jei.machine.MachineRecipeWrapper;
import mekanism.common.recipe.machines.BasicMachineRecipe;
public class CrusherRecipeWrapper extends MachineRecipeWrapper {
public CrusherRecipeWrapper(BasicMachineRecipe r) {
super(r);
}
}
@@ -1,11 +0,0 @@
package mekanism.client.jei.machine.basic;
import mekanism.client.jei.machine.MachineRecipeWrapper;
import mekanism.common.recipe.machines.BasicMachineRecipe;
public class EnrichmentRecipeWrapper extends MachineRecipeWrapper {
public EnrichmentRecipeWrapper(BasicMachineRecipe r) {
super(r);
}
}
@@ -1,11 +0,0 @@
package mekanism.client.jei.machine.basic;
import mekanism.client.jei.machine.MachineRecipeWrapper;
import mekanism.common.recipe.machines.BasicMachineRecipe;
public class SmeltingRecipeWrapper extends MachineRecipeWrapper {
public SmeltingRecipeWrapper(BasicMachineRecipe r) {
super(r);
}
}
@@ -1,8 +0,0 @@
@ParametersAreNonnullByDefault
@FieldsAreNonnullByDefault
@MethodsReturnNonnullByDefault
package mekanism.client.jei.machine.basic;
import javax.annotation.ParametersAreNonnullByDefault;
import mcp.MethodsReturnNonnullByDefault;
import mekanism.common.util.FieldsAreNonnullByDefault;
@@ -1,11 +0,0 @@
package mekanism.client.jei.machine.chance;
import mekanism.client.jei.machine.ChanceMachineRecipeWrapper;
import mekanism.common.recipe.machines.ChanceMachineRecipe;
public class PrecisionSawmillRecipeWrapper extends ChanceMachineRecipeWrapper {
public PrecisionSawmillRecipeWrapper(ChanceMachineRecipe r) {
super(r);
}
}
@@ -1,8 +0,0 @@
@ParametersAreNonnullByDefault
@FieldsAreNonnullByDefault
@MethodsReturnNonnullByDefault
package mekanism.client.jei.machine.chance;
import javax.annotation.ParametersAreNonnullByDefault;
import mcp.MethodsReturnNonnullByDefault;
import mekanism.common.util.FieldsAreNonnullByDefault;
@@ -685,6 +685,7 @@ public final class RecipeHandler {
}
public boolean containsRecipe(ItemStack input) {
//TODO: Support other input types
for (Object obj : get().entrySet()) {
if (obj instanceof Map.Entry) {
Map.Entry entry = (Map.Entry) obj;
@@ -713,6 +714,7 @@ public final class RecipeHandler {
}
public boolean containsRecipe(Fluid input) {
//TODO: Support other input types
for (Object obj : get().entrySet()) {
if (obj instanceof Map.Entry) {
Map.Entry entry = (Map.Entry) obj;
@@ -729,14 +731,19 @@ public final class RecipeHandler {
}
public boolean containsRecipe(Gas input) {
//TODO: Support other input types
for (Object obj : get().entrySet()) {
if (obj instanceof Map.Entry) {
Map.Entry entry = (Map.Entry) obj;
Gas toCheck = null;
if (entry.getKey() instanceof GasInput) {
if (((GasInput) entry.getKey()).ingredient.getGas() == input) {
return true;
}
toCheck = ((GasInput) entry.getKey()).ingredient.getGas();
} else if (entry.getKey() instanceof AdvancedMachineInput) {
toCheck = ((AdvancedMachineInput) entry.getKey()).gasType;
}
if (toCheck == input) {
return true;
}
}
}
@@ -9,7 +9,6 @@ import mekanism.api.gas.GasTankInfo;
import mekanism.api.gas.IGasHandler;
import mekanism.api.gas.IGasItem;
import mekanism.api.gas.ITubeConnection;
import mekanism.common.MekanismFluids;
import mekanism.common.Upgrade;
import mekanism.common.base.ISustainedData;
import mekanism.common.base.ITankManager;
@@ -18,6 +17,7 @@ import mekanism.common.block.states.BlockStateMachine;
import mekanism.common.capabilities.Capabilities;
import mekanism.common.config.MekanismConfig.usage;
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;
@@ -64,10 +64,20 @@ public class TileEntityChemicalDissolutionChamber extends TileEntityMachine impl
public void onUpdate() {
if (!world.isRemote) {
ChargeUtils.discharge(3, this);
ItemStack itemStack = inventory.get(0);
if (!inventory.get(0).isEmpty() && injectTank.getNeeded() > 0) {
injectTank.receive(
GasUtils.removeGas(inventory.get(0), MekanismFluids.SulfuricAcid, injectTank.getNeeded()), true);
if (!itemStack.isEmpty() && injectTank.getNeeded() > 0 && itemStack.getItem() instanceof IGasItem) {
//TODO: Maybe make this use GasUtils.getItemGas. This only currently accepts IGasItems here though
IGasItem item = (IGasItem) itemStack.getItem();
GasStack gasStack = item.getGas(itemStack);
//Check to make sure it can provide the gas it contains
if (gasStack != null && item.canProvideGas(itemStack, gasStack.getGas())) {
Gas gas = gasStack.getGas();
if (gas != null && injectTank.canReceive(gas) && Recipe.CHEMICAL_DISSOLUTION_CHAMBER
.containsRecipe(gas)) {
injectTank.receive(GasUtils.removeGas(itemStack, gas, injectTank.getNeeded()), true);
}
}
}
TileUtils.drawGas(inventory.get(2), outputTank);
@@ -241,7 +251,8 @@ public class TileEntityChemicalDissolutionChamber extends TileEntityMachine impl
@Override
public boolean canReceiveGas(EnumFacing side, Gas type) {
return side == MekanismUtils.getLeft(facing) && type == MekanismFluids.SulfuricAcid;
return side == MekanismUtils.getLeft(facing) && injectTank.canReceive(type)
&& Recipe.CHEMICAL_DISSOLUTION_CHAMBER.containsRecipe(type);
}
@Override
@@ -6,8 +6,6 @@ import mekanism.api.gas.Gas;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.IGasItem;
import mekanism.api.transmitters.TransmissionType;
import mekanism.common.MekanismBlocks;
import mekanism.common.MekanismFluids;
import mekanism.common.SideData;
import mekanism.common.block.states.BlockStateMachine;
import mekanism.common.config.MekanismConfig.usage;
@@ -17,9 +15,6 @@ import mekanism.common.recipe.machines.InjectionRecipe;
import mekanism.common.tile.prefab.TileEntityAdvancedElectricMachine;
import mekanism.common.util.GasUtils;
import mekanism.common.util.InventoryUtils;
import mekanism.common.util.MekanismUtils;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
public class TileEntityChemicalInjectionChamber extends TileEntityAdvancedElectricMachine<InjectionRecipe> {
@@ -41,23 +36,6 @@ public class TileEntityChemicalInjectionChamber extends TileEntityAdvancedElectr
return Recipe.CHEMICAL_INJECTION_CHAMBER.get();
}
@Override
public GasStack getItemGas(ItemStack itemstack) {
if (MekanismUtils.getOreDictName(itemstack).contains("dustSulfur")) {
return new GasStack(MekanismFluids.SulfuricAcid, 2);
}
if (MekanismUtils.getOreDictName(itemstack).contains("dustSalt")) {
return new GasStack(MekanismFluids.HydrogenChloride, 2);
}
if (Block.getBlockFromItem(itemstack.getItem()) == MekanismBlocks.GasTank
&& ((IGasItem) itemstack.getItem()).getGas(itemstack) != null &&
isValidGas(((IGasItem) itemstack.getItem()).getGas(itemstack).getGas())) {
return new GasStack(MekanismFluids.SulfuricAcid, 1);
}
return null;
}
@Override
public int receiveGas(EnumFacing side, GasStack stack, boolean doTransfer) {
if (canReceiveGas(side, stack.getGas())) {
@@ -69,11 +47,9 @@ public class TileEntityChemicalInjectionChamber extends TileEntityAdvancedElectr
@Override
public boolean canReceiveGas(EnumFacing side, Gas type) {
if (configComponent.getOutput(TransmissionType.GAS, side, facing).hasSlot(0)) {
return isValidGas(type);
}
return configComponent.getOutput(TransmissionType.GAS, side, facing).hasSlot(0) && gasTank.canReceive(type)
&& isValidGas(type);
return false;
}
@Override
@@ -99,8 +75,7 @@ public class TileEntityChemicalInjectionChamber extends TileEntityAdvancedElectr
@Override
public boolean isValidGas(Gas gas) {
return gas == MekanismFluids.SulfuricAcid || gas == MekanismFluids.Water
|| gas == MekanismFluids.HydrogenChloride;
return Recipe.CHEMICAL_INJECTION_CHAMBER.containsRecipe(gas);
}
@Override
@@ -3,15 +3,13 @@ package mekanism.common.tile;
import java.util.Map;
import mekanism.api.gas.Gas;
import mekanism.api.gas.GasStack;
import mekanism.common.MekanismFluids;
import mekanism.common.block.states.BlockStateMachine;
import mekanism.common.config.MekanismConfig.usage;
import mekanism.common.recipe.RecipeHandler.Recipe;
import mekanism.common.recipe.inputs.AdvancedMachineInput;
import mekanism.common.recipe.machines.OsmiumCompressorRecipe;
import mekanism.common.tile.prefab.TileEntityAdvancedElectricMachine;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import net.minecraft.util.EnumFacing;
public class TileEntityOsmiumCompressor extends TileEntityAdvancedElectricMachine<OsmiumCompressorRecipe> {
@@ -26,26 +24,25 @@ public class TileEntityOsmiumCompressor extends TileEntityAdvancedElectricMachin
}
@Override
public GasStack getItemGas(ItemStack itemstack) {
int amount = 0;
for (ItemStack ore : OreDictionary.getOres("ingotOsmium")) {
if (ore.isItemEqual(itemstack)) {
return new GasStack(MekanismFluids.LiquidOsmium, 200);
}
}
for (ItemStack ore : OreDictionary.getOres("blockOsmium")) {
if (ore.isItemEqual(itemstack)) {
return new GasStack(MekanismFluids.LiquidOsmium, 1800);
}
}
return null;
public boolean isValidGas(Gas gas) {
return Recipe.OSMIUM_COMPRESSOR.containsRecipe(gas);
}
@Override
public boolean isValidGas(Gas gas) {
return false;
public int receiveGas(EnumFacing side, GasStack stack, boolean doTransfer) {
if (canReceiveGas(side, stack.getGas())) {
return gasTank.receive(stack, doTransfer);
}
return 0;
}
@Override
public boolean canReceiveGas(EnumFacing side, Gas type) {
return gasTank.canReceive(type) && isValidGas(type);
}
@Override
public boolean canTubeConnect(EnumFacing side) {
return true;
}
}
@@ -4,8 +4,6 @@ import java.util.Map;
import mekanism.api.gas.Gas;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.IGasItem;
import mekanism.common.MekanismBlocks;
import mekanism.common.MekanismFluids;
import mekanism.common.block.states.BlockStateMachine;
import mekanism.common.config.MekanismConfig.usage;
import mekanism.common.recipe.RecipeHandler.Recipe;
@@ -13,8 +11,6 @@ import mekanism.common.recipe.inputs.AdvancedMachineInput;
import mekanism.common.recipe.machines.PurificationRecipe;
import mekanism.common.tile.prefab.TileEntityAdvancedElectricMachine;
import mekanism.common.util.GasUtils;
import net.minecraft.block.Block;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
@@ -30,40 +26,29 @@ public class TileEntityPurificationChamber extends TileEntityAdvancedElectricMac
return Recipe.PURIFICATION_CHAMBER.get();
}
@Override
public GasStack getItemGas(ItemStack itemstack) {
if (itemstack.isItemEqual(new ItemStack(Items.FLINT))) {
return new GasStack(MekanismFluids.Oxygen, 10);
}
if (Block.getBlockFromItem(itemstack.getItem()) == MekanismBlocks.GasTank
&& ((IGasItem) itemstack.getItem()).getGas(itemstack) != null &&
((IGasItem) itemstack.getItem()).getGas(itemstack).getGas() == MekanismFluids.Oxygen) {
return new GasStack(MekanismFluids.Oxygen, 1);
}
return null;
}
@Override
public int receiveGas(EnumFacing side, GasStack stack, boolean doTransfer) {
if (stack.getGas() == MekanismFluids.Oxygen) {
if (canReceiveGas(side, stack.getGas())) {
return gasTank.receive(stack, doTransfer);
}
return 0;
}
@Override
public boolean canReceiveGas(EnumFacing side, Gas type) {
return type == MekanismFluids.Oxygen;
return gasTank.canReceive(type) && isValidGas(type);
}
@Override
public void handleSecondaryFuel() {
if (!inventory.get(1).isEmpty() && gasTank.getNeeded() > 0 && inventory.get(1).getItem() instanceof IGasItem) {
GasStack removed = GasUtils.removeGas(inventory.get(1), MekanismFluids.Oxygen, gasTank.getNeeded());
gasTank.receive(removed, true);
return;
ItemStack itemStack = inventory.get(1);
if (!itemStack.isEmpty() && gasTank.getNeeded() > 0 && itemStack.getItem() instanceof IGasItem) {
GasStack gas = ((IGasItem) itemStack.getItem()).getGas(itemStack);
if (gas != null) {
GasStack removed = GasUtils.removeGas(itemStack, gas.getGas(), gasTank.getNeeded());
gasTank.receive(removed, true);
return;
}
}
super.handleSecondaryFuel();
@@ -76,7 +61,7 @@ public class TileEntityPurificationChamber extends TileEntityAdvancedElectricMac
@Override
public boolean isValidGas(Gas gas) {
return gas == MekanismFluids.Oxygen;
return Recipe.PURIFICATION_CHAMBER.containsRecipe(gas);
}
@Override
@@ -117,7 +117,16 @@ public abstract class TileEntityAdvancedElectricMachine<RECIPE extends AdvancedM
* @param itemstack - itemstack to check with
* @return fuel ticks
*/
public abstract GasStack getItemGas(ItemStack itemstack);
public GasStack getItemGas(ItemStack itemstack) {
return GasUtils.getItemGas(itemstack, this::getIfValid);
}
private GasStack getIfValid(Gas gas, int quantity) {
if (gas != null && gasTank.canReceive(gas) && isValidGas(gas)) {
return new GasStack(gas, quantity);
}
return null;
}
public abstract boolean isValidGas(Gas gas);
@@ -288,8 +297,9 @@ public abstract class TileEntityAdvancedElectricMachine<RECIPE extends AdvancedM
public boolean canExtractItem(int slotID, @Nonnull ItemStack itemstack, @Nonnull EnumFacing side) {
if (slotID == 3) {
return ChargeUtils.canBeOutputted(itemstack, false);
} else
} else {
return slotID == 2;
}
}
@@ -5,19 +5,24 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.function.BiFunction;
import mekanism.api.gas.Gas;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasTank;
import mekanism.api.gas.IGasHandler;
import mekanism.api.gas.IGasItem;
import mekanism.api.gas.ITubeConnection;
import mekanism.common.MekanismFluids;
import mekanism.common.Tier.GasTankTier;
import mekanism.common.capabilities.Capabilities;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;
/**
* A handy class containing several utilities for efficient gas transfer.
@@ -177,4 +182,83 @@ public final class GasUtils {
gasTank.stored = null;
}
}
/**
* Gets the amount of ticks the declared itemstack can fuel this machine.
*
* @param itemStack - itemstack to check with
* @return fuel ticks
*/
public static GasStack getItemGas(ItemStack itemStack, BiFunction<Gas, Integer, GasStack> getIfValid) {
//TODO: Allow them to register other items that get converted to gas
GasStack gasStack = null;
if (itemStack.isItemEqual(new ItemStack(Items.FLINT))) {
gasStack = getIfValid.apply(MekanismFluids.Oxygen, 10);
if (gasStack != null) {
return gasStack;
}
}
List<String> oreDictNames = MekanismUtils.getOreDictName(itemStack);
if (oreDictNames.contains("dustSulfur")) {
gasStack = getIfValid.apply(MekanismFluids.SulfuricAcid, 2);
if (gasStack != null) {
return gasStack;
}
}
if (oreDictNames.contains("dustSalt")) {
gasStack = getIfValid.apply(MekanismFluids.HydrogenChloride, 2);
if (gasStack != null) {
return gasStack;
}
}
if (oreDictNames.contains("ingotOsmium")) {
gasStack = getIfValid.apply(MekanismFluids.LiquidOsmium, 200);
if (gasStack != null) {
return gasStack;
}
}
OreDictionary.getOres("blockOsmium");
if (oreDictNames.contains("blockOsmium")) {
gasStack = getIfValid.apply(MekanismFluids.LiquidOsmium, 1800);
if (gasStack != null) {
return gasStack;
}
}
if (itemStack.getItem() instanceof IGasItem) {
IGasItem item = (IGasItem) itemStack.getItem();
GasStack gas = item.getGas(itemStack);
//Check to make sure it can provide the gas it contains
if (gas != null && item.canProvideGas(itemStack, gas.getGas())) {
gasStack = getIfValid.apply(gas.getGas(), 1);
if (gasStack != null) {
return gasStack;
}
}
}
return gasStack;
}
//TODO: Have item to gas and gas to items be registered in a lookup registry
public static List<ItemStack> getStacksForGas(Gas type) {
if (type == null) {
return Collections.emptyList();
}
List<ItemStack> stacks = new ArrayList<>();
if (type == MekanismFluids.SulfuricAcid) {
stacks.addAll(OreDictionary.getOres("dustSulfur"));
}
if (type == MekanismFluids.HydrogenChloride) {
stacks.addAll(OreDictionary.getOres("dustSalt"));
}
if (type == MekanismFluids.LiquidOsmium) {
stacks.addAll(OreDictionary.getOres("ingotOsmium"));
stacks.addAll(OreDictionary.getOres("blockOsmium"));
}
if (type == MekanismFluids.Oxygen) {
stacks.add(new ItemStack(Items.FLINT));
}
stacks.add(MekanismUtils.getFullGasTank(GasTankTier.BASIC, type));
return stacks;
}
}