diff options
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/skyblock/dungeon')
5 files changed, 77 insertions, 54 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/LividColor.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/LividColor.java index 42810b60..b6a035aa 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/LividColor.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/LividColor.java @@ -1,23 +1,24 @@ package de.hysky.skyblocker.skyblock.dungeon; -import de.hysky.skyblocker.config.SkyblockerConfig; import de.hysky.skyblocker.config.SkyblockerConfigManager; import de.hysky.skyblocker.config.configs.DungeonsConfig; import de.hysky.skyblocker.skyblock.dungeon.secrets.DungeonManager; import de.hysky.skyblocker.utils.Constants; import de.hysky.skyblocker.utils.Utils; import de.hysky.skyblocker.utils.scheduler.MessageScheduler; -import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents; +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.minecraft.block.Block; import net.minecraft.block.Blocks; import net.minecraft.client.MinecraftClient; +import net.minecraft.entity.effect.StatusEffects; import net.minecraft.registry.Registries; import net.minecraft.text.MutableText; import net.minecraft.util.Formatting; import net.minecraft.util.math.BlockPos; import java.util.Map; -import java.util.Set; public class LividColor { private static final Map<Block, Formatting> WOOL_TO_FORMATTING = Map.of( @@ -42,39 +43,55 @@ public class LividColor { "Doctor Livid", Formatting.GRAY, "Vendetta Livid", Formatting.WHITE ); - public static final Set<String> LIVID_NAMES = Set.copyOf(LIVID_TO_FORMATTING.keySet()); public static final DungeonsConfig.Livid CONFIG = SkyblockerConfigManager.get().dungeons.livid; - private static int tenTicks = 0; - private static Formatting color; + private static Formatting color = Formatting.AQUA; + private static Block lastColor = Blocks.AIR; + + private static boolean isInitialized = false; + /** + * The correct livid may change color in M5, so we use the entity id to track the correct original livid. + */ + private static boolean correctLividIdFound = false; + private static int correctLividId = 0; + private static final long OFFSET_DURATION = 2000; + private static long toggleTime = 0; public static void init() { - ClientReceiveMessageEvents.GAME.register((message, overlay) -> { - DungeonsConfig.Livid config = SkyblockerConfigManager.get().dungeons.livid; - if ((config.enableLividColorText || config.enableLividColorTitle || config.enableLividColorGlow) && message.getString().equals("[BOSS] Livid: I respect you for making it to here, but I'll be your undoing.")) { - tenTicks = 8; - } - }); + ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> LividColor.reset()); + WorldRenderEvents.AFTER_ENTITIES.register(LividColor::update); } - public static void update() { + private static void update(WorldRenderContext context) { + DungeonsConfig.Livid config = SkyblockerConfigManager.get().dungeons.livid; + if (!(config.enableLividColorText || config.enableLividColorTitle || config.enableLividColorGlow || config.enableLividColorBoundingBox)) return; + MinecraftClient client = MinecraftClient.getInstance(); - if (tenTicks != 0) { - DungeonsConfig.Livid config = SkyblockerConfigManager.get().dungeons.livid; - if ((config.enableLividColorText || config.enableLividColorTitle || config.enableLividColorGlow) && Utils.isInDungeons() && client.world != null) { - if (tenTicks == 1) { - onLividColorFound(client, Blocks.RED_WOOL); - return; - } - Block color = client.world.getBlockState(new BlockPos(5, 110, 42)).getBlock(); - if (WOOL_TO_FORMATTING.containsKey(color) && !color.equals(Blocks.RED_WOOL)) { - onLividColorFound(client, color); - return; - } - tenTicks--; - } else { - tenTicks = 0; + + if (!(Utils.isInDungeons() && DungeonManager.isInBoss() && client.player != null && client.world != null)) return; + + Block currentColor = client.world.getBlockState(new BlockPos(5, 110, 42)).getBlock(); + if (!(WOOL_TO_FORMATTING.containsKey(currentColor) && !currentColor.equals(lastColor))) return; + + if (!isInitialized && client.player.hasStatusEffect(StatusEffects.BLINDNESS)) { + toggleTime = System.currentTimeMillis(); + isInitialized = true; + } else if (isInitialized && System.currentTimeMillis() - toggleTime >= OFFSET_DURATION) { + onLividColorFound(client, currentColor); + if (!correctLividIdFound) { + String lividName = LIVID_TO_FORMATTING.entrySet().stream() + .filter(entry -> entry.getValue() == color) + .map(Map.Entry::getKey) + .findFirst() + .orElse("unknown"); + client.world.getPlayers().stream() + .filter(entity -> entity.getName().getString().equals(lividName)) + .findFirst() + .ifPresent(entity -> correctLividId = entity.getId()); + correctLividIdFound = true; } + lastColor = currentColor; } + } private static void onLividColorFound(MinecraftClient client, Block color) { @@ -91,7 +108,6 @@ public class LividColor { client.inGameHud.setDefaultTitleFade(); client.inGameHud.setTitle(message); } - tenTicks = 0; } public static boolean allowGlow() { @@ -102,8 +118,27 @@ public class LividColor { return SkyblockerConfigManager.get().dungeons.livid.enableLividColorGlow && color == LIVID_TO_FORMATTING.get(name); } + public static boolean shouldDrawBoundingBox(String name) { + return SkyblockerConfigManager.get().dungeons.livid.enableLividColorBoundingBox && color == LIVID_TO_FORMATTING.get(name); + } + @SuppressWarnings("DataFlowIssue") public static int getGlowColor(String name) { - return LIVID_TO_FORMATTING.containsKey(name) ? LIVID_TO_FORMATTING.get(name).getColorValue() : Formatting.WHITE.getColorValue(); + if (SkyblockerConfigManager.get().dungeons.livid.enableSolidColor) return Formatting.RED.getColorValue(); + if (LIVID_TO_FORMATTING.containsKey(name)) return LIVID_TO_FORMATTING.get(name).getColorValue(); + return Formatting.WHITE.getColorValue(); + } + + public static int getCorrectLividId() { + return correctLividId; + } + + private static void reset() { + lastColor = Blocks.AIR; + toggleTime = 0; + isInitialized = false; + correctLividIdFound = false; + correctLividId = 0; + color = Formatting.AQUA; } } 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 5aa97dd9..eeb6608f 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 @@ -5,7 +5,6 @@ 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.ColorUtils; import de.hysky.skyblocker.utils.Utils; import de.hysky.skyblocker.utils.render.RenderHelper; @@ -101,7 +100,7 @@ public class SimonSays { Box outline = RenderHelper.getBlockBoundingBox(world, state, buttonPos); float[] colour = buttonsRendered == 0 ? GREEN : YELLOW; - RenderHelper.renderFilled(context, Boxes.getMinVec(outline), Boxes.getLengthVec(outline), colour, 0.5f, true); + RenderHelper.renderFilled(context, outline, colour, 0.5f, true); RenderHelper.renderOutline(context, outline, colour, 5f, true); if (++buttonsRendered == 2) return; diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/ThreeWeirdos.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/ThreeWeirdos.java index 98d32c68..d703acb6 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/ThreeWeirdos.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/ThreeWeirdos.java @@ -8,6 +8,7 @@ import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; import net.fabricmc.fabric.api.event.player.UseBlockCallback; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.world.ClientWorld; import net.minecraft.entity.decoration.ArmorStandEntity; import net.minecraft.text.Text; import net.minecraft.util.ActionResult; @@ -15,7 +16,6 @@ import net.minecraft.util.Formatting; import net.minecraft.util.hit.HitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Box; -import net.minecraft.world.World; import java.util.List; import java.util.regex.Matcher; @@ -25,11 +25,12 @@ public class ThreeWeirdos extends DungeonPuzzle { protected static final Pattern PATTERN = Pattern.compile("^\\[NPC] ([A-Z][a-z]+): (?:The reward is(?: not in my chest!|n't in any of our chests\\.)|My chest (?:doesn't have the reward\\. We are all telling the truth\\.|has the reward and I'm telling the truth!)|At least one of them is lying, and the reward is not in [A-Z][a-z]+'s chest!|Both of them are telling the truth\\. Also, [A-Z][a-z]+ has the reward in their chest!)$"); private static final float[] GREEN_COLOR_COMPONENTS = new float[]{0, 1, 0}; private static BlockPos pos; + static Box boundingBox; private ThreeWeirdos() { super("three-weirdos", "three-chests"); ClientReceiveMessageEvents.GAME.register((message, overlay) -> { - World world = MinecraftClient.getInstance().world; + ClientWorld world = MinecraftClient.getInstance().world; if (overlay || !shouldSolve() || !SkyblockerConfigManager.get().dungeons.puzzleSolvers.solveThreeWeirdos || world == null || !DungeonManager.isCurrentRoomMatched()) return; @SuppressWarnings("DataFlowIssue") @@ -54,7 +55,7 @@ public class ThreeWeirdos extends DungeonPuzzle { new ThreeWeirdos(); } - private void checkForNPC(World world, Room room, BlockPos relative, String name) { + private void checkForNPC(ClientWorld world, Room room, BlockPos relative, String name) { BlockPos npcPos = room.relativeToActual(relative); List<ArmorStandEntity> npcs = world.getEntitiesByClass( ArmorStandEntity.class, @@ -63,6 +64,7 @@ public class ThreeWeirdos extends DungeonPuzzle { ); if (!npcs.isEmpty()) { pos = room.relativeToActual(relative.add(1, 0, 0)); + boundingBox = RenderHelper.getBlockBoundingBox(world, pos); npcs.forEach(entity -> entity.setCustomName(Text.literal(name).formatted(Formatting.GREEN))); } } @@ -72,8 +74,8 @@ public class ThreeWeirdos extends DungeonPuzzle { @Override public void render(WorldRenderContext context) { - if (shouldSolve() && pos != null) { - RenderHelper.renderFilled(context, pos, GREEN_COLOR_COMPONENTS, 0.5f, true); + if (shouldSolve() && boundingBox != null) { + RenderHelper.renderFilled(context, boundingBox, GREEN_COLOR_COMPONENTS, 0.5f, false); } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/TicTacToe.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/TicTacToe.java index 5a497c19..9e9d20f6 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/TicTacToe.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/TicTacToe.java @@ -23,6 +23,7 @@ import java.util.List; public class TicTacToe extends DungeonPuzzle { private static final Logger LOGGER = LoggerFactory.getLogger(TicTacToe.class); private static final float[] RED_COLOR_COMPONENTS = { 1.0F, 0.0F, 0.0F }; + private static final float[] GREEN_COLOR_COMPONENTS = { 0.0F, 1.0F, 0.0F }; @SuppressWarnings("unused") private static final TicTacToe INSTANCE = new TicTacToe(); private static Box nextBestMoveToMake = null; @@ -101,7 +102,7 @@ public class TicTacToe extends DungeonPuzzle { double nextZ = 17 - bestMove.column(); BlockPos nextPos = DungeonManager.getCurrentRoom().relativeToActual(BlockPos.ofFloored(nextX, nextY, nextZ)); - nextBestMoveToMake = new Box(nextPos); + nextBestMoveToMake = RenderHelper.getBlockBoundingBox(client.world, nextPos); } } catch (Exception e) { LOGGER.error("[Skyblocker Tic Tac Toe] Encountered an exception while determining a tic tac toe solution!", e); @@ -112,7 +113,7 @@ public class TicTacToe extends DungeonPuzzle { public void render(WorldRenderContext context) { try { if (SkyblockerConfigManager.get().dungeons.puzzleSolvers.solveTicTacToe && nextBestMoveToMake != null) { - RenderHelper.renderOutline(context, nextBestMoveToMake, RED_COLOR_COMPONENTS, 5, false); + RenderHelper.renderFilled(context, nextBestMoveToMake, GREEN_COLOR_COMPONENTS, 0.5f, false); } } catch (Exception e) { LOGGER.error("[Skyblocker Tic Tac Toe] Encountered an exception while rendering the tic tac toe solution!", e); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/boulder/Boulder.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/boulder/Boulder.java index aef9109f..2b61940b 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/boulder/Boulder.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/boulder/Boulder.java @@ -9,7 +9,6 @@ import de.hysky.skyblocker.utils.render.RenderHelper; import de.hysky.skyblocker.utils.render.title.Title; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; 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; @@ -18,7 +17,6 @@ import net.minecraft.util.Formatting; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Box; import net.minecraft.util.math.Vec3d; -import net.minecraft.world.BlockView; import java.util.Arrays; import java.util.List; @@ -106,7 +104,7 @@ public class Boulder extends DungeonPuzzle { button = checkForButtonBlocksOnLine(client.world, point1, point2); if (button != null) { // If a button is found, calculate its bounding box - boundingBox = getBlockBoundingBox(client.world, button); + boundingBox = RenderHelper.getBlockBoundingBox(client.world, button); break; } } @@ -179,18 +177,6 @@ public class Boulder extends DungeonPuzzle { return null; } - /** - * Retrieves the bounding box of a block in the world. - * - * @param world The client world. - * @param pos The position of the block. - * @return The bounding box of the block. - */ - public static Box getBlockBoundingBox(BlockView world, BlockPos pos) { - BlockState blockState = world.getBlockState(pos); - return blockState.getOutlineShape(world, pos).getBoundingBox().offset(pos); - } - @Override public void render(WorldRenderContext context) { if (!shouldSolve() || !SkyblockerConfigManager.get().dungeons.puzzleSolvers.solveBoulder || !DungeonManager.isCurrentRoomMatched()) |