Skip to content

Commit

Permalink
fix mm gasstack can't be transferred from jei
Browse files Browse the repository at this point in the history
  • Loading branch information
GlodBlock committed Jul 5, 2024
1 parent be9a9a8 commit a0fb61c
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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<GasStack> extModMach;

public ExtraGasExtractors(@Nullable IngredientExtractor<GasStack> extModMach) {
this.extModMach = extModMach;
}

public Stream<WrappedIngredient<GasStack>> extractGases(IRecipeLayout recipeLayout) {
return extModMach != null ? extModMach.extract(recipeLayout) : Stream.empty();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public void registerCategories(@Nonnull IRecipeCategoryRegistration registry) {
public void register(@Nonnull IModRegistry registry) {
IngredientExtractor<FluidStack> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<GasStack> {

private final IIngredientType<HybridFluidGas> ingTypeHybridFluid;

ModMachHybridGasStackExtractor(IModRegistry registry) {
ingTypeHybridFluid = Objects.requireNonNull(registry.getIngredientRegistry().getIngredientType(HybridFluidGas.class));
}

public Stream<WrappedIngredient<GasStack>> 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());
});
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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<ItemStack> ing = this.recipe.getItemStacks().getGuiIngredients().get(index);
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -145,6 +151,21 @@ public Int2ObjectMap<ItemStack> getRecipeTransferMap(IRecipeLayout recipeLayout,
}
}
}
if (ModAndClassUtil.GAS) {
Iterator<WrappedIngredient<GasStack>> iterGas = RecipeTransferBuilder.getGasExtractor().extractGases(recipeLayout).iterator();
while (iterGas.hasNext()) {
WrappedIngredient<GasStack> 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;
}

Expand Down

0 comments on commit a0fb61c

Please sign in to comment.