diff --git a/src/main/java/com/glodblock/github/integration/jei/ExtraGasExtractors.java b/src/main/java/com/glodblock/github/integration/jei/ExtraGasExtractors.java new file mode 100644 index 000000000..cfac4799c --- /dev/null +++ b/src/main/java/com/glodblock/github/integration/jei/ExtraGasExtractors.java @@ -0,0 +1,23 @@ +package com.glodblock.github.integration.jei; + +import com.glodblock.github.integration.jei.interfaces.IngredientExtractor; +import mekanism.api.gas.GasStack; +import mezz.jei.api.gui.IRecipeLayout; + +import javax.annotation.Nullable; +import java.util.stream.Stream; + +public class ExtraGasExtractors { + + @Nullable + private final IngredientExtractor extModMach; + + public ExtraGasExtractors(@Nullable IngredientExtractor extModMach) { + this.extModMach = extModMach; + } + + public Stream> extractGases(IRecipeLayout recipeLayout) { + return extModMach != null ? extModMach.extract(recipeLayout) : Stream.empty(); + } + +} diff --git a/src/main/java/com/glodblock/github/integration/jei/FCJeiPlugin.java b/src/main/java/com/glodblock/github/integration/jei/FCJeiPlugin.java index 7029d512e..a1e19adb6 100644 --- a/src/main/java/com/glodblock/github/integration/jei/FCJeiPlugin.java +++ b/src/main/java/com/glodblock/github/integration/jei/FCJeiPlugin.java @@ -40,6 +40,9 @@ public void registerCategories(@Nonnull IRecipeCategoryRegistration registry) { public void register(@Nonnull IModRegistry registry) { IngredientExtractor extModMach = Loader.isModLoaded("modularmachinery") ? new ModMachHybridFluidStackExtractor(registry) : null; + if (ModAndClassUtil.GAS && extModMach != null) { + RecipeTransferBuilder.setGasExtractor(new ExtraGasExtractors(new ModMachHybridGasStackExtractor(registry))); + } RecipeTransferBuilder.setExtractor(new ExtraExtractors(extModMach)); registry.getRecipeTransferRegistry().addRecipeTransferHandler( new FluidPatternEncoderRecipeTransferHandler(), Constants.UNIVERSAL_RECIPE_TRANSFER_UID); diff --git a/src/main/java/com/glodblock/github/integration/jei/ModMachHybridGasStackExtractor.java b/src/main/java/com/glodblock/github/integration/jei/ModMachHybridGasStackExtractor.java new file mode 100644 index 000000000..b7eb000c0 --- /dev/null +++ b/src/main/java/com/glodblock/github/integration/jei/ModMachHybridGasStackExtractor.java @@ -0,0 +1,29 @@ +package com.glodblock.github.integration.jei; + +import com.glodblock.github.integration.jei.interfaces.IngredientExtractor; +import hellfirepvp.modularmachinery.common.integration.ingredient.HybridFluidGas; +import mekanism.api.gas.GasStack; +import mezz.jei.api.IModRegistry; +import mezz.jei.api.gui.IRecipeLayout; +import mezz.jei.api.recipe.IIngredientType; + +import java.util.Objects; +import java.util.stream.Stream; + +public class ModMachHybridGasStackExtractor implements IngredientExtractor { + + private final IIngredientType ingTypeHybridFluid; + + ModMachHybridGasStackExtractor(IModRegistry registry) { + ingTypeHybridFluid = Objects.requireNonNull(registry.getIngredientRegistry().getIngredientType(HybridFluidGas.class)); + } + + public Stream> extract(IRecipeLayout recipeLayout) { + return recipeLayout.getIngredientsGroup(ingTypeHybridFluid).getGuiIngredients().values().stream() + .map(ing -> { + HybridFluidGas hf = ing.getDisplayedIngredient(); + return new WrappedIngredient<>(hf != null ? hf.asGasStack() : null, ing.isInput()); + }); + } + +} diff --git a/src/main/java/com/glodblock/github/integration/jei/RecipeTransferBuilder.java b/src/main/java/com/glodblock/github/integration/jei/RecipeTransferBuilder.java index 3491b23af..b30087c80 100644 --- a/src/main/java/com/glodblock/github/integration/jei/RecipeTransferBuilder.java +++ b/src/main/java/com/glodblock/github/integration/jei/RecipeTransferBuilder.java @@ -1,6 +1,5 @@ package com.glodblock.github.integration.jei; -import com.glodblock.github.common.item.ItemFluidPacket; import com.glodblock.github.common.item.fake.FakeFluids; import com.glodblock.github.integration.gregtech.GregUtil; import com.glodblock.github.integration.mek.FakeGases; @@ -26,6 +25,7 @@ public class RecipeTransferBuilder { private static ExtraExtractors extractor = null; + private static ExtraGasExtractors extractorGas = null; private static final int MAX_ITEMS = 16; private static Field fRecipeLayout_recipeWrapper; @@ -66,10 +66,18 @@ public static void setExtractor(ExtraExtractors extractor) { RecipeTransferBuilder.extractor = extractor; } + public static void setGasExtractor(ExtraGasExtractors extractor) { + RecipeTransferBuilder.extractorGas = extractor; + } + public static ExtraExtractors getExtractor() { return extractor; } + public static ExtraGasExtractors getGasExtractor() { + return extractorGas; + } + private void split() { for (int index : this.recipe.getItemStacks().getGuiIngredients().keySet()) { IGuiIngredient ing = this.recipe.getItemStacks().getGuiIngredients().get(index); @@ -121,6 +129,17 @@ private void split() { } ); } + if (extractorGas != null) { + extractorGas.extractGases(this.recipe).forEach( + ing -> { + if (ing.isInput()) { + this.gasIn.add(ing.getIngredient()); + } else { + this.gasOut.add(ing.getIngredient()); + } + } + ); + } } private void setItemIn(int offset) { diff --git a/src/main/java/com/glodblock/github/integration/pauto/RecipeTypeFluidProcessing.java b/src/main/java/com/glodblock/github/integration/pauto/RecipeTypeFluidProcessing.java index 0521eba19..7d69fa211 100644 --- a/src/main/java/com/glodblock/github/integration/pauto/RecipeTypeFluidProcessing.java +++ b/src/main/java/com/glodblock/github/integration/pauto/RecipeTypeFluidProcessing.java @@ -1,12 +1,18 @@ package com.glodblock.github.integration.pauto; import com.glodblock.github.FluidCraft; -import com.glodblock.github.common.item.ItemFluidPacket; import com.glodblock.github.common.item.fake.FakeFluids; import com.glodblock.github.integration.jei.RecipeTransferBuilder; import com.glodblock.github.integration.jei.WrappedIngredient; +import com.glodblock.github.integration.mek.FakeGases; import com.glodblock.github.loader.FCBlocks; -import it.unimi.dsi.fastutil.ints.*; +import com.glodblock.github.util.ModAndClassUtil; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import it.unimi.dsi.fastutil.ints.IntOpenHashSet; +import it.unimi.dsi.fastutil.ints.IntSet; +import it.unimi.dsi.fastutil.ints.IntSets; +import mekanism.api.gas.GasStack; import mezz.jei.api.gui.IGuiIngredient; import mezz.jei.api.gui.IRecipeLayout; import net.minecraft.item.ItemStack; @@ -145,6 +151,21 @@ public Int2ObjectMap getRecipeTransferMap(IRecipeLayout recipeLayout, } } } + if (ModAndClassUtil.GAS) { + Iterator> iterGas = RecipeTransferBuilder.getGasExtractor().extractGases(recipeLayout).iterator(); + while (iterGas.hasNext()) { + WrappedIngredient ing = iterGas.next(); + if (ing.isInput()) { + if (ndxCrafting < NUM_SLOTS_CRAFT) { + tfrs.put(ndxCrafting++, FakeGases.packGas2Packet(ing.getIngredient())); + } + } else { + if (ndxOutput < NUM_SLOTS_OUT) { + tfrs.put(NUM_SLOTS_CRAFT + ndxOutput++, FakeGases.packGas2Packet(ing.getIngredient())); + } + } + } + } return tfrs; }