From bbb62b9e4497a9e2f1f9087e5b28eac7f2417943 Mon Sep 17 00:00:00 2001 From: Relentless Date: Wed, 30 Nov 2022 20:49:18 +0100 Subject: [PATCH] [1.19] fix REI item hiding (#26) Co-authored-by: LLytho --- CHANGELOG.md | 8 +++++ Common/build.gradle.kts | 2 ++ .../unified/ClientTagUpdateEvent.java | 23 ++++++++++++++ .../unified/api/ModConstants.java | 3 ++ .../unified/compat/AlmostJEI.java | 10 +++--- .../unified/compat/AlmostREI.java | 31 +++++++++++++------ .../unified/mixin/AlmostMixinPlugin.java | 3 +- .../mixin/ClientPacketListenerMixin.java | 17 ++++++++++ .../almostunified-common.mixins.json | 30 +++++++++--------- Fabric/build.gradle.kts | 2 ++ Forge/build.gradle.kts | 4 +++ Forge/src/main/resources/META-INF/mods.toml | 7 +++++ gradle.properties | 4 +-- 13 files changed, 110 insertions(+), 34 deletions(-) create mode 100644 Common/src/main/java/com/almostreliable/unified/ClientTagUpdateEvent.java create mode 100644 Common/src/main/java/com/almostreliable/unified/mixin/ClientPacketListenerMixin.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 96889bb..3d93b64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog], and this project adheres to [Semantic Versioning]. +## Unreleased + +### Changed +- REI on Forge now uses a native plugin instead of the compat layer + +### Fixed +- automatic item hiding with REI + ## [0.2.6] - 2022-11-21 ### Removed diff --git a/Common/build.gradle.kts b/Common/build.gradle.kts index 34821cc..8eff9f8 100644 --- a/Common/build.gradle.kts +++ b/Common/build.gradle.kts @@ -39,6 +39,8 @@ dependencies { }) modCompileOnly("me.shedaniel:RoughlyEnoughItems-api:$reiVersion") // required for common rei plugin + compileOnly("me.shedaniel:REIPluginCompatibilities-forge-annotations:9.+") // required to disable rei compat layer on jei plugin + testCompileOnly("me.shedaniel:REIPluginCompatibilities-forge-annotations:9.+") // don't question this, it's required for compiling modCompileOnly("mezz.jei:jei-$minecraftVersion-common:$jeiVersion") // required for common jei plugin and mixin modCompileOnly("dev.latvian.mods:kubejs-fabric:$kubejsVersion") // required for common kubejs plugin | common has remapping issues diff --git a/Common/src/main/java/com/almostreliable/unified/ClientTagUpdateEvent.java b/Common/src/main/java/com/almostreliable/unified/ClientTagUpdateEvent.java new file mode 100644 index 0000000..d3d0dc9 --- /dev/null +++ b/Common/src/main/java/com/almostreliable/unified/ClientTagUpdateEvent.java @@ -0,0 +1,23 @@ +package com.almostreliable.unified; + +import java.util.ArrayList; +import java.util.List; + +public class ClientTagUpdateEvent { + + private static final List INVOKERS = new ArrayList<>(); + + public static void register(Invoker invoker) { + INVOKERS.add(invoker); + } + + public static void invoke() { + for (Invoker invoker : INVOKERS) { + invoker.invoke(); + } + } + + public interface Invoker { + void invoke(); + } +} diff --git a/Common/src/main/java/com/almostreliable/unified/api/ModConstants.java b/Common/src/main/java/com/almostreliable/unified/api/ModConstants.java index df43a1c..64aaca1 100644 --- a/Common/src/main/java/com/almostreliable/unified/api/ModConstants.java +++ b/Common/src/main/java/com/almostreliable/unified/api/ModConstants.java @@ -2,6 +2,9 @@ package com.almostreliable.unified.api; @SuppressWarnings("SpellCheckingInspection") public final class ModConstants { + public static final String JEI = "jei"; + public static final String REI = "roughlyenoughitems"; + public static final String IE = "immersiveengineering"; public static final String AMETHYST_IMBUEMENT = "amethyst_imbuement"; public static final String AD_ASTRA = "ad_astra"; diff --git a/Common/src/main/java/com/almostreliable/unified/compat/AlmostJEI.java b/Common/src/main/java/com/almostreliable/unified/compat/AlmostJEI.java index 7b1bad3..99303e1 100644 --- a/Common/src/main/java/com/almostreliable/unified/compat/AlmostJEI.java +++ b/Common/src/main/java/com/almostreliable/unified/compat/AlmostJEI.java @@ -1,11 +1,12 @@ package com.almostreliable.unified.compat; -import com.almostreliable.unified.BuildConfig; +import com.almostreliable.unified.api.ModConstants; import com.almostreliable.unified.config.Config; import com.almostreliable.unified.config.UnifyConfig; import com.almostreliable.unified.recipe.CRTLookup; import com.almostreliable.unified.utils.Utils; import com.mojang.blaze3d.vertex.PoseStack; +import me.shedaniel.rei.plugincompatibilities.api.REIPluginCompatIgnore; import mezz.jei.api.IModPlugin; import mezz.jei.api.JeiPlugin; import mezz.jei.api.constants.VanillaTypes; @@ -17,20 +18,19 @@ import net.minecraft.world.item.ItemStack; import java.util.Collection; +@REIPluginCompatIgnore @JeiPlugin public class AlmostJEI implements IModPlugin { @Override public ResourceLocation getPluginUid() { - return new ResourceLocation(BuildConfig.MOD_ID, "jei"); + return Utils.getRL(ModConstants.JEI); } @Override public void onRuntimeAvailable(IJeiRuntime jei) { UnifyConfig config = Config.load(UnifyConfig.NAME, new UnifyConfig.Serializer()); - if (config.reiOrJeiDisabled()) { - return; - } + if (config.reiOrJeiDisabled()) return; Collection items = HideHelper.createHidingList(config); if (!items.isEmpty()) { diff --git a/Common/src/main/java/com/almostreliable/unified/compat/AlmostREI.java b/Common/src/main/java/com/almostreliable/unified/compat/AlmostREI.java index 44cae18..0174f4f 100644 --- a/Common/src/main/java/com/almostreliable/unified/compat/AlmostREI.java +++ b/Common/src/main/java/com/almostreliable/unified/compat/AlmostREI.java @@ -1,7 +1,7 @@ package com.almostreliable.unified.compat; -import com.almostreliable.unified.AlmostUnifiedPlatform; -import com.almostreliable.unified.Platform; +import com.almostreliable.unified.ClientTagUpdateEvent; +import com.almostreliable.unified.api.ModConstants; import com.almostreliable.unified.config.Config; import com.almostreliable.unified.config.UnifyConfig; import com.almostreliable.unified.recipe.CRTLookup; @@ -21,7 +21,7 @@ import me.shedaniel.rei.api.client.registry.display.DisplayCategoryView; import me.shedaniel.rei.api.common.display.Display; import me.shedaniel.rei.api.common.plugins.PluginManager; import me.shedaniel.rei.api.common.registry.ReloadStage; -import me.shedaniel.rei.api.common.util.EntryStacks; +import me.shedaniel.rei.api.common.util.EntryIngredients; import net.minecraft.client.renderer.Rect2i; import javax.annotation.Nullable; @@ -30,15 +30,26 @@ import java.util.List; @SuppressWarnings("UnstableApiUsage") public class AlmostREI implements REIClientPlugin { + @Nullable private BasicFilteringRule.MarkDirty filterUpdate; + + public AlmostREI() { + ClientTagUpdateEvent.register(() -> { + if (filterUpdate != null) filterUpdate.markDirty(); + }); + } + + @Override + public String getPluginProviderName() { + return Utils.prefix(ModConstants.REI); + } + @Override public void registerBasicEntryFiltering(BasicFilteringRule rule) { - // REI compat layer will automatically hide entries for Forge through JEI - if (AlmostUnifiedPlatform.INSTANCE.getPlatform() == Platform.FORGE) return; - - UnifyConfig config = Config.load(UnifyConfig.NAME, new UnifyConfig.Serializer()); - if (config.reiOrJeiDisabled()) return; - - HideHelper.createHidingList(config).stream().map(EntryStacks::of).forEach(rule::hide); + filterUpdate = rule.hide(() -> { + UnifyConfig config = Config.load(UnifyConfig.NAME, new UnifyConfig.Serializer()); + if (config.reiOrJeiDisabled()) return List.of(); + return EntryIngredients.ofItemStacks(HideHelper.createHidingList(config)); + }); } @Override diff --git a/Common/src/main/java/com/almostreliable/unified/mixin/AlmostMixinPlugin.java b/Common/src/main/java/com/almostreliable/unified/mixin/AlmostMixinPlugin.java index 612c620..600140e 100644 --- a/Common/src/main/java/com/almostreliable/unified/mixin/AlmostMixinPlugin.java +++ b/Common/src/main/java/com/almostreliable/unified/mixin/AlmostMixinPlugin.java @@ -1,6 +1,7 @@ package com.almostreliable.unified.mixin; import com.almostreliable.unified.AlmostUnifiedPlatform; +import com.almostreliable.unified.api.ModConstants; import com.google.common.collect.ImmutableMap; import org.objectweb.asm.tree.ClassNode; import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; @@ -16,7 +17,7 @@ public class AlmostMixinPlugin implements IMixinConfigPlugin { private static final BooleanSupplier TRUE = () -> true; private static final Map CONDITIONS = ImmutableMap.of( - "com.almostreliable.unified.mixin.JeiRecipeLayoutMixin", modLoaded("jei") + "com.almostreliable.unified.mixin.JeiRecipeLayoutMixin", modLoaded(ModConstants.JEI) ); private static BooleanSupplier modLoaded(String id) { diff --git a/Common/src/main/java/com/almostreliable/unified/mixin/ClientPacketListenerMixin.java b/Common/src/main/java/com/almostreliable/unified/mixin/ClientPacketListenerMixin.java new file mode 100644 index 0000000..8dc41a0 --- /dev/null +++ b/Common/src/main/java/com/almostreliable/unified/mixin/ClientPacketListenerMixin.java @@ -0,0 +1,17 @@ +package com.almostreliable.unified.mixin; + +import com.almostreliable.unified.ClientTagUpdateEvent; +import net.minecraft.client.multiplayer.ClientPacketListener; +import net.minecraft.network.protocol.game.ClientboundUpdateTagsPacket; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(ClientPacketListener.class) +public class ClientPacketListenerMixin { + @Inject(method = "handleUpdateTags", at = @At("RETURN")) + private void runClientTagUpdateEvent(ClientboundUpdateTagsPacket packet, CallbackInfo ci) { + ClientTagUpdateEvent.invoke(); + } +} diff --git a/Common/src/main/resources/almostunified-common.mixins.json b/Common/src/main/resources/almostunified-common.mixins.json index 96ad23e..e9853df 100644 --- a/Common/src/main/resources/almostunified-common.mixins.json +++ b/Common/src/main/resources/almostunified-common.mixins.json @@ -1,18 +1,16 @@ { - "required": true, - "minVersion": "0.8.5", - "package": "com.almostreliable.unified.mixin", - "refmap": "almostunified.refmap.json", - "compatibilityLevel": "JAVA_17", - "plugin": "com.almostreliable.unified.mixin.AlmostMixinPlugin", - "mixins": [ - "RecipeManagerMixin", - "ReloadableServerResourcesMixin" - ], - "client": [ - "JeiRecipeLayoutMixin" - ], - "injectors": { - "defaultRequire": 1 - } + "required": true, + "minVersion": "0.8.5", + "package": "com.almostreliable.unified.mixin", + "refmap": "almostunified.refmap.json", + "compatibilityLevel": "JAVA_17", + "plugin": "com.almostreliable.unified.mixin.AlmostMixinPlugin", + "mixins": [ + "RecipeManagerMixin", + "ReloadableServerResourcesMixin" + ], + "client": ["ClientPacketListenerMixin", "JeiRecipeLayoutMixin"], + "injectors": { + "defaultRequire": 1 + } } diff --git a/Fabric/build.gradle.kts b/Fabric/build.gradle.kts index 4cf38c5..a83001b 100644 --- a/Fabric/build.gradle.kts +++ b/Fabric/build.gradle.kts @@ -61,6 +61,8 @@ dependencies { }) modCompileOnly("me.shedaniel:RoughlyEnoughItems-api-fabric:$reiVersion") // required for common rei plugin + compileOnly("me.shedaniel:REIPluginCompatibilities-forge-annotations:9.+") // required to disable rei compat layer on jei plugin + testCompileOnly("me.shedaniel:REIPluginCompatibilities-forge-annotations:9.+") // don't question this, it's required for compiling modCompileOnly("mezz.jei:jei-$minecraftVersion-fabric:$jeiVersion") // required for common jei plugin and mixin // runtime only diff --git a/Forge/build.gradle.kts b/Forge/build.gradle.kts index 4bc25ff..73c4024 100644 --- a/Forge/build.gradle.kts +++ b/Forge/build.gradle.kts @@ -68,6 +68,10 @@ dependencies { // required for common rei plugin | api does not work here modCompileOnly("me.shedaniel:RoughlyEnoughItems-forge:$reiVersion") + // required to disable rei compat layer on jei plugin + compileOnly("me.shedaniel:REIPluginCompatibilities-forge-annotations:9.+") + // don't question this, it's required for compiling + testCompileOnly("me.shedaniel:REIPluginCompatibilities-forge-annotations:9.+") // required for common jei plugin and mixin, transitivity is off because it breaks the forge runtime modCompileOnly("mezz.jei:jei-$minecraftVersion-forge:$jeiVersion") { isTransitive = false } diff --git a/Forge/src/main/resources/META-INF/mods.toml b/Forge/src/main/resources/META-INF/mods.toml index 660de9d..e96e139 100644 --- a/Forge/src/main/resources/META-INF/mods.toml +++ b/Forge/src/main/resources/META-INF/mods.toml @@ -32,6 +32,13 @@ versionRange = "[${reiMinVersion},)" ordering = "BEFORE" side = "BOTH" +[[dependencies.${modId}]] +modId = "rei_plugin_compatibilities" +mandatory = false +versionRange = "[9.0.43,)" +ordering = "BEFORE" +side = "BOTH" + [[dependencies.${modId}]] modId = "kubejs" mandatory = false diff --git a/gradle.properties b/gradle.properties index 73b1286..8f88f15 100644 --- a/gradle.properties +++ b/gradle.properties @@ -27,8 +27,8 @@ fabricVersion = 0.63.0+1.19.2 fabricLoaderVersion = 0.14.9 # Dependencies -reiVersion = 9.1.558 -reiMinVersion = 9.1.558 +reiVersion = 9.1.574 +reiMinVersion = 9.1.574 jeiVersion = 11+ kubejsVersion = 1902.6.0-build.117 kubejsMinVersion = 1902.6.0-build.117