From fbbd3aefe2c3ae456a9a1d28415ef19410c10a76 Mon Sep 17 00:00:00 2001 From: Aaron <51387595+AzureAaron@users.noreply.github.com> Date: Mon, 23 Dec 2024 22:44:19 -0500 Subject: Fix Simon Says Solver (#1100) --- .../de/hysky/skyblocker/mixins/ClientWorldMixin.java | 16 +++++++++++++--- .../skyblocker/skyblock/dungeon/device/SimonSays.java | 10 ++++++---- 2 files changed, 19 insertions(+), 7 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/de/hysky/skyblocker/mixins/ClientWorldMixin.java b/src/main/java/de/hysky/skyblocker/mixins/ClientWorldMixin.java index 0d7e2c70..d9d90cd8 100644 --- a/src/main/java/de/hysky/skyblocker/mixins/ClientWorldMixin.java +++ b/src/main/java/de/hysky/skyblocker/mixins/ClientWorldMixin.java @@ -10,15 +10,25 @@ import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.client.world.ClientWorld; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.BlockView; + +import org.jetbrains.annotations.Nullable; 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; import com.llamalad7.mixinextras.sugar.Local; +import com.llamalad7.mixinextras.sugar.Share; +import com.llamalad7.mixinextras.sugar.ref.LocalRef; @Mixin(ClientWorld.class) -public class ClientWorldMixin { +public abstract class ClientWorldMixin implements BlockView { + + @Inject(method = "handleBlockUpdate", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;II)Z")) + private void skyblocker$beforeBlockUpdate(CallbackInfo ci, @Local(argsOnly = true) BlockPos pos, @Share("old") LocalRef<@Nullable BlockState> oldState) { + oldState.set(getBlockState(pos)); + } /** * @implNote The {@code pos} can be mutable when this is called by chunk delta updates, so if you want to copy it into memory @@ -26,7 +36,7 @@ public class ClientWorldMixin { */ //TODO might be worth creating an event for this @Inject(method = "handleBlockUpdate", at = @At("RETURN")) - private void skyblocker$handleBlockUpdate(CallbackInfo ci, @Local(argsOnly = true) BlockPos pos, @Local(argsOnly = true) BlockState state) { + private void skyblocker$afterBlockUpdate(CallbackInfo ci, @Local(argsOnly = true) BlockPos pos, @Local(argsOnly = true) BlockState state, @Share("old") LocalRef<@Nullable BlockState> oldState) { if (Utils.isInCrimson()) { DojoManager.onBlockUpdate(pos.toImmutable(), state); } else if (Utils.isInCrystalHollows()) { @@ -37,6 +47,6 @@ public class ClientWorldMixin { if (state.isOf(Blocks.BEACON)) BeaconHighlighter.beaconPositions.add(pos.toImmutable()); } - SimonSays.onBlockUpdate(pos, state); + SimonSays.onBlockUpdate(pos, state, oldState.get()); } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/device/SimonSays.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/device/SimonSays.java index e6c71b3d..1b94ca18 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/device/SimonSays.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/device/SimonSays.java @@ -32,6 +32,8 @@ import net.minecraft.world.World; import java.util.Objects; +import org.jetbrains.annotations.Nullable; + public class SimonSays { private static final Box BOARD_AREA = Box.enclosing(new BlockPos(111, 123, 92), new BlockPos(111, 120, 95)); private static final Box BUTTONS_AREA = Box.enclosing(new BlockPos(110, 123, 92), new BlockPos(110, 120, 95)); @@ -71,14 +73,14 @@ public class SimonSays { //If the player goes out of the range required to receive block/chunk updates then their solver won't detect stuff but that //doesn't matter because if they're doing pre-4 or something they won't be doing the ss, and if they end up needing to they can //just reset it or have the other person finish the current sequence first then let them do it. - public static void onBlockUpdate(BlockPos pos, BlockState state) { + public static void onBlockUpdate(BlockPos pos, BlockState newState, @Nullable BlockState oldState) { if (shouldProcess()) { Vec3d posVec = Vec3d.of(pos); - Block block = state.getBlock(); + Block newBlock = newState.getBlock(); - if (BOARD_AREA.contains(posVec) && block.equals(Blocks.SEA_LANTERN)) { + if (BOARD_AREA.contains(posVec) && newBlock.equals(Blocks.OBSIDIAN) && oldState != null && oldState.getBlock().equals(Blocks.SEA_LANTERN)) { SIMON_PATTERN.add(pos.toImmutable()); //Convert to immutable because chunk delta updates use the mutable variant - } else if (BUTTONS_AREA.contains(posVec) && block.equals(Blocks.AIR)) { + } else if (BUTTONS_AREA.contains(posVec) && newBlock.equals(Blocks.AIR)) { //Upon reaching the showing of the next sequence we need to reset the state so that we don't show old data //Otherwise, the nextIndex will go beyond 5 and that can cause bugs, it also helps with the other case noted above reset(); -- cgit