-
Notifications
You must be signed in to change notification settings - Fork 5
Fix fluid encoder JEI support not working #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
cbbde37
try mixin approach
solidDoWant c63fdeb
remove d ebug code
solidDoWant 0debb22
Fix hasInputFluids check to prevent shaped recipe compression (#14)
Copilot ab8bbcb
rm dead code
solidDoWant 476d22f
rm old import, warning
solidDoWant 3dc75f4
address PR comments
solidDoWant d1d492f
Gate JEI mixin behind mod presence check to prevent crashes without J…
Copilot b548fc0
fix import
solidDoWant ff00260
Statically init GT_ENERGISTICS_HANDLER
solidDoWant File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
68 changes: 17 additions & 51 deletions
68
src/main/java/com/soliddowant/gregtechenergistics/integration/jei/JeiPlugin.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,63 +1,29 @@ | ||
| package com.soliddowant.gregtechenergistics.integration.jei; | ||
|
|
||
| import appeng.container.implementations.ContainerPatternTerm; | ||
| import com.google.common.collect.HashBasedTable; | ||
| import com.google.common.collect.ImmutableTable; | ||
| import com.soliddowant.gregtechenergistics.gui.ExtendedPatternContainer; | ||
| import mezz.jei.collect.Table; | ||
| import mezz.jei.api.IModPlugin; | ||
| import mezz.jei.api.IModRegistry; | ||
| import mezz.jei.api.JEIPlugin; | ||
| import mezz.jei.api.recipe.transfer.IRecipeTransferHandler; | ||
| import mezz.jei.api.recipe.transfer.IRecipeTransferRegistry; | ||
| import mezz.jei.config.Constants; | ||
| import mezz.jei.recipes.RecipeTransferRegistry; | ||
| import net.minecraftforge.fml.relauncher.ReflectionHelper; | ||
|
|
||
| @SuppressWarnings({"unused", "rawtypes"}) | ||
| /** | ||
| * JEI Plugin for GregTech Energistics. | ||
| * | ||
| * Registers the Extended Pattern Terminal handler directly. | ||
| * | ||
| * Note: The native AE2 Pattern Terminal (ContainerPatternTerm) handler is | ||
| * replaced at runtime via Mixin (see RecipeRegistryMixin) to support fluid | ||
| * encoding. | ||
| */ | ||
| @SuppressWarnings({ "unused" }) | ||
| @JEIPlugin | ||
| public class JeiPlugin implements IModPlugin { | ||
| @Override | ||
| public void register(IModRegistry registry) | ||
| { | ||
| IRecipeTransferRegistry transferRegistry = registry.getRecipeTransferRegistry(); | ||
|
|
||
| // If true, some change to JEI broke this integration | ||
| if(!(transferRegistry instanceof RecipeTransferRegistry)) | ||
| return; | ||
|
|
||
| RecipeTransferRegistry castedTransferRegistry = (RecipeTransferRegistry) transferRegistry; | ||
|
|
||
| // Collect non-ContainerPatternTerm transfer handlers and flag if AE2 has been found | ||
| // JEE checks if AE2 has been found, but that's not needed as the JVM would throw an exception on the import | ||
| // of ContainerPatternTerm if AE2 was not present | ||
| Table<Class<?>, String, IRecipeTransferHandler> collectedRegistry = | ||
| collectNonPatternTerminals(castedTransferRegistry.getRecipeTransferHandlers()); | ||
|
|
||
| collectedRegistry.put(ContainerPatternTerm.class, Constants.UNIVERSAL_RECIPE_TRANSFER_UID, | ||
| new RecipeTransferHandler()); | ||
| collectedRegistry.put(ExtendedPatternContainer.class, Constants.UNIVERSAL_RECIPE_TRANSFER_UID, | ||
| new ExtendedRecipeTransferHandler()); | ||
| ReflectionHelper.setPrivateValue(RecipeTransferRegistry.class, | ||
| (RecipeTransferRegistry) registry.getRecipeTransferRegistry(), collectedRegistry, | ||
| "recipeTransferHandlers", null); | ||
| } | ||
|
|
||
| protected static <T, U> Table<Class<?>, T, U> collectNonPatternTerminals(ImmutableTable<Class, T, U> transferHandlers) { | ||
| Table<Class<?>, T, U> newRegistry = Table.hashBasedTable(); | ||
| for (final ImmutableTable.Cell<Class, T, U> currentCell : transferHandlers.cellSet()) { | ||
| Class<?> rowKey = currentCell.getRowKey(); | ||
| if(rowKey == null) | ||
| continue; | ||
|
|
||
| if (currentCell.getRowKey().equals(ContainerPatternTerm.class)) { | ||
| continue; | ||
| } | ||
|
|
||
| //noinspection ConstantConditions | ||
| newRegistry.put(currentCell.getRowKey(), currentCell.getColumnKey(), currentCell.getValue()); | ||
| } | ||
|
|
||
| return newRegistry; | ||
| @Override | ||
| public void register(IModRegistry registry) { | ||
| // Register our Extended Pattern Terminal handler | ||
| // This uses the public API and works fine since there's no conflict | ||
| registry.getRecipeTransferRegistry().addRecipeTransferHandler( | ||
| new ExtendedRecipeTransferHandler(), | ||
| Constants.UNIVERSAL_RECIPE_TRANSFER_UID); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/main/java/com/soliddowant/gregtechenergistics/mixins/GregTechEnergisticsMixinPlugin.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package com.soliddowant.gregtechenergistics.mixins; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Set; | ||
|
|
||
| import org.objectweb.asm.tree.ClassNode; | ||
| import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; | ||
| import org.spongepowered.asm.mixin.extensibility.IMixinInfo; | ||
|
|
||
| import net.minecraftforge.fml.common.Loader; | ||
|
|
||
| /** | ||
| * Mixin config plugin that conditionally loads mixins based on mod presence. | ||
| * This prevents crashes when optional dependencies like JEI are not installed. | ||
| * | ||
| * <p> | ||
| * This plugin assumes that JEI-specific mixins are placed in a ".jei" | ||
| * subpackage | ||
| * under the main mixin package. For example, if the mixin package is | ||
| * "com.soliddowant.gregtechenergistics.mixins", then JEI mixins should be in | ||
| * "com.soliddowant.gregtechenergistics.mixins.jei". | ||
| * </p> | ||
| */ | ||
| public class GregTechEnergisticsMixinPlugin implements IMixinConfigPlugin { | ||
|
|
||
| private static final String JEI_PACKAGE_SUFFIX = ".jei."; | ||
| private static final String JEI_MOD_ID = "jei"; | ||
|
|
||
| private String mixinPackage; | ||
|
|
||
| @Override | ||
| public void onLoad(String mixinPackage) { | ||
| this.mixinPackage = mixinPackage; | ||
| } | ||
|
|
||
| @Override | ||
| public String getRefMapperConfig() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { | ||
| // Only gate JEI-related mixins behind JEI presence check | ||
| // Check if the mixin is in the jei subpackage | ||
| String jeiMixinPackage = mixinPackage + JEI_PACKAGE_SUFFIX; | ||
| if (mixinClassName.startsWith(jeiMixinPackage)) { | ||
| return Loader.isModLoaded(JEI_MOD_ID); | ||
| } | ||
|
|
||
| // Apply all other mixins unconditionally | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) { | ||
| // No special target handling needed | ||
| } | ||
|
|
||
| @Override | ||
| public List<String> getMixins() { | ||
| // Return null to let the config file handle mixin listing | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { | ||
| // No pre-apply processing needed | ||
| } | ||
|
|
||
| @Override | ||
| public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { | ||
| // No post-apply processing needed | ||
| } | ||
| } |
59 changes: 59 additions & 0 deletions
59
src/main/java/com/soliddowant/gregtechenergistics/mixins/jei/RecipeRegistryMixin.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package com.soliddowant.gregtechenergistics.mixins.jei; | ||
|
|
||
| import org.spongepowered.asm.mixin.Mixin; | ||
| import org.spongepowered.asm.mixin.Unique; | ||
| import org.spongepowered.asm.mixin.injection.At; | ||
| import org.spongepowered.asm.mixin.injection.Inject; | ||
| import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
|
||
| import com.soliddowant.gregtechenergistics.integration.jei.RecipeTransferHandler; | ||
|
|
||
| import appeng.container.implementations.ContainerPatternTerm; | ||
| import mezz.jei.api.recipe.IRecipeCategory; | ||
| import mezz.jei.api.recipe.transfer.IRecipeTransferHandler; | ||
| import mezz.jei.recipes.RecipeRegistry; | ||
| import net.minecraft.inventory.Container; | ||
|
|
||
| /** | ||
| * Mixin to override JEI's recipe transfer handler lookup for | ||
| * ContainerPatternTerm. | ||
| * | ||
| * This is necessary because RecipeRegistry creates an immutable snapshot of | ||
| * handlers | ||
| * during construction, so runtime modifications via reflection don't work. | ||
| * AE2's native | ||
| * JEI handler doesn't support fluid encoding, so we need to replace it with our | ||
| * own. | ||
| */ | ||
| @Mixin(value = RecipeRegistry.class, remap = false) | ||
| public abstract class RecipeRegistryMixin { | ||
|
|
||
| @Unique | ||
| private static final RecipeTransferHandler GT_ENERGISTICS_HANDLER = new RecipeTransferHandler(); | ||
|
|
||
| @Inject(method = "getRecipeTransferHandler", at = @At("RETURN"), cancellable = true, remap = false) | ||
| private void injectPatternTermHandler( | ||
| Container container, | ||
| IRecipeCategory recipeCategory, | ||
| CallbackInfoReturnable<IRecipeTransferHandler> cir) { | ||
|
|
||
| // Only intercept for ContainerPatternTerm | ||
| if (!(container instanceof ContainerPatternTerm)) { | ||
| return; | ||
| } | ||
|
|
||
| IRecipeTransferHandler originalHandler = cir.getReturnValue(); | ||
|
|
||
| // If there's no handler or it's already ours, do nothing | ||
| if (originalHandler == null) { | ||
| return; | ||
| } | ||
|
|
||
| if (originalHandler instanceof RecipeTransferHandler) { | ||
| return; | ||
| } | ||
|
|
||
| // Replace AE2's handler with this mod's handler | ||
| cir.setReturnValue(GT_ENERGISTICS_HANDLER); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.