Skip to content

Commit

Permalink
Fixup REI support
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed Oct 17, 2024
1 parent 8451816 commit fd4e765
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 7 deletions.
2 changes: 1 addition & 1 deletion polymer-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -42,4 +44,8 @@ public Identifier getId() {
public boolean polymer$isSyncable() {
return false;
}

public RegistryKey<ItemGroup> getKey() {
return RegistryKey.of(RegistryKeys.ITEM_GROUP, this.identifier);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Object> exceptionSupplier, Operation<Object> original, @Local ItemGroup group) {
if (instance.isEmpty() && group instanceof InternalClientItemGroup group1) {
return group1.getKey();
}
return original.call(instance, exceptionSupplier);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -24,27 +26,48 @@
@Environment(EnvType.CLIENT)
@Mixin(ItemEntryDefinition.class)
public abstract class rei_ItemEntryDefinitionMixin {
@Shadow public abstract ItemStack copy(EntryStack<ItemStack> 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<Boolean> 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<ItemStack> entry, ItemStack value, ComparisonContext context, CallbackInfoReturnable<Long> 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<ItemStack> entry, ItemStack value, CallbackInfoReturnable<ItemStack> cir) {
var id1 = PolymerItemUtils.getServerIdentifier(value);
if (id1 != null) {
var item = ClientPolymerItem.REGISTRY.get(id1);

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<ItemStack> entry, ItemStack value, CallbackInfoReturnable<@Nullable Identifier> cir) {
var id1 = PolymerItemUtils.getServerIdentifier(value);
if (id1 != null) {
Expand Down
1 change: 1 addition & 0 deletions polymer-core/src/main/resources/polymer-core.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit fd4e765

Please sign in to comment.