From 2b5c570ec36c8b2b57cc48faa5f635fb49b6f084 Mon Sep 17 00:00:00 2001 From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Date: Thu, 8 Aug 2024 22:12:55 -0700 Subject: [PATCH] Make BooleanPropertyMixin and UtilMixin more compatible --- .../BooleanPropertyMixin.java | 37 ++++++++++++++++--- .../mixin/util_thread_counts/UtilMixin.java | 8 ++-- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/main/java/ca/spottedleaf/moonrise/mixin/blockstate_propertyaccess/BooleanPropertyMixin.java b/src/main/java/ca/spottedleaf/moonrise/mixin/blockstate_propertyaccess/BooleanPropertyMixin.java index edddb081..5d03f7ff 100644 --- a/src/main/java/ca/spottedleaf/moonrise/mixin/blockstate_propertyaccess/BooleanPropertyMixin.java +++ b/src/main/java/ca/spottedleaf/moonrise/mixin/blockstate_propertyaccess/BooleanPropertyMixin.java @@ -4,7 +4,8 @@ import net.minecraft.world.level.block.state.properties.BooleanProperty; import net.minecraft.world.level.block.state.properties.Property; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; @Mixin(BooleanProperty.class) abstract class BooleanPropertyMixin extends Property implements PropertyAccess { @@ -13,13 +14,39 @@ protected BooleanPropertyMixin(String string, Class class_) { } /** + * This skips all ops after the identity comparison in the original code. + * * @reason Properties are identity comparable * @author Spottedleaf */ - @Overwrite - @Override - public boolean equals(final Object obj) { - return this == obj; + /* + TODO: idk why this isn't working, we'll just redirect the super call for now and deal with the useless instanceof op + @WrapOperation( + method = "equals", + at = @At( + value = "CONSTANT", + opcode = Opcodes.INSTANCEOF, + args = "classValue=net/minecraft/world/level/block/state/properties/BooleanProperty" + ) + ) + private boolean skipFurtherComparison(final Object obj, final Operation orig) { + return false; + } + */ + + /** + * @reason Properties are identity comparable + * @author Spottedleaf + */ + @Redirect( + method = "equals", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/level/block/state/properties/Property;equals(Ljava/lang/Object;)Z" + ) + ) + private boolean skipSuperCheck(final Property instance, final Object object) { + return false; } @Override diff --git a/src/main/java/ca/spottedleaf/moonrise/mixin/util_thread_counts/UtilMixin.java b/src/main/java/ca/spottedleaf/moonrise/mixin/util_thread_counts/UtilMixin.java index c13eb967..198e1727 100644 --- a/src/main/java/ca/spottedleaf/moonrise/mixin/util_thread_counts/UtilMixin.java +++ b/src/main/java/ca/spottedleaf/moonrise/mixin/util_thread_counts/UtilMixin.java @@ -1,12 +1,13 @@ package ca.spottedleaf.moonrise.mixin.util_thread_counts; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import net.minecraft.Util; import net.minecraft.util.Mth; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; import java.util.concurrent.ForkJoinPool; import java.util.concurrent.TimeUnit; @@ -41,7 +42,7 @@ private static int getThreadCounts(final int min, final int max) { * not lost due to some timeout, as G1GC has some issues cleaning up those. * @author Spottedleaf */ - @Redirect( + @WrapOperation( method = "makeExecutor", at = @At( value = "NEW", @@ -49,7 +50,8 @@ private static int getThreadCounts(final int min, final int max) { ) ) private static ForkJoinPool modifyExecutor(final int parallelism, final ForkJoinPool.ForkJoinWorkerThreadFactory factory, - final Thread.UncaughtExceptionHandler handler, final boolean asyncMode) { + final Thread.UncaughtExceptionHandler handler, final boolean asyncMode, + final Operation original) { final int threads = getThreadCounts(1, getMaxThreads()); return new ForkJoinPool(threads, factory, handler, asyncMode, 0, Integer.MAX_VALUE, 1, null, 365, TimeUnit.DAYS);