[1.19] fix REI item hiding (#26)

Co-authored-by: LLytho <main@lytho.dev>
This commit is contained in:
Relentless 2022-11-30 20:49:18 +01:00 committed by GitHub
parent d89c2f1f60
commit bbb62b9e44
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 110 additions and 34 deletions

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,23 @@
package com.almostreliable.unified;
import java.util.ArrayList;
import java.util.List;
public class ClientTagUpdateEvent {
private static final List<Invoker> 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();
}
}

View file

@ -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";

View file

@ -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<ItemStack> items = HideHelper.createHidingList(config);
if (!items.isEmpty()) {

View file

@ -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

View file

@ -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<String, BooleanSupplier> CONDITIONS = ImmutableMap.of(
"com.almostreliable.unified.mixin.JeiRecipeLayoutMixin", modLoaded("jei")
"com.almostreliable.unified.mixin.JeiRecipeLayoutMixin", modLoaded(ModConstants.JEI)
);
private static BooleanSupplier modLoaded(String id) {

View file

@ -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();
}
}

View file

@ -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
}
}

View file

@ -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

View file

@ -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 }

View file

@ -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

View file

@ -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