Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Simon Says Solver #1100

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/main/java/de/hysky/skyblocker/mixins/ClientWorldMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,33 @@
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
* (e.g. store it in a field/list/map) make sure to duplicate it via {@link BlockPos#toImmutable()}.
*/
//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()) {
Expand All @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

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));
Expand Down Expand Up @@ -71,14 +73,14 @@ private static ActionResult onBlockInteract(PlayerEntity player, World world, Ha
//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();
Expand Down
Loading