diff --git a/src/main/java/dev/stardust/modules/SignHistorian.java b/src/main/java/dev/stardust/modules/SignHistorian.java index c37982b..5cdcd9f 100644 --- a/src/main/java/dev/stardust/modules/SignHistorian.java +++ b/src/main/java/dev/stardust/modules/SignHistorian.java @@ -98,6 +98,14 @@ public SignHistorian() { .build() ); + private final Setting dynamicColor = sgESP.add( + new BoolSetting.Builder() + .name("Dynamic Color") + .description("Derive ESP side color from the sign's wood type.") + .defaultValue(true) + .build() + ); + private final Setting destroyedSettings = sgESP.add( new GenericSetting.Builder() .name("Destroyed/Missing Signs ESP") @@ -106,7 +114,7 @@ public SignHistorian() { new ESPBlockData( ShapeMode.Both, new SettingColor(255, 42, 0, 255), - new SettingColor(255, 42, 0, 44), + new SettingColor(255, 42, 0, 69), true, new SettingColor(255, 42, 0, 137) ) @@ -263,6 +271,7 @@ public SignHistorian() { private final HashSet signsToGlowInk = new HashSet<>(); private final HashMap trackedGriefers = new HashMap<>(); private final HashSet approachingGriefers = new HashSet<>(); + private final HashMap woodTypeMap = new HashMap<>(); private final HashMap signsToColor = new HashMap<>(); private final HashMap> grieferHadLineOfSight = new HashMap<>(); private final Map> serverSigns = new HashMap<>(); @@ -326,6 +335,9 @@ private void readSignsFromFile(Path signsFile) { if (be instanceof SignBlockEntity sbeReconstructed) { if (!serverSigns.containsKey(bPos)) { + if (state.getBlock() instanceof AbstractSignBlock signBlock) { + woodTypeMap.put(sbeReconstructed, signBlock.getWoodType()); + } serverSigns.put(bPos, new Pair<>(sbeReconstructed, sbeReconstructed.getCachedState())); } } @@ -426,6 +438,34 @@ private Vec3d getTracerOffset(BlockPos pos, BlockState state) { return new Vec3d(offsetX, offsetY, offsetZ); } + private SettingColor colorFromWoodType(@Nullable WoodType type) { + if (type == null || !dynamicColor.get()) { + return dangerESP.get().sideColor; + } else if (type == WoodType.OAK) { + return new SettingColor(181, 146, 94, dangerESP.get().sideColor.a); + } else if (type == WoodType.BIRCH) { + return new SettingColor(212, 200, 139, dangerESP.get().sideColor.a); + } else if (type == WoodType.SPRUCE) { + return new SettingColor(126, 93, 53, dangerESP.get().sideColor.a); + } else if (type == WoodType.JUNGLE) { + return new SettingColor(181, 133, 98, dangerESP.get().sideColor.a); + } else if (type == WoodType.ACACIA) { + return new SettingColor(170, 92, 49, dangerESP.get().sideColor.a); + } else if (type == WoodType.BAMBOO) { + return new SettingColor(133, 124, 53, dangerESP.get().sideColor.a); + } else if (type == WoodType.CHERRY) { + return new SettingColor(227, 191, 184, dangerESP.get().sideColor.a); + } else if (type == WoodType.WARPED) { + return new SettingColor(57, 140, 138, dangerESP.get().sideColor.a); + } else if (type == WoodType.CRIMSON) { + return new SettingColor(124, 57, 85, dangerESP.get().sideColor.a); + } else if (type == WoodType.MANGROVE) { + return new SettingColor(109, 41, 44, dangerESP.get().sideColor.a); + } else if (type == WoodType.DARK_OAK) { + return new SettingColor(72, 46, 23, dangerESP.get().sideColor.a); + } else return dangerESP.get().sideColor; + } + @Nullable private BlockPos getTargetedSign() { ClientPlayerEntity player = mc.player; @@ -532,6 +572,61 @@ private boolean hasNearbySigns() { return false; } + private boolean mobHasLineOfSight(HostileEntity mob) { + Vec3d mobEyePos = mob.getEyePos(); + Vec3d eyePos = mc.player.getEyePos(); + HitResult lineOfSightCheck = mc.world.raycast( + new RaycastContext( + mobEyePos, eyePos, + RaycastContext.ShapeType.COLLIDER, + RaycastContext.FluidHandling.WATER, mob + ) + ); + + return lineOfSightCheck.getType() != HitResult.Type.BLOCK; + } + + private boolean isMobAThreat(HostileEntity mob) { + if (!Utils.canUpdate()) return false; + + Vec3d newPos = mob.getPos(); + Vec3d playerPos = mc.player.getPos(); + Vec3d lastPos = trackedGriefers.get(mob.getId()); + + if (lastPos == null) return false; + double newDistance = playerPos.squaredDistanceTo(newPos); + double oldDistance = playerPos.squaredDistanceTo(lastPos); + + long now = System.currentTimeMillis(); + boolean mobHasLoS = mobHasLineOfSight(mob); + if (grieferHadLineOfSight.get(mob.getId()) == null) { + grieferHadLineOfSight.put(mob.getId(), new Pair<>(mobHasLoS, now)); + } else { + Pair prevLoSCheck = grieferHadLineOfSight.get(mob.getId()); + if (mobHasLoS || now - prevLoSCheck.getRight() >= 7000) { + grieferHadLineOfSight.put(mob.getId(), new Pair<>(mobHasLoS, now)); + } + } + + if (mob instanceof CreeperEntity creeper) { + if (newDistance <= MathHelper.square(10)) { + return mobHasLoS || (newDistance < oldDistance && grieferHadLineOfSight.get(creeper.getId()).getLeft()); + } else if (newDistance <= MathHelper.square(20)) { + return (newDistance < oldDistance && mobHasLoS); + } + } else if (mob instanceof WitherEntity wither) { + if (newDistance <= MathHelper.square(16)) { + return true; + } else if (newDistance <= MathHelper.square(32)) { + return mobHasLoS || (newDistance < oldDistance && grieferHadLineOfSight.get(wither.getId()).getLeft()); + } else if (newDistance <= MathHelper.square(48)) { + return (newDistance < oldDistance && mobHasLoS); + } + } + + return false; + } + private void processSign(@NotNull SignBlockEntity sbe) { if (!sbe.getFrontText().hasText(mc.player) && !sbe.getBackText().hasText(mc.player)) return; else if (contentBlacklist.get() && containsBlacklistedText(sbe)) return; @@ -545,6 +640,9 @@ private void processSign(@NotNull SignBlockEntity sbe) { } destroyedSigns.remove(serverSigns.get(pos).getLeft()); } else { + if (sbe.getCachedState().getBlock() instanceof AbstractSignBlock signBlock) { + woodTypeMap.put(sbe, signBlock.getWoodType()); + } serverSigns.put(pos, new Pair<>(sbe, sbe.getCachedState())); if (persistenceSetting.get()) { saveSignToFile(sbe, sbe.getCachedState()); @@ -593,61 +691,6 @@ private void interactSign(SignBlockEntity sbe, Item dye) { } } - private boolean mobHasLineOfSight(HostileEntity mob) { - Vec3d mobEyePos = mob.getEyePos(); - Vec3d eyePos = mc.player.getEyePos(); - HitResult lineOfSightCheck = mc.world.raycast( - new RaycastContext( - mobEyePos, eyePos, - RaycastContext.ShapeType.COLLIDER, - RaycastContext.FluidHandling.WATER, mob - ) - ); - - return lineOfSightCheck.getType() != HitResult.Type.BLOCK; - } - - private boolean isMobAThreat(HostileEntity mob) { - if (!Utils.canUpdate()) return false; - - Vec3d newPos = mob.getPos(); - Vec3d playerPos = mc.player.getPos(); - Vec3d lastPos = trackedGriefers.get(mob.getId()); - - if (lastPos == null) return false; - double newDistance = playerPos.squaredDistanceTo(newPos); - double oldDistance = playerPos.squaredDistanceTo(lastPos); - - long now = System.currentTimeMillis(); - boolean mobHasLoS = mobHasLineOfSight(mob); - if (grieferHadLineOfSight.get(mob.getId()) == null) { - grieferHadLineOfSight.put(mob.getId(), new Pair<>(mobHasLoS, now)); - } else { - Pair prevLoSCheck = grieferHadLineOfSight.get(mob.getId()); - if (mobHasLoS || now - prevLoSCheck.getRight() >= 7000) { - grieferHadLineOfSight.put(mob.getId(), new Pair<>(mobHasLoS, now)); - } - } - - if (mob instanceof CreeperEntity creeper) { - if (newDistance <= MathHelper.square(10)) { - return mobHasLoS || (newDistance < oldDistance && grieferHadLineOfSight.get(creeper.getId()).getLeft()); - } else if (newDistance <= MathHelper.square(20)) { - return (newDistance < oldDistance && mobHasLoS); - } - } else if (mob instanceof WitherEntity wither) { - if (newDistance <= MathHelper.square(16)) { - return true; - } else if (newDistance <= MathHelper.square(32)) { - return mobHasLoS || (newDistance < oldDistance && grieferHadLineOfSight.get(wither.getId()).getLeft()); - } else if (newDistance <= MathHelper.square(48)) { - return (newDistance < oldDistance && mobHasLoS); - } - } - - return false; - } - @Override public void onActivate() { if (!Utils.canUpdate()) { @@ -665,6 +708,7 @@ public void onDeactivate() { gracePeriod = 0; currentDim = null; signsToWax.clear(); + woodTypeMap.clear(); serverSigns.clear(); signsToColor.clear(); modifiedSigns.clear(); @@ -886,7 +930,7 @@ else if (targeted == null) { @EventHandler private void onRender3D(Render3DEvent event) { if (!Utils.canUpdate()) return; - // if (mc.getNetworkHandler().getPlayerList().size() <= 1) return; // ignore queue TODO: disabled for testing, re-enable this before committing + if (mc.getNetworkHandler().getPlayerList().size() <= 1) return; // ignore queue if (espSigns.get()) { ESPBlockData mESP = modifiedSettings.get(); @@ -906,10 +950,11 @@ private void onRender3D(Render3DEvent event) { double z2 = sign.getPos().getZ() + shape.getMax(Direction.Axis.Z); if (dESP.sideColor.a > 0 || dESP.lineColor.a > 0) { + WoodType woodType = woodTypeMap.get(sign); event.renderer.box( x1, y1, z1, x2, y2, z2, - dESP.sideColor, dESP.lineColor, - ShapeMode.Both, 0 + colorFromWoodType(woodType), dESP.lineColor, + dESP.shapeMode, 0 ); } @@ -936,10 +981,11 @@ private void onRender3D(Render3DEvent event) { double z2 = sign.getPos().getZ() + shape.getMax(Direction.Axis.Z); if (mESP.sideColor.a > 0 || mESP.lineColor.a > 0) { + WoodType woodType = woodTypeMap.get(sign); event.renderer.box( x1, y1, z1, x2, y2, z2, - mESP.sideColor, mESP.lineColor, - ShapeMode.Both, 0 + colorFromWoodType(woodType), mESP.lineColor, + mESP.shapeMode, 0 ); }