From a45227810a73c7b4e79960f4d775d6c91389f43d Mon Sep 17 00:00:00 2001 From: olim Date: Thu, 11 Jul 2024 13:17:28 +0100 Subject: create feature --- .../java/de/hysky/skyblocker/SkyblockerMod.java | 1 + .../config/categories/MiningCategory.java | 27 +++++-- .../skyblocker/config/configs/MiningConfig.java | 8 ++ .../hysky/skyblocker/mixins/ClientWorldMixin.java | 6 +- .../skyblock/dwarven/CrystalsChestHighlighter.java | 88 ++++++++++++++++++++++ .../skyblocker/utils/render/RenderHelper.java | 36 +++++++++ .../resources/assets/skyblocker/lang/en_us.json | 4 + 7 files changed, 163 insertions(+), 7 deletions(-) create mode 100644 src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java (limited to 'src/main') diff --git a/src/main/java/de/hysky/skyblocker/SkyblockerMod.java b/src/main/java/de/hysky/skyblocker/SkyblockerMod.java index b1d25a01..d5b8204f 100644 --- a/src/main/java/de/hysky/skyblocker/SkyblockerMod.java +++ b/src/main/java/de/hysky/skyblocker/SkyblockerMod.java @@ -134,6 +134,7 @@ public class SkyblockerMod implements ClientModInitializer { LowerSensitivity.init(); CrystalsLocationsManager.init(); WishingCompassSolver.init(); + CrystalsChestHighlighter.init(); MetalDetector.init(); ChatMessageListener.init(); Shortcuts.init(); diff --git a/src/main/java/de/hysky/skyblocker/config/categories/MiningCategory.java b/src/main/java/de/hysky/skyblocker/config/categories/MiningCategory.java index 796a6105..74be78cb 100644 --- a/src/main/java/de/hysky/skyblocker/config/categories/MiningCategory.java +++ b/src/main/java/de/hysky/skyblocker/config/categories/MiningCategory.java @@ -4,17 +4,16 @@ import de.hysky.skyblocker.config.ConfigUtils; import de.hysky.skyblocker.config.SkyblockerConfig; import de.hysky.skyblocker.config.configs.MiningConfig; import de.hysky.skyblocker.skyblock.dwarven.CrystalsHudConfigScreen; -import dev.isxander.yacl3.api.ButtonOption; -import dev.isxander.yacl3.api.ConfigCategory; -import dev.isxander.yacl3.api.Option; -import dev.isxander.yacl3.api.OptionDescription; -import dev.isxander.yacl3.api.OptionGroup; import de.hysky.skyblocker.skyblock.dwarven.DwarvenHudConfigScreen; +import dev.isxander.yacl3.api.*; +import dev.isxander.yacl3.api.controller.ColorControllerBuilder; import dev.isxander.yacl3.api.controller.FloatFieldControllerBuilder; import dev.isxander.yacl3.api.controller.IntegerSliderControllerBuilder; import net.minecraft.client.MinecraftClient; import net.minecraft.text.Text; +import java.awt.*; + public class MiningCategory { public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig config) { @@ -111,7 +110,23 @@ public class MiningCategory { newValue -> config.mining.crystalHollows.nucleusWaypoints = newValue) .controller(ConfigUtils::createBooleanController) .build()) - .build()) + .option(Option.createBuilder() + .name(Text.translatable("skyblocker.config.mining.crystalHollows.chestHighlighter")) + .description(OptionDescription.of(Text.translatable("skyblocker.config.mining.crystalHollows.chestHighlighter.@Tooltip"))) + .binding(defaults.mining.crystalHollows.chestHighlighter, + () -> config.mining.crystalHollows.chestHighlighter, + newValue -> config.mining.crystalHollows.chestHighlighter = newValue) + .controller(ConfigUtils::createBooleanController) + .build()) + .option(Option.createBuilder() + .name(Text.translatable("skyblocker.config.mining.crystalHollows.chestHighlighter.color")) + .description(OptionDescription.of(Text.translatable("skyblocker.config.mining.crystalHollows.chestHighlighter.color.@Tooltip"))) + .binding(defaults.mining.crystalHollows.chestHighlightColor, + () -> config.mining.crystalHollows.chestHighlightColor, + newValue -> config.mining.crystalHollows.chestHighlightColor = newValue) + .controller(v -> ColorControllerBuilder.create(v).allowAlpha(true)) + .build()) + .build()) //Crystal Hollows Map .group(OptionGroup.createBuilder() diff --git a/src/main/java/de/hysky/skyblocker/config/configs/MiningConfig.java b/src/main/java/de/hysky/skyblocker/config/configs/MiningConfig.java index dcf70f24..5236f1eb 100644 --- a/src/main/java/de/hysky/skyblocker/config/configs/MiningConfig.java +++ b/src/main/java/de/hysky/skyblocker/config/configs/MiningConfig.java @@ -2,6 +2,8 @@ package de.hysky.skyblocker.config.configs; import dev.isxander.yacl3.config.v2.api.SerialEntry; +import java.awt.*; + public class MiningConfig { @SerialEntry public boolean enableDrillFuel = true; @@ -67,6 +69,12 @@ public class MiningConfig { @SerialEntry public boolean nucleusWaypoints = false; + + @SerialEntry + public boolean chestHighlighter = true; + + @SerialEntry + public Color chestHighlightColor = new Color(0, 0, 255, 128); } public static class CrystalsHud { diff --git a/src/main/java/de/hysky/skyblocker/mixins/ClientWorldMixin.java b/src/main/java/de/hysky/skyblocker/mixins/ClientWorldMixin.java index a2d7887b..fdc199e8 100644 --- a/src/main/java/de/hysky/skyblocker/mixins/ClientWorldMixin.java +++ b/src/main/java/de/hysky/skyblocker/mixins/ClientWorldMixin.java @@ -2,6 +2,7 @@ package de.hysky.skyblocker.mixins; import de.hysky.skyblocker.skyblock.crimson.dojo.DojoManager; import de.hysky.skyblocker.skyblock.dungeon.device.SimonSays; +import de.hysky.skyblocker.skyblock.dwarven.CrystalsChestHighlighter; import de.hysky.skyblocker.utils.Utils; import net.minecraft.block.BlockState; import net.minecraft.client.world.ClientWorld; @@ -25,7 +26,10 @@ public class ClientWorldMixin { if (Utils.isInCrimson()) { DojoManager.onBlockUpdate(pos.toImmutable(), state); } - + else if (Utils.isInCrystalHollows()) { + CrystalsChestHighlighter.onBlockUpdate(pos.toImmutable(), state); + } SimonSays.onBlockUpdate(pos, state); + } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java new file mode 100644 index 00000000..ded2e678 --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java @@ -0,0 +1,88 @@ +package de.hysky.skyblocker.skyblock.dwarven; + +import de.hysky.skyblocker.config.SkyblockerConfigManager; +import de.hysky.skyblocker.utils.Utils; +import de.hysky.skyblocker.utils.render.RenderHelper; +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.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.client.MinecraftClient; +import net.minecraft.text.Text; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Box; + +import java.util.ArrayList; +import java.util.List; + +public class CrystalsChestHighlighter { + + private static final MinecraftClient CLIENT = MinecraftClient.getInstance(); + private static final String CHEST_SPAWN_MESSAGE = "You uncovered a treasure chest!"; + + private static int waitingForChest = 0; + private static final List activeChests = new ArrayList<>(); + + public static void init() { + ClientReceiveMessageEvents.GAME.register(CrystalsChestHighlighter::extractLocationFromMessage); + WorldRenderEvents.AFTER_TRANSLUCENT.register(CrystalsChestHighlighter::render); + ClientPlayConnectionEvents.JOIN.register((_handler, _sender, _client) -> reset()); + } + + private static void reset() { + waitingForChest = 0; + activeChests.clear(); + } + + private static void extractLocationFromMessage(Text text, boolean b) { + if (!Utils.isInCrystalHollows() || !SkyblockerConfigManager.get().mining.crystalHollows.chestHighlighter) { + return; + } + //if a chest is spawned add chest to look for + if (text.getString().matches(CHEST_SPAWN_MESSAGE)) { + waitingForChest += 1; + } + } + + /** + * When a block is updated in the crystal hollows if looking for a chest see if it's a chest and if so add to active. or remove active chests from where air is placed + * + * @param pos location of block update + * @param state the new state of the block + */ + public static void onBlockUpdate(BlockPos pos, BlockState state) { + if (!SkyblockerConfigManager.get().mining.crystalHollows.chestHighlighter || CLIENT.player == null) { + return; + } + if (waitingForChest > 0 && state.isOf(Blocks.CHEST)) { + //make sure it is not too far from the player (more than 10 blocks away) + if (pos.getSquaredDistance(CLIENT.player.getPos()) > 100) { + return; + } + activeChests.add(pos); + waitingForChest -= 1; + } else if (state.isAir()) { + activeChests.remove(pos); + } + + + } + + /** + * Renders a box around active treasure chests if enabled. Taking the color from the config + * + * @param context context + */ + private static void render(WorldRenderContext context) { + if (!Utils.isInCrystalHollows() || !SkyblockerConfigManager.get().mining.crystalHollows.chestHighlighter) { + return; + } + float[] color = SkyblockerConfigManager.get().mining.crystalHollows.chestHighlightColor.getComponents(new float[]{0, 0, 0, 0}); + for (BlockPos chest : activeChests) { + RenderHelper.renderOutline(context, Box.of(chest.toCenterPos().subtract(0, 0.0625, 0), 0.875, 0.875, 0.875), color, color[3], 3, true); + } + + } +} diff --git a/src/main/java/de/hysky/skyblocker/utils/render/RenderHelper.java b/src/main/java/de/hysky/skyblocker/utils/render/RenderHelper.java index 20d8157a..1106dee8 100644 --- a/src/main/java/de/hysky/skyblocker/utils/render/RenderHelper.java +++ b/src/main/java/de/hysky/skyblocker/utils/render/RenderHelper.java @@ -146,6 +146,42 @@ public class RenderHelper { } } + /** + * Renders the outline of a box with the specified color components and line width. + * This does not use renderer since renderer draws outline using debug lines with a fixed width. + * + * @param alpha the transparency of the lines for the box + */ + public static void renderOutline(WorldRenderContext context, Box box, float[] colorComponents, float alpha, float lineWidth, boolean throughWalls) { + if (FrustumUtils.isVisible(box)) { + MatrixStack matrices = context.matrixStack(); + Vec3d camera = context.camera().getPos(); + Tessellator tessellator = RenderSystem.renderThreadTesselator(); + + RenderSystem.setShader(GameRenderer::getRenderTypeLinesProgram); + RenderSystem.setShaderColor(1f, 1f, 1f, 1f); + RenderSystem.enableBlend(); + RenderSystem.lineWidth(lineWidth); + RenderSystem.disableCull(); + RenderSystem.enableDepthTest(); + RenderSystem.depthFunc(throughWalls ? GL11.GL_ALWAYS : GL11.GL_LEQUAL); + + matrices.push(); + matrices.translate(-camera.getX(), -camera.getY(), -camera.getZ()); + + BufferBuilder buffer = tessellator.begin(DrawMode.LINES, VertexFormats.LINES); + WorldRenderer.drawBox(matrices, buffer, box, colorComponents[0], colorComponents[1], colorComponents[2], alpha); + BufferRenderer.drawWithGlobalProgram(buffer.end()); + + matrices.pop(); + RenderSystem.lineWidth(1f); + RenderSystem.enableCull(); + RenderSystem.disableBlend(); + RenderSystem.disableDepthTest(); + RenderSystem.depthFunc(GL11.GL_LEQUAL); + } + } + /** * Draws lines from point to point.

*

diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index 129381a2..6a2a48c0 100644 --- a/src/main/resources/assets/skyblocker/lang/en_us.json +++ b/src/main/resources/assets/skyblocker/lang/en_us.json @@ -481,6 +481,10 @@ "skyblocker.config.mining.crystalHollows.metalDetectorHelper.@Tooltip": "Helper for the metal detector puzzle in the Mines of Divan.", "skyblocker.config.mining.crystalHollows.nucleusWaypoints": "Nucleus Waypoints", "skyblocker.config.mining.crystalHollows.nucleusWaypoints.@Tooltip": "Show waypoints to the Nucleus in the Crystal Hollows.", + "skyblocker.config.mining.crystalHollows.chestHighlighter": "Treasure Chest Highlighter", + "skyblocker.config.mining.crystalHollows.chestHighlighter.@Tooltip": "Highlight found treasure chests when powder mining.", + "skyblocker.config.mining.crystalHollows.chestHighlighter.color": "Chest Highlight Color", + "skyblocker.config.mining.crystalHollows.chestHighlighter.color.@Tooltip": "What color the treasure chests should be highlighted.", "skyblocker.config.mining.crystalsHud": "Crystal Hollows Map", "skyblocker.config.mining.crystalsHud.enabled": "Enabled", -- cgit From e293fafcb0766c6aa59efb880aeaa5dd3be140fd Mon Sep 17 00:00:00 2001 From: olim Date: Thu, 11 Jul 2024 15:13:50 +0100 Subject: remove extra lines --- .../de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/main') diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java index ded2e678..344151d8 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java @@ -66,8 +66,6 @@ public class CrystalsChestHighlighter { } else if (state.isAir()) { activeChests.remove(pos); } - - } /** @@ -83,6 +81,5 @@ public class CrystalsChestHighlighter { for (BlockPos chest : activeChests) { RenderHelper.renderOutline(context, Box.of(chest.toCenterPos().subtract(0, 0.0625, 0), 0.875, 0.875, 0.875), color, color[3], 3, true); } - } } -- cgit From f36e69876d6b96db7f924aeb77683873f28cc556 Mon Sep 17 00:00:00 2001 From: olim Date: Thu, 11 Jul 2024 16:30:58 +0100 Subject: add chest lock picking solver --- .../mixins/ClientPlayNetworkHandlerMixin.java | 4 ++ .../skyblock/dwarven/CrystalsChestHighlighter.java | 58 +++++++++++++++++++++- .../resources/assets/skyblocker/lang/en_us.json | 4 +- 3 files changed, 63 insertions(+), 3 deletions(-) (limited to 'src/main') diff --git a/src/main/java/de/hysky/skyblocker/mixins/ClientPlayNetworkHandlerMixin.java b/src/main/java/de/hysky/skyblocker/mixins/ClientPlayNetworkHandlerMixin.java index c0cd8b7b..2859aa01 100644 --- a/src/main/java/de/hysky/skyblocker/mixins/ClientPlayNetworkHandlerMixin.java +++ b/src/main/java/de/hysky/skyblocker/mixins/ClientPlayNetworkHandlerMixin.java @@ -10,6 +10,7 @@ import de.hysky.skyblocker.skyblock.crimson.dojo.DojoManager; import de.hysky.skyblocker.skyblock.dungeon.DungeonScore; import de.hysky.skyblocker.skyblock.dungeon.secrets.DungeonManager; import de.hysky.skyblocker.skyblock.dwarven.WishingCompassSolver; +import de.hysky.skyblocker.skyblock.dwarven.CrystalsChestHighlighter; import de.hysky.skyblocker.skyblock.end.BeaconHighlighter; import de.hysky.skyblocker.skyblock.end.EnderNodes; import de.hysky.skyblocker.skyblock.end.TheEnd; @@ -24,6 +25,7 @@ import net.minecraft.entity.EntityStatuses; import net.minecraft.entity.ItemEntity; import net.minecraft.entity.decoration.ArmorStandEntity; import net.minecraft.network.packet.s2c.play.*; +import net.minecraft.particle.ParticleTypes; import net.minecraft.util.Identifier; import org.slf4j.Logger; import org.spongepowered.asm.mixin.Final; @@ -79,6 +81,7 @@ public abstract class ClientPlayNetworkHandlerMixin { @Inject(method = "onPlaySound", at = @At("RETURN")) private void skyblocker$onPlaySound(PlaySoundS2CPacket packet, CallbackInfo ci) { FishingHelper.onSound(packet); + CrystalsChestHighlighter.onSound(packet); } @WrapWithCondition(method = "warnOnUnknownPayload", at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;warn(Ljava/lang/String;Ljava/lang/Object;)V", remap = false)) @@ -100,6 +103,7 @@ public abstract class ClientPlayNetworkHandlerMixin { private void skyblocker$onParticle(ParticleS2CPacket packet, CallbackInfo ci) { MythologicalRitual.onParticle(packet); DojoManager.onParticle(packet); + CrystalsChestHighlighter.onParticle(packet); EnderNodes.onParticle(packet); WishingCompassSolver.onParticle(packet); } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java index 344151d8..93e33d1b 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java @@ -10,20 +10,31 @@ import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.client.MinecraftClient; +import net.minecraft.network.packet.s2c.play.ParticleS2CPacket; +import net.minecraft.network.packet.s2c.play.PlaySoundS2CPacket; +import net.minecraft.particle.ParticleTypes; import net.minecraft.text.Text; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.hit.HitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Box; +import net.minecraft.util.math.Vec3d; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class CrystalsChestHighlighter { private static final MinecraftClient CLIENT = MinecraftClient.getInstance(); private static final String CHEST_SPAWN_MESSAGE = "You uncovered a treasure chest!"; + private static final long MAX_PARTICLE_LIFE_TIME = 500; + private static final Vec3d LOCK_HIGHLIGHT_SIZE = new Vec3d(0.1, 0.1, 0.1); private static int waitingForChest = 0; private static final List activeChests = new ArrayList<>(); + private static final Map activeParticles = new HashMap<>(); public static void init() { ClientReceiveMessageEvents.GAME.register(CrystalsChestHighlighter::extractLocationFromMessage); @@ -34,6 +45,7 @@ public class CrystalsChestHighlighter { private static void reset() { waitingForChest = 0; activeChests.clear(); + activeParticles.clear(); } private static void extractLocationFromMessage(Text text, boolean b) { @@ -68,8 +80,30 @@ public class CrystalsChestHighlighter { } } + public static void onParticle(ParticleS2CPacket packet) { + if (!Utils.isInCrystalHollows() || !SkyblockerConfigManager.get().mining.crystalHollows.chestHighlighter) { + return; + } + if (ParticleTypes.CRIT.equals(packet.getParameters().getType())) { + activeParticles.put(new Vec3d(packet.getX(), packet.getY(), packet.getZ()), System.currentTimeMillis()); + } + } + /** - * Renders a box around active treasure chests if enabled. Taking the color from the config + * When sound is created to tell the user that they have done a stage of picking remove all old particles + * + * @param packet sound packet + */ + public static void onSound(PlaySoundS2CPacket packet) { + String path = packet.getSound().value().getId().getPath(); + if (path.equals("entity.experience_orb.pickup") || path.equals("entity.villager.no")) { + activeParticles.clear(); + } + } + + + /** + * Renders a box around active treasure chests if enabled. Taking the color from the config. Also displaces highlight to where to lock pick chests * * @param context context */ @@ -77,9 +111,31 @@ public class CrystalsChestHighlighter { if (!Utils.isInCrystalHollows() || !SkyblockerConfigManager.get().mining.crystalHollows.chestHighlighter) { return; } + //render chest outline float[] color = SkyblockerConfigManager.get().mining.crystalHollows.chestHighlightColor.getComponents(new float[]{0, 0, 0, 0}); for (BlockPos chest : activeChests) { RenderHelper.renderOutline(context, Box.of(chest.toCenterPos().subtract(0, 0.0625, 0), 0.875, 0.875, 0.875), color, color[3], 3, true); } + + //render lock picking if player is looking at chest that is in the active chests list + if (CLIENT.player == null || activeParticles.isEmpty()) { + return; + } + HitResult target = CLIENT.crosshairTarget; + if (target instanceof BlockHitResult blockHitResult && activeChests.contains(blockHitResult.getBlockPos())) { + //the player is looking at a chest use active particle to highlight correct spot + Vec3d highlightSpot = Vec3d.ZERO; + //if to old remove particle + activeParticles.entrySet().removeIf(e -> System.currentTimeMillis() - e.getValue() > MAX_PARTICLE_LIFE_TIME); + //add up all particle within range of active block + for (Vec3d particlePos : activeParticles.keySet()) { + if (particlePos.squaredDistanceTo(blockHitResult.getBlockPos().toCenterPos()) <= 0.75) { + highlightSpot = highlightSpot.add(particlePos); + } + + } + highlightSpot = highlightSpot.multiply((double) 1 / activeParticles.size()).subtract(LOCK_HIGHLIGHT_SIZE.multiply(0.5)); + RenderHelper.renderFilled(context, highlightSpot, LOCK_HIGHLIGHT_SIZE, color, color[3], true); + } } } diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index 6a2a48c0..1d174c09 100644 --- a/src/main/resources/assets/skyblocker/lang/en_us.json +++ b/src/main/resources/assets/skyblocker/lang/en_us.json @@ -482,9 +482,9 @@ "skyblocker.config.mining.crystalHollows.nucleusWaypoints": "Nucleus Waypoints", "skyblocker.config.mining.crystalHollows.nucleusWaypoints.@Tooltip": "Show waypoints to the Nucleus in the Crystal Hollows.", "skyblocker.config.mining.crystalHollows.chestHighlighter": "Treasure Chest Highlighter", - "skyblocker.config.mining.crystalHollows.chestHighlighter.@Tooltip": "Highlight found treasure chests when powder mining.", + "skyblocker.config.mining.crystalHollows.chestHighlighter.@Tooltip": "Highlight found treasure chests and lock pick locations when powder mining.", "skyblocker.config.mining.crystalHollows.chestHighlighter.color": "Chest Highlight Color", - "skyblocker.config.mining.crystalHollows.chestHighlighter.color.@Tooltip": "What color the treasure chests should be highlighted.", + "skyblocker.config.mining.crystalHollows.chestHighlighter.color.@Tooltip": "What color the treasure chests / lock pick should be highlighted.", "skyblocker.config.mining.crystalsHud": "Crystal Hollows Map", "skyblocker.config.mining.crystalsHud.enabled": "Enabled", -- cgit From caaf749db302da1b4082d14bc545e88496d670cb Mon Sep 17 00:00:00 2001 From: olim Date: Mon, 15 Jul 2024 15:33:06 +0100 Subject: improve formatting and decrease particle life time --- .../skyblocker/mixins/ClientPlayNetworkHandlerMixin.java | 1 - .../skyblock/dwarven/CrystalsChestHighlighter.java | 15 +++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'src/main') diff --git a/src/main/java/de/hysky/skyblocker/mixins/ClientPlayNetworkHandlerMixin.java b/src/main/java/de/hysky/skyblocker/mixins/ClientPlayNetworkHandlerMixin.java index 2859aa01..4e263015 100644 --- a/src/main/java/de/hysky/skyblocker/mixins/ClientPlayNetworkHandlerMixin.java +++ b/src/main/java/de/hysky/skyblocker/mixins/ClientPlayNetworkHandlerMixin.java @@ -25,7 +25,6 @@ import net.minecraft.entity.EntityStatuses; import net.minecraft.entity.ItemEntity; import net.minecraft.entity.decoration.ArmorStandEntity; import net.minecraft.network.packet.s2c.play.*; -import net.minecraft.particle.ParticleTypes; import net.minecraft.util.Identifier; import org.slf4j.Logger; import org.spongepowered.asm.mixin.Final; diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java index 93e33d1b..cd7b936e 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java @@ -29,7 +29,7 @@ public class CrystalsChestHighlighter { private static final MinecraftClient CLIENT = MinecraftClient.getInstance(); private static final String CHEST_SPAWN_MESSAGE = "You uncovered a treasure chest!"; - private static final long MAX_PARTICLE_LIFE_TIME = 500; + private static final long MAX_PARTICLE_LIFE_TIME = 250; private static final Vec3d LOCK_HIGHLIGHT_SIZE = new Vec3d(0.1, 0.1, 0.1); private static int waitingForChest = 0; @@ -80,6 +80,10 @@ public class CrystalsChestHighlighter { } } + /** + * When a particle is spawned add that particle to active particles + * @param packet particle spawn packet + */ public static void onParticle(ParticleS2CPacket packet) { if (!Utils.isInCrystalHollows() || !SkyblockerConfigManager.get().mining.crystalHollows.chestHighlighter) { return; @@ -103,7 +107,7 @@ public class CrystalsChestHighlighter { /** - * Renders a box around active treasure chests if enabled. Taking the color from the config. Also displaces highlight to where to lock pick chests + * If enabled, renders a box around active treasure chests, taking the color from the config. Additionally, calculates and displaces the highlight to indicate lock-picking spots on chests. * * @param context context */ @@ -125,17 +129,20 @@ public class CrystalsChestHighlighter { if (target instanceof BlockHitResult blockHitResult && activeChests.contains(blockHitResult.getBlockPos())) { //the player is looking at a chest use active particle to highlight correct spot Vec3d highlightSpot = Vec3d.ZERO; + //if to old remove particle activeParticles.entrySet().removeIf(e -> System.currentTimeMillis() - e.getValue() > MAX_PARTICLE_LIFE_TIME); + //add up all particle within range of active block for (Vec3d particlePos : activeParticles.keySet()) { if (particlePos.squaredDistanceTo(blockHitResult.getBlockPos().toCenterPos()) <= 0.75) { highlightSpot = highlightSpot.add(particlePos); } - } + + //render the spot highlightSpot = highlightSpot.multiply((double) 1 / activeParticles.size()).subtract(LOCK_HIGHLIGHT_SIZE.multiply(0.5)); RenderHelper.renderFilled(context, highlightSpot, LOCK_HIGHLIGHT_SIZE, color, color[3], true); } } -} +} \ No newline at end of file -- cgit From c285e29355b481cd97207ce12e4db1cb30b548a4 Mon Sep 17 00:00:00 2001 From: olim Date: Mon, 15 Jul 2024 16:16:12 +0100 Subject: add counter for total locks picked on a chest --- .../skyblock/dwarven/CrystalsChestHighlighter.java | 55 ++++++++++++++++------ 1 file changed, 41 insertions(+), 14 deletions(-) (limited to 'src/main') diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java index cd7b936e..ea8bf0a8 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java @@ -14,6 +14,7 @@ import net.minecraft.network.packet.s2c.play.ParticleS2CPacket; import net.minecraft.network.packet.s2c.play.PlaySoundS2CPacket; import net.minecraft.particle.ParticleTypes; import net.minecraft.text.Text; +import net.minecraft.util.Formatting; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.HitResult; import net.minecraft.util.math.BlockPos; @@ -35,6 +36,8 @@ public class CrystalsChestHighlighter { private static int waitingForChest = 0; private static final List activeChests = new ArrayList<>(); private static final Map activeParticles = new HashMap<>(); + private static int currentLockCount = 0; + private static int neededLockCount = 0; public static void init() { ClientReceiveMessageEvents.GAME.register(CrystalsChestHighlighter::extractLocationFromMessage); @@ -46,6 +49,7 @@ public class CrystalsChestHighlighter { waitingForChest = 0; activeChests.clear(); activeParticles.clear(); + currentLockCount = 0; } private static void extractLocationFromMessage(Text text, boolean b) { @@ -74,6 +78,7 @@ public class CrystalsChestHighlighter { return; } activeChests.add(pos); + currentLockCount = 0; waitingForChest -= 1; } else if (state.isAir()) { activeChests.remove(pos); @@ -82,6 +87,7 @@ public class CrystalsChestHighlighter { /** * When a particle is spawned add that particle to active particles + * * @param packet particle spawn packet */ public static void onParticle(ParticleS2CPacket packet) { @@ -100,14 +106,25 @@ public class CrystalsChestHighlighter { */ public static void onSound(PlaySoundS2CPacket packet) { String path = packet.getSound().value().getId().getPath(); - if (path.equals("entity.experience_orb.pickup") || path.equals("entity.villager.no")) { + if (path.equals("entity.experience_orb.pickup") && packet.getPitch() == 1) { + currentLockCount += 1; + activeParticles.clear(); + } else if (path.equals("entity.villager.no")) { + currentLockCount = 0; + activeParticles.clear(); + } else if (path.equals("block.chest.open")) { + //set the needed lock count to the current, so we know how many locks a chest has + neededLockCount = currentLockCount; activeParticles.clear(); } + } /** - * If enabled, renders a box around active treasure chests, taking the color from the config. Additionally, calculates and displaces the highlight to indicate lock-picking spots on chests. + * If enabled, renders a box around active treasure chests, taking the color from the config. + * Additionally, calculates and displaces the highlight to indicate lock-picking spots on chests. + * Finally, renders text showing how many lock picks the player has done * * @param context context */ @@ -122,27 +139,37 @@ public class CrystalsChestHighlighter { } //render lock picking if player is looking at chest that is in the active chests list - if (CLIENT.player == null || activeParticles.isEmpty()) { + if (CLIENT.player == null) { return; } HitResult target = CLIENT.crosshairTarget; if (target instanceof BlockHitResult blockHitResult && activeChests.contains(blockHitResult.getBlockPos())) { - //the player is looking at a chest use active particle to highlight correct spot - Vec3d highlightSpot = Vec3d.ZERO; + Vec3d chestPos = blockHitResult.getBlockPos().toCenterPos(); - //if to old remove particle - activeParticles.entrySet().removeIf(e -> System.currentTimeMillis() - e.getValue() > MAX_PARTICLE_LIFE_TIME); + if (!activeParticles.isEmpty()) { + //the player is looking at a chest use active particle to highlight correct spot + Vec3d highlightSpot = Vec3d.ZERO; - //add up all particle within range of active block - for (Vec3d particlePos : activeParticles.keySet()) { - if (particlePos.squaredDistanceTo(blockHitResult.getBlockPos().toCenterPos()) <= 0.75) { - highlightSpot = highlightSpot.add(particlePos); + //if to old remove particle + activeParticles.entrySet().removeIf(e -> System.currentTimeMillis() - e.getValue() > MAX_PARTICLE_LIFE_TIME); + + //add up all particle within range of active block + for (Vec3d particlePos : activeParticles.keySet()) { + if (particlePos.squaredDistanceTo(chestPos) <= 0.75) { + highlightSpot = highlightSpot.add(particlePos); + } } + + //render the spot + highlightSpot = highlightSpot.multiply((double) 1 / activeParticles.size()).subtract(LOCK_HIGHLIGHT_SIZE.multiply(0.5)); + RenderHelper.renderFilled(context, highlightSpot, LOCK_HIGHLIGHT_SIZE, color, color[3], true); } - //render the spot - highlightSpot = highlightSpot.multiply((double) 1 / activeParticles.size()).subtract(LOCK_HIGHLIGHT_SIZE.multiply(0.5)); - RenderHelper.renderFilled(context, highlightSpot, LOCK_HIGHLIGHT_SIZE, color, color[3], true); + //render total text if needed is more than 0 + if (neededLockCount <= 0) { + return; + } + RenderHelper.renderText(context, Text.literal(Math.min(currentLockCount, neededLockCount) + "/" + neededLockCount).withColor(SkyblockerConfigManager.get().mining.crystalHollows.chestHighlightColor.getRGB()), chestPos, true); } } } \ No newline at end of file -- cgit From aa242a88b0111431aeec79bf2dc5c856a66dc805 Mon Sep 17 00:00:00 2001 From: olim Date: Mon, 15 Jul 2024 16:31:10 +0100 Subject: fix counting with multiple chests --- .../hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/main') diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java index ea8bf0a8..1103008f 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java @@ -80,8 +80,9 @@ public class CrystalsChestHighlighter { activeChests.add(pos); currentLockCount = 0; waitingForChest -= 1; - } else if (state.isAir()) { - activeChests.remove(pos); + } else if (state.isAir() && activeChests.contains(pos)) { + currentLockCount = 0; + activeChests.remove(pos); } } @@ -117,7 +118,6 @@ public class CrystalsChestHighlighter { neededLockCount = currentLockCount; activeParticles.clear(); } - } -- cgit From e53e56c18788a02c1f99c226ec5905ce1958325c Mon Sep 17 00:00:00 2001 From: olim Date: Mon, 15 Jul 2024 19:45:19 +0100 Subject: clean code --- .../skyblock/dwarven/CrystalsChestHighlighter.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/main') diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java index 1103008f..8cd75428 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java @@ -14,7 +14,6 @@ import net.minecraft.network.packet.s2c.play.ParticleS2CPacket; import net.minecraft.network.packet.s2c.play.PlaySoundS2CPacket; import net.minecraft.particle.ParticleTypes; import net.minecraft.text.Text; -import net.minecraft.util.Formatting; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.HitResult; import net.minecraft.util.math.BlockPos; @@ -82,12 +81,12 @@ public class CrystalsChestHighlighter { waitingForChest -= 1; } else if (state.isAir() && activeChests.contains(pos)) { currentLockCount = 0; - activeChests.remove(pos); + activeChests.remove(pos); } } /** - * When a particle is spawned add that particle to active particles + * When a particle is spawned add that particle to active particles if correct for lock picking * * @param packet particle spawn packet */ @@ -101,18 +100,24 @@ public class CrystalsChestHighlighter { } /** - * When sound is created to tell the user that they have done a stage of picking remove all old particles + * Updates {@link CrystalsChestHighlighter#currentLockCount} and clears {@link CrystalsChestHighlighter#activeParticles} based on lock pick related sound events. * * @param packet sound packet */ public static void onSound(PlaySoundS2CPacket packet) { + if (!Utils.isInCrystalHollows() || !SkyblockerConfigManager.get().mining.crystalHollows.chestHighlighter) { + return; + } String path = packet.getSound().value().getId().getPath(); + //lock picked sound if (path.equals("entity.experience_orb.pickup") && packet.getPitch() == 1) { currentLockCount += 1; activeParticles.clear(); + //lock pick fail sound } else if (path.equals("entity.villager.no")) { currentLockCount = 0; activeParticles.clear(); + //lock pick finish sound } else if (path.equals("block.chest.open")) { //set the needed lock count to the current, so we know how many locks a chest has neededLockCount = currentLockCount; @@ -120,7 +125,6 @@ public class CrystalsChestHighlighter { } } - /** * If enabled, renders a box around active treasure chests, taking the color from the config. * Additionally, calculates and displaces the highlight to indicate lock-picking spots on chests. -- cgit From d449cccd170dd53a4b85df9c20fd7b36c3a24c9c Mon Sep 17 00:00:00 2001 From: olim Date: Thu, 18 Jul 2024 12:35:00 +0100 Subject: requested changes --- .../skyblock/dwarven/CrystalsChestHighlighter.java | 9 ++++---- .../skyblocker/utils/render/RenderHelper.java | 26 +--------------------- 2 files changed, 5 insertions(+), 30 deletions(-) (limited to 'src/main') diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java index 8cd75428..cd51daa5 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java @@ -3,6 +3,7 @@ package de.hysky.skyblocker.skyblock.dwarven; import de.hysky.skyblocker.config.SkyblockerConfigManager; import de.hysky.skyblocker.utils.Utils; import de.hysky.skyblocker.utils.render.RenderHelper; +import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap; 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; @@ -21,9 +22,7 @@ import net.minecraft.util.math.Box; import net.minecraft.util.math.Vec3d; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; public class CrystalsChestHighlighter { @@ -34,7 +33,7 @@ public class CrystalsChestHighlighter { private static int waitingForChest = 0; private static final List activeChests = new ArrayList<>(); - private static final Map activeParticles = new HashMap<>(); + private static final Object2LongOpenHashMap activeParticles = new Object2LongOpenHashMap<>(); private static int currentLockCount = 0; private static int neededLockCount = 0; @@ -113,11 +112,11 @@ public class CrystalsChestHighlighter { if (path.equals("entity.experience_orb.pickup") && packet.getPitch() == 1) { currentLockCount += 1; activeParticles.clear(); - //lock pick fail sound + //lock pick fail sound } else if (path.equals("entity.villager.no")) { currentLockCount = 0; activeParticles.clear(); - //lock pick finish sound + //lock pick finish sound } else if (path.equals("block.chest.open")) { //set the needed lock count to the current, so we know how many locks a chest has neededLockCount = currentLockCount; diff --git a/src/main/java/de/hysky/skyblocker/utils/render/RenderHelper.java b/src/main/java/de/hysky/skyblocker/utils/render/RenderHelper.java index 1106dee8..ad5811f1 100644 --- a/src/main/java/de/hysky/skyblocker/utils/render/RenderHelper.java +++ b/src/main/java/de/hysky/skyblocker/utils/render/RenderHelper.java @@ -119,31 +119,7 @@ public class RenderHelper { * This does not use renderer since renderer draws outline using debug lines with a fixed width. */ public static void renderOutline(WorldRenderContext context, Box box, float[] colorComponents, float lineWidth, boolean throughWalls) { - if (FrustumUtils.isVisible(box)) { - MatrixStack matrices = context.matrixStack(); - Vec3d camera = context.camera().getPos(); - Tessellator tessellator = RenderSystem.renderThreadTesselator(); - - RenderSystem.setShader(GameRenderer::getRenderTypeLinesProgram); - RenderSystem.setShaderColor(1f, 1f, 1f, 1f); - RenderSystem.lineWidth(lineWidth); - RenderSystem.disableCull(); - RenderSystem.enableDepthTest(); - RenderSystem.depthFunc(throughWalls ? GL11.GL_ALWAYS : GL11.GL_LEQUAL); - - matrices.push(); - matrices.translate(-camera.getX(), -camera.getY(), -camera.getZ()); - - BufferBuilder buffer = tessellator.begin(DrawMode.LINES, VertexFormats.LINES); - WorldRenderer.drawBox(matrices, buffer, box, colorComponents[0], colorComponents[1], colorComponents[2], 1f); - BufferRenderer.drawWithGlobalProgram(buffer.end()); - - matrices.pop(); - RenderSystem.lineWidth(1f); - RenderSystem.enableCull(); - RenderSystem.disableDepthTest(); - RenderSystem.depthFunc(GL11.GL_LEQUAL); - } + renderOutline(context, box, colorComponents, 1f, lineWidth, throughWalls); } /** -- cgit From 408992b63206d68f9e7f9c0a2ed044f8694887a8 Mon Sep 17 00:00:00 2001 From: olim Date: Fri, 2 Aug 2024 20:46:54 +0100 Subject: stop being esp oops --- .../de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java index cd51daa5..f315ea93 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java @@ -138,7 +138,7 @@ public class CrystalsChestHighlighter { //render chest outline float[] color = SkyblockerConfigManager.get().mining.crystalHollows.chestHighlightColor.getComponents(new float[]{0, 0, 0, 0}); for (BlockPos chest : activeChests) { - RenderHelper.renderOutline(context, Box.of(chest.toCenterPos().subtract(0, 0.0625, 0), 0.875, 0.875, 0.875), color, color[3], 3, true); + RenderHelper.renderOutline(context, Box.of(chest.toCenterPos().subtract(0, 0.0625, 0), 0.875, 0.875, 0.875), color, color[3], 3, false); } //render lock picking if player is looking at chest that is in the active chests list -- cgit From 20370896eaacb73d8c26a3a88575fc7bd58aff94 Mon Sep 17 00:00:00 2001 From: olim Date: Fri, 2 Aug 2024 20:50:29 +0100 Subject: fix esp fix the chest it self was getting in the way of rendering the outline of the chest. so make bounding box slightly bigger --- .../de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java index f315ea93..85d17e5f 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java @@ -138,7 +138,7 @@ public class CrystalsChestHighlighter { //render chest outline float[] color = SkyblockerConfigManager.get().mining.crystalHollows.chestHighlightColor.getComponents(new float[]{0, 0, 0, 0}); for (BlockPos chest : activeChests) { - RenderHelper.renderOutline(context, Box.of(chest.toCenterPos().subtract(0, 0.0625, 0), 0.875, 0.875, 0.875), color, color[3], 3, false); + RenderHelper.renderOutline(context, Box.of(chest.toCenterPos().subtract(0, 0.0625, 0), 0.885, 0.885, 0.885), color, color[3], 3, false); } //render lock picking if player is looking at chest that is in the active chests list -- cgit