diff --git a/src/main/java/mekanism/client/jei/machine/AdvancedMachineRecipeWrapper.java b/src/main/java/mekanism/client/jei/machine/AdvancedMachineRecipeWrapper.java index f218c2432..067bc03a4 100644 --- a/src/main/java/mekanism/client/jei/machine/AdvancedMachineRecipeWrapper.java +++ b/src/main/java/mekanism/client/jei/machine/AdvancedMachineRecipeWrapper.java @@ -4,11 +4,11 @@ import java.util.List; import mekanism.api.gas.Gas; import mekanism.api.gas.GasStack; import mekanism.client.jei.MekanismJEI; +import mekanism.common.recipe.GasConversionHandler; import mekanism.common.recipe.inputs.AdvancedMachineInput; import mekanism.common.recipe.machines.AdvancedMachineRecipe; import mekanism.common.recipe.outputs.ItemStackOutput; import mekanism.common.tile.prefab.TileEntityAdvancedElectricMachine; -import mekanism.common.util.GasUtils; import mezz.jei.api.ingredients.IIngredients; import mezz.jei.api.ingredients.VanillaTypes; import mezz.jei.api.recipe.IRecipeWrapper; @@ -31,7 +31,7 @@ public class AdvancedMachineRecipeWrapper implements IRecipeWrapper { } public List getFuelStacks(Gas gasType) { - return GasUtils.getStacksForGas(gasType); + return GasConversionHandler.getStacksForGas(gasType); } public AdvancedMachineRecipe getRecipe() { diff --git a/src/main/java/mekanism/common/InfuseStorage.java b/src/main/java/mekanism/common/InfuseStorage.java index 723d4db5a..b11d47c97 100644 --- a/src/main/java/mekanism/common/InfuseStorage.java +++ b/src/main/java/mekanism/common/InfuseStorage.java @@ -24,6 +24,7 @@ public class InfuseStorage implements ISustainedData { /** * Replace this instance's properties with that from another + * * @param other the instance to copy from */ public void copyFrom(@Nonnull InfuseStorage other) { diff --git a/src/main/java/mekanism/common/Mekanism.java b/src/main/java/mekanism/common/Mekanism.java index acadd8c49..de35f3458 100644 --- a/src/main/java/mekanism/common/Mekanism.java +++ b/src/main/java/mekanism/common/Mekanism.java @@ -57,6 +57,7 @@ import mekanism.common.network.PacketSimpleGui; import mekanism.common.network.PacketTransmitterUpdate.PacketType; import mekanism.common.network.PacketTransmitterUpdate.TransmitterUpdateMessage; import mekanism.common.recipe.BinRecipe; +import mekanism.common.recipe.GasConversionHandler; import mekanism.common.recipe.RecipeHandler; import mekanism.common.recipe.RecipeHandler.Recipe; import mekanism.common.recipe.inputs.ItemStackInput; @@ -315,6 +316,7 @@ public class Mekanism { event.getRegistry().register(new BinRecipe()); addRecipes(); OreDictManager.init(); + GasConversionHandler.addDefaultGasMappings(); } /** diff --git a/src/main/java/mekanism/common/block/states/BlockStateBasic.java b/src/main/java/mekanism/common/block/states/BlockStateBasic.java index 8c2111bbf..742c30b7d 100644 --- a/src/main/java/mekanism/common/block/states/BlockStateBasic.java +++ b/src/main/java/mekanism/common/block/states/BlockStateBasic.java @@ -60,7 +60,7 @@ public class BlockStateBasic extends ExtendedBlockState { public PropertyEnum getProperty() { if (predicatedProperty == null) { - predicatedProperty = PropertyEnum.create("type", BasicBlockType.class, it->Objects.requireNonNull(it).blockType==this); + predicatedProperty = PropertyEnum.create("type", BasicBlockType.class, it -> Objects.requireNonNull(it).blockType == this); } return predicatedProperty; } @@ -125,11 +125,11 @@ public class BlockStateBasic extends ExtendedBlockState { BasicBlockType(@Nonnull BasicBlock block, int metadata, String s, Supplier tileClass, boolean hasDesc, Predicate facingAllowed, boolean activeState, boolean t, boolean beaconBase, boolean hasRedstoneOutput) { - this(block, metadata, s, tileClass, hasDesc, facingAllowed, activeState, t, beaconBase, hasRedstoneOutput, false); + this(block, metadata, s, tileClass, hasDesc, facingAllowed, activeState, t, beaconBase, hasRedstoneOutput, false); } - + BasicBlockType(@Nonnull BasicBlock block, int metadata, String s, Supplier tileClass, boolean hasDesc, Predicate facingAllowed, - boolean activeState, boolean t, boolean beaconBase, boolean hasRedstoneOutput, boolean fullBlock) { + boolean activeState, boolean t, boolean beaconBase, boolean hasRedstoneOutput, boolean fullBlock) { blockType = block; meta = metadata; name = s; diff --git a/src/main/java/mekanism/common/block/states/BlockStateMachine.java b/src/main/java/mekanism/common/block/states/BlockStateMachine.java index 49374cbe5..0e3aceadd 100644 --- a/src/main/java/mekanism/common/block/states/BlockStateMachine.java +++ b/src/main/java/mekanism/common/block/states/BlockStateMachine.java @@ -90,7 +90,7 @@ public class BlockStateMachine extends ExtendedBlockState { public PropertyEnum getProperty() { if (machineTypeProperty == null) { - machineTypeProperty = PropertyEnum.create("type", MachineType.class, input-> input != null && input.typeBlock == this && input.isValidMachine()); + machineTypeProperty = PropertyEnum.create("type", MachineType.class, input -> input != null && input.typeBlock == this && input.isValidMachine()); } return machineTypeProperty; } diff --git a/src/main/java/mekanism/common/block/states/BlockStateUtils.java b/src/main/java/mekanism/common/block/states/BlockStateUtils.java index 18ebd0336..3d58faaf8 100644 --- a/src/main/java/mekanism/common/block/states/BlockStateUtils.java +++ b/src/main/java/mekanism/common/block/states/BlockStateUtils.java @@ -7,6 +7,7 @@ import net.minecraft.util.EnumFacing; * Created by Thiakil on 18/04/2019. */ public class BlockStateUtils { + public static final Predicate ALL_FACINGS = enumFacing -> true; public static final Predicate NO_ROTATION = enumFacing -> false; } \ No newline at end of file diff --git a/src/main/java/mekanism/common/integration/crafttweaker/handlers/GasConversion.java b/src/main/java/mekanism/common/integration/crafttweaker/handlers/GasConversion.java new file mode 100644 index 000000000..0f6e0eed1 --- /dev/null +++ b/src/main/java/mekanism/common/integration/crafttweaker/handlers/GasConversion.java @@ -0,0 +1,101 @@ +package mekanism.common.integration.crafttweaker.handlers; + +import crafttweaker.CraftTweakerAPI; +import crafttweaker.IAction; +import crafttweaker.annotations.ZenRegister; +import crafttweaker.api.item.IIngredient; +import mekanism.common.Mekanism; +import mekanism.common.integration.crafttweaker.CrafttweakerIntegration; +import mekanism.common.integration.crafttweaker.gas.IGasStack; +import mekanism.common.integration.crafttweaker.helpers.GasHelper; +import mekanism.common.integration.crafttweaker.helpers.IngredientHelper; +import mekanism.common.recipe.GasConversionHandler; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +@ZenClass("mods.mekanism.GasConversion") +@ZenRegister +public class GasConversion { + + public static final String NAME = Mekanism.MOD_NAME + " Gas Conversion"; + + @ZenMethod + public static void register(IIngredient ingredient, IGasStack gas) { + if (IngredientHelper.checkNotNull(NAME, ingredient, gas)) { + CrafttweakerIntegration.LATE_ADDITIONS.add(new Add(ingredient, gas)); + } + } + + @ZenMethod + public static void unregister(IIngredient ingredient, IGasStack gas) { + if (IngredientHelper.checkNotNull(NAME, ingredient, gas)) { + CrafttweakerIntegration.LATE_REMOVALS.add(new Remove(ingredient, gas)); + } + } + + @ZenMethod + public static void unregisterAll() { + CrafttweakerIntegration.LATE_REMOVALS.add(new RemoveAll()); + } + + private static class Add implements IAction { + + private final IIngredient ingredient; + private final IGasStack gas; + + private Add(IIngredient ingredient, IGasStack gas) { + this.ingredient = ingredient; + this.gas = gas; + } + + @Override + public void apply() { + boolean noOverride = GasConversionHandler.addGasMapping(IngredientHelper.getMekanismIngredient(ingredient), GasHelper.toGas(gas)); + if (!noOverride) { + CraftTweakerAPI.logWarning(String.format("%s: %s overrides another conversion. It is recommended to manually call unregisterGasItem and then registerGasItem " + + "to override conversions as unexpected things may occur.", NAME, ingredient.toCommandString())); + } + } + + @Override + public String describe() { + return "Adding gas conversion between: " + ingredient.toCommandString() + " to " + gas.toCommandString(); + } + } + + private static class Remove implements IAction { + + private final IIngredient ingredient; + private final IGasStack gas; + + private Remove(IIngredient ingredient, IGasStack gas) { + this.ingredient = ingredient; + this.gas = gas; + } + + @Override + public void apply() { + int count = GasConversionHandler.removeGasMapping(IngredientHelper.getMekanismIngredient(ingredient), GasHelper.toGas(gas)); + CraftTweakerAPI.logInfo("Removing " + count + " gas conversion" + (count == 1 ? "" : "s") + " between: " + ingredient.toCommandString() + " and " + gas.toCommandString()); + } + + @Override + public String describe() { + //Returns null as we handle it manually when calling apply + return null; + } + } + + private static class RemoveAll implements IAction { + + @Override + public void apply() { + GasConversionHandler.removeAllGasMappings(); + } + + @Override + public String describe() { + return "Removing all gas conversions."; + } + } +} \ No newline at end of file diff --git a/src/main/java/mekanism/common/integration/crafttweaker/helpers/IngredientHelper.java b/src/main/java/mekanism/common/integration/crafttweaker/helpers/IngredientHelper.java index 1842fcb39..b7eff15b7 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/helpers/IngredientHelper.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/helpers/IngredientHelper.java @@ -6,11 +6,16 @@ import crafttweaker.api.item.IItemStack; import crafttweaker.api.item.IngredientAny; import crafttweaker.api.liquid.ILiquidStack; import crafttweaker.api.minecraft.CraftTweakerMC; +import crafttweaker.api.oredict.IOreDictEntry; import mekanism.api.gas.Gas; import mekanism.api.gas.GasStack; import mekanism.common.integration.crafttweaker.gas.CraftTweakerGasStack; import mekanism.common.integration.crafttweaker.gas.IGasStack; import mekanism.common.integration.crafttweaker.util.IngredientWrapper; +import mekanism.common.recipe.ingredients.IMekanismIngredient; +import mekanism.common.recipe.ingredients.IngredientMekIngredientWrapper; +import mekanism.common.recipe.ingredients.ItemStackMekIngredient; +import mekanism.common.recipe.ingredients.OredictMekIngredient; import mekanism.common.recipe.inputs.AdvancedMachineInput; import mekanism.common.recipe.inputs.ChemicalPairInput; import mekanism.common.recipe.inputs.DoubleMachineInput; @@ -139,6 +144,15 @@ public class IngredientHelper { return false; } + public static IMekanismIngredient getMekanismIngredient(IIngredient ingredient) { + if (ingredient instanceof IOreDictEntry) { + return new OredictMekIngredient(((IOreDictEntry) ingredient).getName()); + } else if (ingredient instanceof IItemStack) { + return new ItemStackMekIngredient(CraftTweakerMC.getItemStack(ingredient)); + } + return new IngredientMekIngredientWrapper(CraftTweakerMC.getIngredient(ingredient)); + } + public static FluidStack toFluid(ILiquidStack fluid) { return fluid == null ? null : FluidRegistry.getFluidStack(fluid.getName(), fluid.getAmount()); } diff --git a/src/main/java/mekanism/common/integration/crafttweaker/helpers/RecipeInfoHelper.java b/src/main/java/mekanism/common/integration/crafttweaker/helpers/RecipeInfoHelper.java index 29e7cf870..8d5ef863d 100644 --- a/src/main/java/mekanism/common/integration/crafttweaker/helpers/RecipeInfoHelper.java +++ b/src/main/java/mekanism/common/integration/crafttweaker/helpers/RecipeInfoHelper.java @@ -1,7 +1,7 @@ package mekanism.common.integration.crafttweaker.helpers; import crafttweaker.mc1120.item.MCItemStack; -import java.util.Map; +import java.util.Map.Entry; import mekanism.api.gas.Gas; import mekanism.api.gas.GasStack; import mekanism.common.recipe.inputs.MachineInput; @@ -22,7 +22,7 @@ public class RecipeInfoHelper { private RecipeInfoHelper() { } - public static String getRecipeInfo(Map.Entry recipe) { + public static String getRecipeInfo(Entry recipe) { MachineOutput output = recipe.getValue().recipeOutput; if (output instanceof ItemStackOutput) { return getItemName(((ItemStackOutput) output).output); diff --git a/src/main/java/mekanism/common/item/ItemAtomicDisassembler.java b/src/main/java/mekanism/common/item/ItemAtomicDisassembler.java index 4a0462ffc..a994da30c 100644 --- a/src/main/java/mekanism/common/item/ItemAtomicDisassembler.java +++ b/src/main/java/mekanism/common/item/ItemAtomicDisassembler.java @@ -192,8 +192,7 @@ public class ItemAtomicDisassembler extends ItemEnergized { break; } return EnumActionResult.SUCCESS; - } - else if (!player.isSneaking() && block == Blocks.GRASS) { + } else if (!player.isSneaking() && block == Blocks.GRASS) { if (useShovel(stack, player, world, pos, side) == EnumActionResult.FAIL) { return EnumActionResult.FAIL; } @@ -249,7 +248,7 @@ public class ItemAtomicDisassembler extends ItemEnergized { } return EnumActionResult.PASS; } - + private EnumActionResult useShovel(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing facing) { if (!playerIn.canPlayerEdit(pos.offset(facing), facing, stack)) { return EnumActionResult.FAIL; diff --git a/src/main/java/mekanism/common/network/PacketTileEntity.java b/src/main/java/mekanism/common/network/PacketTileEntity.java index 0ad4fb503..846c3f671 100644 --- a/src/main/java/mekanism/common/network/PacketTileEntity.java +++ b/src/main/java/mekanism/common/network/PacketTileEntity.java @@ -2,8 +2,8 @@ package mekanism.common.network; import io.netty.buffer.ByteBuf; import mekanism.api.Coord4D; -import mekanism.common.Mekanism; import mekanism.api.TileNetworkList; +import mekanism.common.Mekanism; import mekanism.common.PacketHandler; import mekanism.common.base.ITileNetwork; import mekanism.common.capabilities.Capabilities; diff --git a/src/main/java/mekanism/common/recipe/GasConversionHandler.java b/src/main/java/mekanism/common/recipe/GasConversionHandler.java new file mode 100644 index 000000000..637e87a3a --- /dev/null +++ b/src/main/java/mekanism/common/recipe/GasConversionHandler.java @@ -0,0 +1,133 @@ +package mekanism.common.recipe; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.function.BiFunction; +import javax.annotation.Nonnull; +import mekanism.api.gas.Gas; +import mekanism.api.gas.GasStack; +import mekanism.api.gas.IGasItem; +import mekanism.common.MekanismFluids; +import mekanism.common.recipe.ingredients.IMekanismIngredient; +import mekanism.common.recipe.ingredients.ItemStackMekIngredient; +import mekanism.common.recipe.ingredients.OredictMekIngredient; +import mekanism.common.tier.GasTankTier; +import mekanism.common.util.MekanismUtils; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; + +public class GasConversionHandler { + + //TODO: Show uses in JEI for fuels that can be turned to gas?? + private final static Map>> gasToIngredients = new HashMap<>(); + private final static Map, GasStack> ingredientToGas = new HashMap<>(); + + public static void addDefaultGasMappings() { + addGasMapping(new ItemStack(Items.FLINT), MekanismFluids.Oxygen, 10); + addGasMapping("dustSulfur", MekanismFluids.SulfuricAcid, 2); + addGasMapping("dustSalt", MekanismFluids.HydrogenChloride, 2); + addGasMapping("ingotOsmium", MekanismFluids.LiquidOsmium, 200); + addGasMapping("blockOsmium", MekanismFluids.LiquidOsmium, 1800); + } + + public static boolean addGasMapping(@Nonnull ItemStack stack, @Nonnull Gas gas, int amount) { + return addGasMapping(new ItemStackMekIngredient(stack), new GasStack(gas, amount)); + } + + public static boolean addGasMapping(@Nonnull String oreDict, @Nonnull Gas gas, int amount) { + return addGasMapping(new OredictMekIngredient(oreDict), new GasStack(gas, amount)); + } + + public static boolean addGasMapping(@Nonnull IMekanismIngredient ingredient, @Nonnull GasStack gasStack) { + Gas gas = gasStack.getGas(); + if (gas == null || gasStack.amount <= 0) { + return false; + } + List> ingredients = gasToIngredients.computeIfAbsent(gas, k -> new ArrayList<>()); + //TODO: Better checking at some point if the ingredient is already in there? Should partial checking happen as well + ingredients.add(ingredient); + return ingredientToGas.put(ingredient, gasStack) == null; + } + + public static int removeGasMapping(@Nonnull IMekanismIngredient ingredient, @Nonnull GasStack gasStack) { + Gas gas = gasStack.getGas(); + if (gas != null && gasStack.amount > 0 && gasToIngredients.containsKey(gas)) { + List> ingredients = gasToIngredients.get(gas); + List> toRemove = new ArrayList<>(); + for (IMekanismIngredient stored : ingredients) { + if (stored.equals(ingredient)) { + //TODO: Better comparision??? Doesn't really matter until we have better duplication handling + // or have proper handling for if something is registered as an ore dict and as an item + toRemove.add(stored); + ingredientToGas.remove(stored); + } + } + if (ingredients.size() == toRemove.size()) { + //If we are removing all for that gas type then remove the list as well + gasToIngredients.remove(gas); + } else { + ingredients.removeAll(toRemove); + } + return toRemove.size(); + } + return 0; + } + + public static void removeAllGasMappings() { + gasToIngredients.clear(); + ingredientToGas.clear(); + } + + /** + * 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 getIfValid) { + 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 gasStack = getIfValid.apply(gas.getGas(), 1); + if (gasStack != null) { + return gasStack; + } + } + } + for (Entry, GasStack> entry : ingredientToGas.entrySet()) { + if (entry.getKey().contains(itemStack)) { + GasStack gasStack = getIfValid.apply(entry.getValue().getGas(), entry.getValue().amount); + if (gasStack != null) { + return gasStack; + } + } + } + return null; + } + + public static List getStacksForGas(Gas type) { + if (type == null) { + return Collections.emptyList(); + } + List stacks = new ArrayList<>(); + //Always include the gas tank of the type + stacks.add(MekanismUtils.getFullGasTank(GasTankTier.BASIC, type)); + //See if there are any gas to item mappings + List> ingredients = gasToIngredients.get(type); + if (ingredients == null) { + return stacks; + } + //TODO: Maybe check for duplicates if things are in oredict and not? For the most part things assume there are no duplication at the moment + for (IMekanismIngredient ingredient : ingredients) { + stacks.addAll(ingredient.getMatching()); + } + return stacks; + } +} \ No newline at end of file diff --git a/src/main/java/mekanism/common/recipe/ingredients/IMekanismIngredient.java b/src/main/java/mekanism/common/recipe/ingredients/IMekanismIngredient.java new file mode 100644 index 000000000..5cfac1fc8 --- /dev/null +++ b/src/main/java/mekanism/common/recipe/ingredients/IMekanismIngredient.java @@ -0,0 +1,15 @@ +package mekanism.common.recipe.ingredients; + +import java.util.List; +import javax.annotation.Nonnull; + +//TODO: Maybe eventually get rid of this and use the built in Ingredient. +// The reason for this existing for now is to not have to implement all the +// things that Ingredient needs AND to not verify that they properly exist +public interface IMekanismIngredient { + + @Nonnull + List getMatching(); + + boolean contains(@Nonnull TYPE stack); +} \ No newline at end of file diff --git a/src/main/java/mekanism/common/recipe/ingredients/IngredientMekIngredientWrapper.java b/src/main/java/mekanism/common/recipe/ingredients/IngredientMekIngredientWrapper.java new file mode 100644 index 000000000..345eca473 --- /dev/null +++ b/src/main/java/mekanism/common/recipe/ingredients/IngredientMekIngredientWrapper.java @@ -0,0 +1,37 @@ +package mekanism.common.recipe.ingredients; + +import java.util.Arrays; +import java.util.List; +import javax.annotation.Nonnull; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.Ingredient; + +public class IngredientMekIngredientWrapper implements IMekanismIngredient { + + private final Ingredient ingredient; + + public IngredientMekIngredientWrapper(@Nonnull Ingredient ingredient) { + this.ingredient = ingredient; + } + + @Nonnull + @Override + public List getMatching() { + return Arrays.asList(ingredient.getMatchingStacks()); + } + + @Override + public boolean contains(@Nonnull ItemStack stack) { + return ingredient.apply(stack); + } + + @Override + public int hashCode() { + return ingredient.hashCode(); + } + + @Override + public boolean equals(Object obj) { + return obj instanceof IngredientMekIngredientWrapper && ingredient.equals(((IngredientMekIngredientWrapper) obj).ingredient); + } +} \ No newline at end of file diff --git a/src/main/java/mekanism/common/recipe/ingredients/ItemStackMekIngredient.java b/src/main/java/mekanism/common/recipe/ingredients/ItemStackMekIngredient.java new file mode 100644 index 000000000..775705076 --- /dev/null +++ b/src/main/java/mekanism/common/recipe/ingredients/ItemStackMekIngredient.java @@ -0,0 +1,42 @@ +package mekanism.common.recipe.ingredients; + +import java.util.Collections; +import java.util.List; +import javax.annotation.Nonnull; +import net.minecraft.item.ItemStack; + +public class ItemStackMekIngredient implements IMekanismIngredient { + + private final ItemStack stack; + private final List matching; + + public ItemStackMekIngredient(@Nonnull ItemStack stack) { + this.stack = stack; + matching = Collections.singletonList(this.stack); + } + + public ItemStack getStack() { + return stack; + } + + @Nonnull + @Override + public List getMatching() { + return matching; + } + + @Override + public boolean contains(@Nonnull ItemStack stack) { + return ItemStack.areItemStacksEqual(this.stack, stack); + } + + @Override + public int hashCode() { + return stack.hashCode(); + } + + @Override + public boolean equals(Object obj) { + return obj instanceof ItemStackMekIngredient && ItemStack.areItemStacksEqual(stack, ((ItemStackMekIngredient) obj).stack); + } +} \ No newline at end of file diff --git a/src/main/java/mekanism/common/recipe/ingredients/OredictMekIngredient.java b/src/main/java/mekanism/common/recipe/ingredients/OredictMekIngredient.java new file mode 100644 index 000000000..b45031b58 --- /dev/null +++ b/src/main/java/mekanism/common/recipe/ingredients/OredictMekIngredient.java @@ -0,0 +1,36 @@ +package mekanism.common.recipe.ingredients; + +import java.util.List; +import javax.annotation.Nonnull; +import mekanism.common.OreDictCache; +import net.minecraft.item.ItemStack; + +public class OredictMekIngredient implements IMekanismIngredient { + + private final String oreDict; + + public OredictMekIngredient(@Nonnull String oreDict) { + this.oreDict = oreDict; + } + + @Nonnull + @Override + public List getMatching() { + return OreDictCache.getOreDictStacks(oreDict, false); + } + + @Override + public boolean contains(@Nonnull ItemStack stack) { + return OreDictCache.getOreDictName(stack).contains(oreDict); + } + + @Override + public int hashCode() { + return oreDict.hashCode(); + } + + @Override + public boolean equals(Object obj) { + return obj instanceof OredictMekIngredient && oreDict.equals(((OredictMekIngredient) obj).oreDict); + } +} \ No newline at end of file diff --git a/src/main/java/mekanism/common/tile/prefab/TileEntityAdvancedElectricMachine.java b/src/main/java/mekanism/common/tile/prefab/TileEntityAdvancedElectricMachine.java index 52ca0c9db..d404f06d1 100644 --- a/src/main/java/mekanism/common/tile/prefab/TileEntityAdvancedElectricMachine.java +++ b/src/main/java/mekanism/common/tile/prefab/TileEntityAdvancedElectricMachine.java @@ -15,6 +15,7 @@ import mekanism.common.SideData; import mekanism.common.Upgrade; import mekanism.common.base.ISustainedData; import mekanism.common.capabilities.Capabilities; +import mekanism.common.recipe.GasConversionHandler; import mekanism.common.recipe.RecipeHandler; import mekanism.common.recipe.inputs.AdvancedMachineInput; import mekanism.common.recipe.machines.AdvancedMachineRecipe; @@ -114,7 +115,7 @@ public abstract class TileEntityAdvancedElectricMachine 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 oreDictNames = OreDictCache.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 getStacksForGas(Gas type) { - if (type == null) { - return Collections.emptyList(); - } - List 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; - } } \ No newline at end of file diff --git a/src/main/java/mekanism/generators/common/block/states/BlockStateGenerator.java b/src/main/java/mekanism/generators/common/block/states/BlockStateGenerator.java index 7ab33d875..9453d6a4f 100644 --- a/src/main/java/mekanism/generators/common/block/states/BlockStateGenerator.java +++ b/src/main/java/mekanism/generators/common/block/states/BlockStateGenerator.java @@ -58,7 +58,7 @@ public class BlockStateGenerator extends ExtendedBlockState { public PropertyEnum getProperty() { if (generatorTypeProperty == null) { - generatorTypeProperty = PropertyEnum.create("type", GeneratorType.class, input-> input != null && input.blockType == this); + generatorTypeProperty = PropertyEnum.create("type", GeneratorType.class, input -> input != null && input.blockType == this); } return generatorTypeProperty; }