From fd4e7653b7fd2cec4ea29426ad6f5e37edde17f3 Mon Sep 17 00:00:00 2001 From: Patbox Date: Fri, 18 Oct 2024 00:26:04 +0200 Subject: [PATCH] Fixup REI support --- polymer-core/build.gradle | 2 +- .../impl/client/InternalClientItemGroup.java | 6 ++++ .../impl/client/compat/ReiCompatibility.java | 2 +- ...rei_CreativeModeTabCollectorImplMixin.java | 25 ++++++++++++++ .../compat/rei_ItemEntryDefinitionMixin.java | 33 ++++++++++++++++--- .../main/resources/polymer-core.mixins.json | 1 + 6 files changed, 62 insertions(+), 7 deletions(-) create mode 100644 polymer-core/src/main/java/eu/pb4/polymer/core/mixin/client/compat/rei_CreativeModeTabCollectorImplMixin.java diff --git a/polymer-core/build.gradle b/polymer-core/build.gradle index 63f2522f..d7dab984 100644 --- a/polymer-core/build.gradle +++ b/polymer-core/build.gradle @@ -60,7 +60,7 @@ dependencies { //modCompileOnlyApi modLocalRuntime("mezz.jei:jei-1.19-common:11.0.0.206") //modCompileOnlyApi modLocalRuntime("mezz.jei:jei-1.19-fabric:11.0.0.206") - modCompileOnly /*modRuntimeOnly*/("maven.modrinth:jei:lIRFslED") + modCompileOnly /*modRuntimeOnly*/("maven.modrinth:jei:19.0.0.1") //modCompileOnly ("mcjty.theoneprobe:theoneprobe-fabric:1.18.2-5.0.9") //modRuntimeOnly ("mcjty.theoneprobe:theoneprobe-fabric:1.18.2-5.0.9") diff --git a/polymer-core/src/main/java/eu/pb4/polymer/core/impl/client/InternalClientItemGroup.java b/polymer-core/src/main/java/eu/pb4/polymer/core/impl/client/InternalClientItemGroup.java index 1a2f4a67..bdd1bb0e 100644 --- a/polymer-core/src/main/java/eu/pb4/polymer/core/impl/client/InternalClientItemGroup.java +++ b/polymer-core/src/main/java/eu/pb4/polymer/core/impl/client/InternalClientItemGroup.java @@ -8,6 +8,8 @@ import net.fabricmc.api.Environment; import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.RegistryWrapper; import net.minecraft.resource.featuretoggle.FeatureSet; import net.minecraft.text.Text; @@ -42,4 +44,8 @@ public Identifier getId() { public boolean polymer$isSyncable() { return false; } + + public RegistryKey getKey() { + return RegistryKey.of(RegistryKeys.ITEM_GROUP, this.identifier); + } } diff --git a/polymer-core/src/main/java/eu/pb4/polymer/core/impl/client/compat/ReiCompatibility.java b/polymer-core/src/main/java/eu/pb4/polymer/core/impl/client/compat/ReiCompatibility.java index 803d84c7..3d090c9d 100644 --- a/polymer-core/src/main/java/eu/pb4/polymer/core/impl/client/compat/ReiCompatibility.java +++ b/polymer-core/src/main/java/eu/pb4/polymer/core/impl/client/compat/ReiCompatibility.java @@ -38,7 +38,7 @@ private static void update(EntryRegistry registry) { @Override public void registerItemComparators(ItemComparatorRegistry registry) { try { - registry.registerGlobal(ITEM_STACK_ENTRY_COMPARATOR); + //registry.registerGlobal(ITEM_STACK_ENTRY_COMPARATOR); } catch (Throwable e) { e.printStackTrace(); } diff --git a/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/client/compat/rei_CreativeModeTabCollectorImplMixin.java b/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/client/compat/rei_CreativeModeTabCollectorImplMixin.java new file mode 100644 index 00000000..ba68c9cc --- /dev/null +++ b/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/client/compat/rei_CreativeModeTabCollectorImplMixin.java @@ -0,0 +1,25 @@ +package eu.pb4.polymer.core.mixin.client.compat; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.llamalad7.mixinextras.sugar.Local; +import eu.pb4.polymer.core.api.item.PolymerItemGroupUtils; +import eu.pb4.polymer.core.impl.client.InternalClientItemGroup; +import me.shedaniel.rei.impl.client.fabric.CreativeModeTabCollectorImpl; +import net.minecraft.item.ItemGroup; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +import java.util.Optional; +import java.util.function.Supplier; + +@Mixin(CreativeModeTabCollectorImpl.class) +public class rei_CreativeModeTabCollectorImplMixin { + @WrapOperation(method = "collectTabs", at = @At(value = "INVOKE", target = "Ljava/util/Optional;orElseThrow(Ljava/util/function/Supplier;)Ljava/lang/Object;"), remap = false) + private static Object getItemGroupKey(Optional instance, Supplier exceptionSupplier, Operation original, @Local ItemGroup group) { + if (instance.isEmpty() && group instanceof InternalClientItemGroup group1) { + return group1.getKey(); + } + return original.call(instance, exceptionSupplier); + } +} diff --git a/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/client/compat/rei_ItemEntryDefinitionMixin.java b/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/client/compat/rei_ItemEntryDefinitionMixin.java index e86c2050..16ee92d3 100644 --- a/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/client/compat/rei_ItemEntryDefinitionMixin.java +++ b/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/client/compat/rei_ItemEntryDefinitionMixin.java @@ -6,6 +6,7 @@ import eu.pb4.polymer.core.impl.client.compat.CompatUtils; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.entry.comparison.ComparisonContext; +import me.shedaniel.rei.api.common.entry.comparison.ItemComparatorRegistry; import me.shedaniel.rei.plugin.client.entry.ItemEntryDefinition; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -14,6 +15,7 @@ import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Pseudo; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @@ -24,15 +26,34 @@ @Environment(EnvType.CLIENT) @Mixin(ItemEntryDefinition.class) public abstract class rei_ItemEntryDefinitionMixin { + @Shadow public abstract ItemStack copy(EntryStack entry, ItemStack value); - @Inject(method = "equals(Lnet/minecraft/item/ItemStack;Lnet/minecraft/item/ItemStack;Lme/shedaniel/rei/api/common/entry/comparison/ComparisonContext;)Z", at = @At("HEAD"), cancellable = true, remap = false, require = 0) + @Inject(method = "equals(Lnet/minecraft/item/ItemStack;Lnet/minecraft/item/ItemStack;Lme/shedaniel/rei/api/common/entry/comparison/ComparisonContext;)Z", at = @At("HEAD"), cancellable = true, require = 0) private void polymer$areEqual(ItemStack o1, ItemStack o2, ComparisonContext context, CallbackInfoReturnable cir) { - if (!CompatUtils.areSamePolymerType(o1, o2)) { - cir.setReturnValue(false); + var lId = PolymerItemUtils.getServerIdentifier(o1); + var rId = PolymerItemUtils.getServerIdentifier(o2); + if ((lId != null || rId != null) && CompatUtils.areSamePolymerType(o1, o2)) { + if (context == ComparisonContext.FUZZY) { + cir.setReturnValue(true); + } else if (context == ComparisonContext.EXACT) { + cir.setReturnValue(CompatUtils.areEqualItems(o1, o2)); + } + } + } + + @Inject(method = "hash(Lme/shedaniel/rei/api/common/entry/EntryStack;Lnet/minecraft/item/ItemStack;Lme/shedaniel/rei/api/common/entry/comparison/ComparisonContext;)J", at = @At("HEAD"), cancellable = true, require = 0) + private void polymer$hash(EntryStack entry, ItemStack value, ComparisonContext context, CallbackInfoReturnable cir) { + var id = PolymerItemUtils.getServerIdentifier(value); + if (id != null) { + long code = 1; + code = 31 * code + id.hashCode(); + code = 31 * code + Long.hashCode(ItemComparatorRegistry.getInstance().hashOf(context, value)); + + cir.setReturnValue(code); } } - @Inject(method = "wildcard(Lme/shedaniel/rei/api/common/entry/EntryStack;Lnet/minecraft/item/ItemStack;)Lnet/minecraft/item/ItemStack;", at = @At("HEAD"), cancellable = true, remap = false, require = 0) + @Inject(method = "wildcard(Lme/shedaniel/rei/api/common/entry/EntryStack;Lnet/minecraft/item/ItemStack;)Lnet/minecraft/item/ItemStack;", at = @At("HEAD"), cancellable = true, require = 0) private void polymer$wildcard(EntryStack entry, ItemStack value, CallbackInfoReturnable cir) { var id1 = PolymerItemUtils.getServerIdentifier(value); if (id1 != null) { @@ -40,11 +61,13 @@ public abstract class rei_ItemEntryDefinitionMixin { if (item != null) { cir.setReturnValue(item.visualStack().copy()); + } else { + cir.setReturnValue(value.copyWithCount(1)); } } } - @Inject(method = "getIdentifier(Lme/shedaniel/rei/api/common/entry/EntryStack;Lnet/minecraft/item/ItemStack;)Lnet/minecraft/util/Identifier;", at = @At("HEAD"), cancellable = true, remap = false, require = 0) + @Inject(method = "getIdentifier(Lme/shedaniel/rei/api/common/entry/EntryStack;Lnet/minecraft/item/ItemStack;)Lnet/minecraft/util/Identifier;", at = @At("HEAD"), cancellable = true, require = 0) private void polymer$getIdentifier(EntryStack entry, ItemStack value, CallbackInfoReturnable<@Nullable Identifier> cir) { var id1 = PolymerItemUtils.getServerIdentifier(value); if (id1 != null) { diff --git a/polymer-core/src/main/resources/polymer-core.mixins.json b/polymer-core/src/main/resources/polymer-core.mixins.json index 25708cee..5f060627 100644 --- a/polymer-core/src/main/resources/polymer-core.mixins.json +++ b/polymer-core/src/main/resources/polymer-core.mixins.json @@ -108,6 +108,7 @@ "client.compat.emi_EmiStackMixin", "client.compat.emi_ItemEmiStack2Mixin", "client.compat.jei_StackHelperMixin", + "client.compat.rei_CreativeModeTabCollectorImplMixin", "client.compat.rei_ItemEntryDefinitionMixin", "client.compat.wthit_HarvestProviderMixin", "client.entity.EntityMixin",