mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-26 14:52:58 +00:00
Add support for adding/removing item to gas conversions via crafttweaker
also run formatter to fix spacing/ensure import order is correct
This commit is contained in:
20 files changed
+398
-104
No files matched your search
@@ -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<ItemStack> getFuelStacks(Gas gasType) {
|
||||
return GasUtils.getStacksForGas(gasType);
|
||||
return GasConversionHandler.getStacksForGas(gasType);
|
||||
}
|
||||
|
||||
public AdvancedMachineRecipe getRecipe() {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -60,7 +60,7 @@ public class BlockStateBasic extends ExtendedBlockState {
|
||||
|
||||
public PropertyEnum<BasicBlockType> 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<TileEntity> tileClass, boolean hasDesc, Predicate<EnumFacing> 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<TileEntity> tileClass, boolean hasDesc, Predicate<EnumFacing> 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;
|
||||
|
||||
@@ -90,7 +90,7 @@ public class BlockStateMachine extends ExtendedBlockState {
|
||||
|
||||
public PropertyEnum<MachineType> 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;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import net.minecraft.util.EnumFacing;
|
||||
* Created by Thiakil on 18/04/2019.
|
||||
*/
|
||||
public class BlockStateUtils {
|
||||
|
||||
public static final Predicate<EnumFacing> ALL_FACINGS = enumFacing -> true;
|
||||
public static final Predicate<EnumFacing> NO_ROTATION = enumFacing -> false;
|
||||
}
|
||||
@@ -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.";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<ItemStack> 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());
|
||||
}
|
||||
|
||||
+2
-2
@@ -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<? extends MachineInput, ? extends MachineRecipe> recipe) {
|
||||
public static String getRecipeInfo(Entry<? extends MachineInput, ? extends MachineRecipe> recipe) {
|
||||
MachineOutput output = recipe.getValue().recipeOutput;
|
||||
if (output instanceof ItemStackOutput) {
|
||||
return getItemName(((ItemStackOutput) output).output);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<Gas, List<IMekanismIngredient<ItemStack>>> gasToIngredients = new HashMap<>();
|
||||
private final static Map<IMekanismIngredient<ItemStack>, 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<ItemStack> ingredient, @Nonnull GasStack gasStack) {
|
||||
Gas gas = gasStack.getGas();
|
||||
if (gas == null || gasStack.amount <= 0) {
|
||||
return false;
|
||||
}
|
||||
List<IMekanismIngredient<ItemStack>> 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<ItemStack> ingredient, @Nonnull GasStack gasStack) {
|
||||
Gas gas = gasStack.getGas();
|
||||
if (gas != null && gasStack.amount > 0 && gasToIngredients.containsKey(gas)) {
|
||||
List<IMekanismIngredient<ItemStack>> ingredients = gasToIngredients.get(gas);
|
||||
List<IMekanismIngredient<ItemStack>> toRemove = new ArrayList<>();
|
||||
for (IMekanismIngredient<ItemStack> 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<Gas, Integer, GasStack> 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<IMekanismIngredient<ItemStack>, 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<ItemStack> getStacksForGas(Gas type) {
|
||||
if (type == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<ItemStack> 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<IMekanismIngredient<ItemStack>> 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<ItemStack> ingredient : ingredients) {
|
||||
stacks.addAll(ingredient.getMatching());
|
||||
}
|
||||
return stacks;
|
||||
}
|
||||
}
|
||||
@@ -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<TYPE> {
|
||||
|
||||
@Nonnull
|
||||
List<TYPE> getMatching();
|
||||
|
||||
boolean contains(@Nonnull TYPE stack);
|
||||
}
|
||||
@@ -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<ItemStack> {
|
||||
|
||||
private final Ingredient ingredient;
|
||||
|
||||
public IngredientMekIngredientWrapper(@Nonnull Ingredient ingredient) {
|
||||
this.ingredient = ingredient;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<ItemStack> 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);
|
||||
}
|
||||
}
|
||||
@@ -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<ItemStack> {
|
||||
|
||||
private final ItemStack stack;
|
||||
private final List<ItemStack> matching;
|
||||
|
||||
public ItemStackMekIngredient(@Nonnull ItemStack stack) {
|
||||
this.stack = stack;
|
||||
matching = Collections.singletonList(this.stack);
|
||||
}
|
||||
|
||||
public ItemStack getStack() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<ItemStack> 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);
|
||||
}
|
||||
}
|
||||
@@ -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<ItemStack> {
|
||||
|
||||
private final String oreDict;
|
||||
|
||||
public OredictMekIngredient(@Nonnull String oreDict) {
|
||||
this.oreDict = oreDict;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<ItemStack> 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);
|
||||
}
|
||||
}
|
||||
@@ -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<RECIPE extends AdvancedM
|
||||
* @return fuel ticks
|
||||
*/
|
||||
public GasStack getItemGas(ItemStack itemstack) {
|
||||
return GasUtils.getItemGas(itemstack, this::getIfValid);
|
||||
return GasConversionHandler.getItemGas(itemstack, this::getIfValid);
|
||||
}
|
||||
|
||||
private GasStack getIfValid(Gas gas, int quantity) {
|
||||
|
||||
@@ -89,7 +89,7 @@ public final class CableUtils {
|
||||
}
|
||||
|
||||
IEnergyStorage forgeStorage;
|
||||
if (MekanismUtils.useForge() && (forgeStorage = CapabilityUtils.getCapability(tileEntity, CapabilityEnergy.ENERGY, opposite))!=null) {
|
||||
if (MekanismUtils.useForge() && (forgeStorage = CapabilityUtils.getCapability(tileEntity, CapabilityEnergy.ENERGY, opposite)) != null) {
|
||||
return forgeStorage.canExtract();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,30 +1,21 @@
|
||||
package mekanism.common.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
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.common.MekanismFluids;
|
||||
import mekanism.common.OreDictCache;
|
||||
import mekanism.common.base.target.GasHandlerTarget;
|
||||
import mekanism.common.capabilities.Capabilities;
|
||||
import mekanism.common.tier.GasTankTier;
|
||||
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.
|
||||
@@ -147,83 +138,4 @@ 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 = 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<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;
|
||||
}
|
||||
}
|
||||
@@ -58,7 +58,7 @@ public class BlockStateGenerator extends ExtendedBlockState {
|
||||
|
||||
public PropertyEnum<GeneratorType> 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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user