aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorolim <bobq4582@gmail.com>2024-07-15 16:16:12 +0100
committerolim <bobq4582@gmail.com>2024-08-02 20:31:34 +0100
commitc285e29355b481cd97207ce12e4db1cb30b548a4 (patch)
tree8653725f21e481a56b13bbc6c181f11e9f4128d9 /src/main
parentcaaf749db302da1b4082d14bc545e88496d670cb (diff)
downloadSkyblocker-c285e29355b481cd97207ce12e4db1cb30b548a4.tar.gz
Skyblocker-c285e29355b481cd97207ce12e4db1cb30b548a4.tar.bz2
Skyblocker-c285e29355b481cd97207ce12e4db1cb30b548a4.zip
add counter for total locks picked on a chest
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsChestHighlighter.java55
1 files changed, 41 insertions, 14 deletions
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<BlockPos> activeChests = new ArrayList<>();
private static final Map<Vec3d, Long> 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