aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hysky/skyblocker/skyblock/dungeon
diff options
context:
space:
mode:
authorAaron <51387595+AzureAaron@users.noreply.github.com>2024-05-19 11:45:42 -0400
committerAaron <51387595+AzureAaron@users.noreply.github.com>2024-07-10 15:42:29 -0400
commite1b951f6124c28a5cc1ec9d9ca3416f5104b27b3 (patch)
tree339cf2339cea0faab7b61849e027a2ef7957f7d5 /src/main/java/de/hysky/skyblocker/skyblock/dungeon
parentd3ca54c64fffc34fa0f100a2f51dbe5314b7b3e1 (diff)
downloadSkyblocker-e1b951f6124c28a5cc1ec9d9ca3416f5104b27b3.tar.gz
Skyblocker-e1b951f6124c28a5cc1ec9d9ca3416f5104b27b3.tar.bz2
Skyblocker-e1b951f6124c28a5cc1ec9d9ca3416f5104b27b3.zip
Simon Says Solver
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/skyblock/dungeon')
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/dungeon/device/SimonSays.java124
1 files changed, 124 insertions, 0 deletions
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
new file mode 100644
index 00000000..341c6025
--- /dev/null
+++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/device/SimonSays.java
@@ -0,0 +1,124 @@
+package de.hysky.skyblocker.skyblock.dungeon.device;
+
+import java.util.Objects;
+
+import de.hysky.skyblocker.config.SkyblockerConfigManager;
+import de.hysky.skyblocker.skyblock.dungeon.DungeonBoss;
+import de.hysky.skyblocker.skyblock.dungeon.secrets.DungeonManager;
+import de.hysky.skyblocker.utils.Boxes;
+import de.hysky.skyblocker.utils.Utils;
+import de.hysky.skyblocker.utils.render.RenderHelper;
+import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
+import it.unimi.dsi.fastutil.ints.Int2ObjectRBTreeMap;
+import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
+import it.unimi.dsi.fastutil.objects.ObjectSet;
+import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
+import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
+import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents;
+import net.fabricmc.fabric.api.event.player.UseBlockCallback;
+import net.minecraft.block.Block;
+import net.minecraft.block.BlockState;
+import net.minecraft.block.Blocks;
+import net.minecraft.client.MinecraftClient;
+import net.minecraft.client.world.ClientWorld;
+import net.minecraft.entity.player.PlayerEntity;
+import net.minecraft.util.ActionResult;
+import net.minecraft.util.DyeColor;
+import net.minecraft.util.Hand;
+import net.minecraft.util.hit.BlockHitResult;
+import net.minecraft.util.math.BlockPos;
+import net.minecraft.util.math.Box;
+import net.minecraft.util.math.Vec3d;
+import net.minecraft.world.World;
+
+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));
+ private static final BlockPos START_BUTTON = new BlockPos(110, 121, 91);
+ private static final float[] GREEN = DyeColor.LIME.getColorComponents();
+ private static final float[] YELLOW = DyeColor.YELLOW.getColorComponents();
+ private static final ObjectSet<BlockPos> CLICKED_BUTTONS = new ObjectOpenHashSet<>();
+ private static final Int2ObjectRBTreeMap<BlockPos> SIMON_PATTERN = new Int2ObjectRBTreeMap<>();
+
+ public static void init() {
+ UseBlockCallback.EVENT.register(SimonSays::onBlockInteract);
+ ClientPlayConnectionEvents.JOIN.register((_handler, _sender, _client) -> reset());
+ WorldRenderEvents.AFTER_TRANSLUCENT.register(SimonSays::render);
+ }
+
+ //When another player is pressing the buttons hypixel doesnt send block or block state updates
+ //so you can't see it which means the solver can only count the buttons you press yourself
+ private static ActionResult onBlockInteract(PlayerEntity player, World world, Hand hand, BlockHitResult hitResult) {
+ if (shouldProcess()) {
+ BlockPos pos = hitResult.getBlockPos();
+ Block block = world.getBlockState(pos).getBlock();
+
+ if (block.equals(Blocks.STONE_BUTTON)) {
+ if (BUTTONS_AREA.contains(Vec3d.of(pos))) {
+ CLICKED_BUTTONS.add(new BlockPos(pos)); //Copy just in case it becomes mutable in the future
+ } else if (pos.equals(START_BUTTON)) {
+ reset();
+ }
+ }
+ }
+
+ //This could also be used to cancel incorrect clicks in the future
+ return ActionResult.PASS;
+ }
+
+ //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) {
+ if (shouldProcess()) {
+ Vec3d posVec = Vec3d.of(pos);
+ Block block = state.getBlock();
+
+ if (BOARD_AREA.contains(posVec) && block.equals(Blocks.SEA_LANTERN)) {
+ int nextIndex = SIMON_PATTERN.size() + 1;
+
+ SIMON_PATTERN.put(nextIndex, new BlockPos(pos)); //Copy it because it can be mutable in chunk delta updates
+ } else if (BUTTONS_AREA.contains(posVec) && block.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();
+ }
+ }
+ }
+
+ private static void render(WorldRenderContext context) {
+ if (shouldProcess()) {
+ int buttonsRendered = 0;
+
+ //Tree maps iterate in natural order of key - so it goes from the lowest to the highest int :)
+ for (Int2ObjectMap.Entry<BlockPos> entry : SIMON_PATTERN.int2ObjectEntrySet()) {
+ //Offset to west (x - 1) to get the position of the button from the sea lantern block
+ BlockPos buttonPos = entry.getValue().west();
+ ClientWorld world = Objects.requireNonNull(MinecraftClient.getInstance().world); //Should never be null here
+ BlockState state = world.getBlockState(buttonPos);
+
+ //If the button hasn't been clicked yet
+ //Also don't do anything if the button isn't there which means the device is showing the sequence
+ if (!CLICKED_BUTTONS.contains(buttonPos) && state.getBlock().equals(Blocks.STONE_BUTTON)) {
+ Box outline = state.getOutlineShape(world, buttonPos).asCuboid().getBoundingBox().offset(buttonPos);
+ float[] colour = buttonsRendered == 0 ? GREEN : YELLOW;
+
+ RenderHelper.renderFilled(context, Boxes.getMinVec(outline), Boxes.getLengthVec(outline), colour, 0.5f, true);
+ RenderHelper.renderOutline(context, outline, colour, 5f, true);
+
+ if (++buttonsRendered == 2) return;
+ }
+ }
+ }
+ }
+
+ private static boolean shouldProcess() {
+ return SkyblockerConfigManager.get().dungeons.devices.solveSimonSays &&
+ Utils.isInDungeons() && DungeonManager.isInBoss() && DungeonManager.getBoss() == DungeonBoss.MAXOR;
+ }
+
+ private static void reset() {
+ CLICKED_BUTTONS.clear();
+ SIMON_PATTERN.clear();
+ }
+}