Skip to content

Commit

Permalink
Make BooleanPropertyMixin and UtilMixin more compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
jpenilla committed Aug 9, 2024
1 parent 13374ad commit 2b5c570
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Boolean> implements PropertyAccess<Boolean> {
Expand All @@ -13,13 +14,39 @@ protected BooleanPropertyMixin(String string, Class<Boolean> 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<Boolean> 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -41,15 +42,16 @@ 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",
target = "(ILjava/util/concurrent/ForkJoinPool$ForkJoinWorkerThreadFactory;Ljava/lang/Thread$UncaughtExceptionHandler;Z)Ljava/util/concurrent/ForkJoinPool;"
)
)
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<ForkJoinPool> original) {
final int threads = getThreadCounts(1, getMaxThreads());

return new ForkJoinPool(threads, factory, handler, asyncMode, 0, Integer.MAX_VALUE, 1, null, 365, TimeUnit.DAYS);
Expand Down

0 comments on commit 2b5c570

Please sign in to comment.