Skip to content

Commit a0fb61c

Browse files
committed
fix mm gasstack can't be transferred from jei
1 parent be9a9a8 commit a0fb61c

File tree

5 files changed

+98
-3
lines changed

5 files changed

+98
-3
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.glodblock.github.integration.jei;
2+
3+
import com.glodblock.github.integration.jei.interfaces.IngredientExtractor;
4+
import mekanism.api.gas.GasStack;
5+
import mezz.jei.api.gui.IRecipeLayout;
6+
7+
import javax.annotation.Nullable;
8+
import java.util.stream.Stream;
9+
10+
public class ExtraGasExtractors {
11+
12+
@Nullable
13+
private final IngredientExtractor<GasStack> extModMach;
14+
15+
public ExtraGasExtractors(@Nullable IngredientExtractor<GasStack> extModMach) {
16+
this.extModMach = extModMach;
17+
}
18+
19+
public Stream<WrappedIngredient<GasStack>> extractGases(IRecipeLayout recipeLayout) {
20+
return extModMach != null ? extModMach.extract(recipeLayout) : Stream.empty();
21+
}
22+
23+
}

src/main/java/com/glodblock/github/integration/jei/FCJeiPlugin.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public void registerCategories(@Nonnull IRecipeCategoryRegistration registry) {
4040
public void register(@Nonnull IModRegistry registry) {
4141
IngredientExtractor<FluidStack> extModMach = Loader.isModLoaded("modularmachinery")
4242
? new ModMachHybridFluidStackExtractor(registry) : null;
43+
if (ModAndClassUtil.GAS && extModMach != null) {
44+
RecipeTransferBuilder.setGasExtractor(new ExtraGasExtractors(new ModMachHybridGasStackExtractor(registry)));
45+
}
4346
RecipeTransferBuilder.setExtractor(new ExtraExtractors(extModMach));
4447
registry.getRecipeTransferRegistry().addRecipeTransferHandler(
4548
new FluidPatternEncoderRecipeTransferHandler(), Constants.UNIVERSAL_RECIPE_TRANSFER_UID);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.glodblock.github.integration.jei;
2+
3+
import com.glodblock.github.integration.jei.interfaces.IngredientExtractor;
4+
import hellfirepvp.modularmachinery.common.integration.ingredient.HybridFluidGas;
5+
import mekanism.api.gas.GasStack;
6+
import mezz.jei.api.IModRegistry;
7+
import mezz.jei.api.gui.IRecipeLayout;
8+
import mezz.jei.api.recipe.IIngredientType;
9+
10+
import java.util.Objects;
11+
import java.util.stream.Stream;
12+
13+
public class ModMachHybridGasStackExtractor implements IngredientExtractor<GasStack> {
14+
15+
private final IIngredientType<HybridFluidGas> ingTypeHybridFluid;
16+
17+
ModMachHybridGasStackExtractor(IModRegistry registry) {
18+
ingTypeHybridFluid = Objects.requireNonNull(registry.getIngredientRegistry().getIngredientType(HybridFluidGas.class));
19+
}
20+
21+
public Stream<WrappedIngredient<GasStack>> extract(IRecipeLayout recipeLayout) {
22+
return recipeLayout.getIngredientsGroup(ingTypeHybridFluid).getGuiIngredients().values().stream()
23+
.map(ing -> {
24+
HybridFluidGas hf = ing.getDisplayedIngredient();
25+
return new WrappedIngredient<>(hf != null ? hf.asGasStack() : null, ing.isInput());
26+
});
27+
}
28+
29+
}

src/main/java/com/glodblock/github/integration/jei/RecipeTransferBuilder.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.glodblock.github.integration.jei;
22

3-
import com.glodblock.github.common.item.ItemFluidPacket;
43
import com.glodblock.github.common.item.fake.FakeFluids;
54
import com.glodblock.github.integration.gregtech.GregUtil;
65
import com.glodblock.github.integration.mek.FakeGases;
@@ -26,6 +25,7 @@
2625
public class RecipeTransferBuilder {
2726

2827
private static ExtraExtractors extractor = null;
28+
private static ExtraGasExtractors extractorGas = null;
2929
private static final int MAX_ITEMS = 16;
3030
private static Field fRecipeLayout_recipeWrapper;
3131

@@ -66,10 +66,18 @@ public static void setExtractor(ExtraExtractors extractor) {
6666
RecipeTransferBuilder.extractor = extractor;
6767
}
6868

69+
public static void setGasExtractor(ExtraGasExtractors extractor) {
70+
RecipeTransferBuilder.extractorGas = extractor;
71+
}
72+
6973
public static ExtraExtractors getExtractor() {
7074
return extractor;
7175
}
7276

77+
public static ExtraGasExtractors getGasExtractor() {
78+
return extractorGas;
79+
}
80+
7381
private void split() {
7482
for (int index : this.recipe.getItemStacks().getGuiIngredients().keySet()) {
7583
IGuiIngredient<ItemStack> ing = this.recipe.getItemStacks().getGuiIngredients().get(index);
@@ -121,6 +129,17 @@ private void split() {
121129
}
122130
);
123131
}
132+
if (extractorGas != null) {
133+
extractorGas.extractGases(this.recipe).forEach(
134+
ing -> {
135+
if (ing.isInput()) {
136+
this.gasIn.add(ing.getIngredient());
137+
} else {
138+
this.gasOut.add(ing.getIngredient());
139+
}
140+
}
141+
);
142+
}
124143
}
125144

126145
private void setItemIn(int offset) {

src/main/java/com/glodblock/github/integration/pauto/RecipeTypeFluidProcessing.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
package com.glodblock.github.integration.pauto;
22

33
import com.glodblock.github.FluidCraft;
4-
import com.glodblock.github.common.item.ItemFluidPacket;
54
import com.glodblock.github.common.item.fake.FakeFluids;
65
import com.glodblock.github.integration.jei.RecipeTransferBuilder;
76
import com.glodblock.github.integration.jei.WrappedIngredient;
7+
import com.glodblock.github.integration.mek.FakeGases;
88
import com.glodblock.github.loader.FCBlocks;
9-
import it.unimi.dsi.fastutil.ints.*;
9+
import com.glodblock.github.util.ModAndClassUtil;
10+
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
11+
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
12+
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
13+
import it.unimi.dsi.fastutil.ints.IntSet;
14+
import it.unimi.dsi.fastutil.ints.IntSets;
15+
import mekanism.api.gas.GasStack;
1016
import mezz.jei.api.gui.IGuiIngredient;
1117
import mezz.jei.api.gui.IRecipeLayout;
1218
import net.minecraft.item.ItemStack;
@@ -145,6 +151,21 @@ public Int2ObjectMap<ItemStack> getRecipeTransferMap(IRecipeLayout recipeLayout,
145151
}
146152
}
147153
}
154+
if (ModAndClassUtil.GAS) {
155+
Iterator<WrappedIngredient<GasStack>> iterGas = RecipeTransferBuilder.getGasExtractor().extractGases(recipeLayout).iterator();
156+
while (iterGas.hasNext()) {
157+
WrappedIngredient<GasStack> ing = iterGas.next();
158+
if (ing.isInput()) {
159+
if (ndxCrafting < NUM_SLOTS_CRAFT) {
160+
tfrs.put(ndxCrafting++, FakeGases.packGas2Packet(ing.getIngredient()));
161+
}
162+
} else {
163+
if (ndxOutput < NUM_SLOTS_OUT) {
164+
tfrs.put(NUM_SLOTS_CRAFT + ndxOutput++, FakeGases.packGas2Packet(ing.getIngredient()));
165+
}
166+
}
167+
}
168+
}
148169
return tfrs;
149170
}
150171

0 commit comments

Comments
 (0)