Skip to content

Commit

Permalink
Added OldSign ESP to ChatSigns
Browse files Browse the repository at this point in the history
  • Loading branch information
0xTas committed Feb 25, 2024
1 parent 0ef9978 commit 7763f63
Showing 1 changed file with 125 additions and 7 deletions.
132 changes: 125 additions & 7 deletions src/main/java/dev/stardust/modules/ChatSigns.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.Direction;
import net.minecraft.registry.RegistryKey;
import net.minecraft.util.shape.VoxelShape;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import meteordevelopment.orbit.EventHandler;
Expand All @@ -37,10 +39,15 @@
import net.minecraft.block.entity.SignBlockEntity;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.block.entity.HangingSignBlockEntity;
import meteordevelopment.meteorclient.renderer.ShapeMode;
import meteordevelopment.meteorclient.systems.modules.Module;
import meteordevelopment.meteorclient.events.world.TickEvent;
import meteordevelopment.meteorclient.mixininterface.IChatHud;
import meteordevelopment.meteorclient.utils.render.RenderUtils;
import meteordevelopment.meteorclient.events.world.ChunkDataEvent;
import meteordevelopment.meteorclient.events.render.Render3DEvent;
import meteordevelopment.meteorclient.utils.render.color.SettingColor;
import meteordevelopment.meteorclient.systems.modules.render.blockesp.ESPBlockData;


/**
Expand All @@ -60,6 +67,7 @@ public enum RepeatMode {

private final SettingGroup modesGroup = settings.createGroup("Modes", true);
private final SettingGroup formatGroup = settings.createGroup("Formatting", true);
private final SettingGroup oldSignGroup = settings.createGroup("OldSigns Settings", true);
private final SettingGroup blacklistGroup = settings.createGroup("SignText Blacklist", true);

private final Setting<ChatMode> chatMode = modesGroup.add(
Expand Down Expand Up @@ -90,15 +98,15 @@ public enum RepeatMode {
.build()
);

private final Setting<Boolean> showOldSigns = modesGroup.add(
private final Setting<Boolean> showOldSigns = oldSignGroup.add(
new BoolSetting.Builder()
.name("Show Possibly Old Signs*")
.description("*will show signs placed before 1.8, AND after 1.12. Use your best judgment to determine what's legit.")
.defaultValue(false)
.build()
);

private final Setting<Boolean> onlyOldSigns = modesGroup.add(
private final Setting<Boolean> onlyOldSigns = oldSignGroup.add(
new BoolSetting.Builder()
.name("Only Show New/Old Signs")
.description("Only display text from signs that are either really old, or brand new.")
Expand All @@ -107,10 +115,10 @@ public enum RepeatMode {
.build()
);

private final Setting<Boolean> ignoreNether = modesGroup.add(
private final Setting<Boolean> ignoreNether = oldSignGroup.add(
new BoolSetting.Builder()
.name("Ignore Nether")
.description("Ignore potentially-old signs in the nether since near highways they're almost all certainly new.")
.description("Ignore potentially-old signs in the nether (near highways they're all certainly new.)")
.visible(showOldSigns::get)
.defaultValue(true)
.build()
Expand Down Expand Up @@ -140,7 +148,7 @@ public enum RepeatMode {
.build()
);

private final Setting<TextColor> oldSignColor = formatGroup.add(
private final Setting<TextColor> oldSignColor = oldSignGroup.add(
new EnumSetting.Builder<TextColor>()
.name("Old Sign Color")
.description("Text color for signs that might be old.")
Expand All @@ -149,7 +157,7 @@ public enum RepeatMode {
.build()
);

private final Setting<TextFormat> oldSignFormat = formatGroup.add(
private final Setting<TextFormat> oldSignFormat = oldSignGroup.add(
new EnumSetting.Builder<TextFormat>()
.name("Old Text Format")
.description("Apply formatting to text displayed from (maybe) old signs.")
Expand All @@ -172,6 +180,27 @@ public enum RepeatMode {
.build()
);

private final Setting<Boolean> renderOldSigns = oldSignGroup.add(new BoolSetting.Builder()
.name("OldSign ESP")
.description("Render signs which could be old through walls.")
.defaultValue(false)
.build()
);

private final Setting<ESPBlockData> espSettings = oldSignGroup.add(new GenericSetting.Builder<ESPBlockData>()
.name("ESP Settings")
.defaultValue(
new ESPBlockData(
ShapeMode.Both,
new SettingColor(147, 233, 190),
new SettingColor(147, 233, 190, 25),
true,
new SettingColor(147, 233, 190, 125)
)
)
.build()
);

private final Setting<Boolean> signBlacklist = blacklistGroup.add(
new BoolSetting.Builder()
.name("SignText Blacklist")
Expand Down Expand Up @@ -218,6 +247,7 @@ public enum RepeatMode {
private int totalTicksEnabled = 0;
@Nullable private BlockPos lastFocusedSign = null;
private final HashSet<BlockPos> posSet = new HashSet<>();
private final HashSet<BlockPos> oldSet = new HashSet<>();
private final ArrayList<String> blacklisted = new ArrayList<>();
private final HashMap<BlockPos, Instant> cooldowns = new HashMap<>();
private final HashMap<String, Integer> signMessages = new HashMap<>();
Expand Down Expand Up @@ -284,7 +314,7 @@ private String formatSignText(SignBlockEntity sign, WorldChunk chunk) {
// and we can make sure the sign material is oak for those signs in chunks devoid of copper,
// but new oak signs placed in old chunks can still be indistinguishable from old signs by metadata alone.

// On 2b2t, this will single-out oak-material signs placed BOTH before January 2015, and AFTER August 2023 (in old chunks).
// On 2b2t, this will single-out oak-material signs placed BOTH before January 2015, and AFTER August 2023 (in old pre 1.8 chunks).
// While this will still be useful for identifying old bases for a while,
// most old signs are at spawn, and the signal-to-noise ratio there will worsen every single day.
boolean couldBeOld = false;
Expand Down Expand Up @@ -316,6 +346,7 @@ private String formatSignText(SignBlockEntity sign, WorldChunk chunk) {
if (!couldBeOld && showOldSigns.get() && onlyOldSigns.get()) return "";
if (couldBeOld && showOldSigns.get()) {
color = oldSignColor.get().label;
this.oldSet.add(sign.getPos());
}
String signText = chatFormat.get() ?
String.join("\n"+ color + format, lines) : String.join(" ", lines);
Expand Down Expand Up @@ -532,6 +563,7 @@ public void onActivate() {
@Override
public void onDeactivate() {
this.posSet.clear();
this.oldSet.clear();
this.cooldowns.clear();
this.chunkCache.clear();
this.blacklisted.clear();
Expand Down Expand Up @@ -584,4 +616,90 @@ private void onTick(TickEvent.Pre event) {
cooldowns.put(targetedSign, Instant.now());
}
}

@EventHandler
private void onRender(Render3DEvent event) {
if (mc.player == null || mc.world == null || !renderOldSigns.get()) return;
List<BlockPos> inRange = this.oldSet
.stream()
.filter(pos -> pos.isWithinDistance(mc.player.getBlockPos(), mc.options.getViewDistance().getValue() * 16+32))
.toList();

ESPBlockData esp = espSettings.get();
for (BlockPos pos : inRange) {
BlockState state = mc.world.getBlockState(pos);
if (!(state.getBlock() instanceof SignBlock) && !(state.getBlock() instanceof WallSignBlock)) continue;
VoxelShape shape = state.getOutlineShape(mc.world, pos);

double x1 = pos.getX() + shape.getMin(Direction.Axis.X);
double y1 = pos.getY() + shape.getMin(Direction.Axis.Y);
double z1 = pos.getZ() + shape.getMin(Direction.Axis.Z);
double x2 = pos.getX() + shape.getMax(Direction.Axis.X);
double y2 = pos.getY() + shape.getMax(Direction.Axis.Y);
double z2 = pos.getZ() + shape.getMax(Direction.Axis.Z);

event.renderer.box(
x1, y1, z1, x2, y2, z2,
esp.sideColor, esp.lineColor, esp.shapeMode, 0
);

if (esp.tracer) {
try {
double offsetX;
double offsetY;
double offsetZ;
if (state.getBlock() instanceof SignBlock) {
offsetX = pos.getX() + .5;
offsetY = pos.getY() + .5;
offsetZ = pos.getZ() + .5;
} else if (state.getBlock() instanceof WallSignBlock) {
Direction facing = state.get(WallSignBlock.FACING);
switch (facing) {
case NORTH -> {
offsetX = pos.getX() + .5;
offsetY = pos.getY() + .5;
offsetZ = pos.getZ() + .937;
}
case EAST -> {
offsetX = pos.getX() + .1337;
offsetY = pos.getY() + .5;
offsetZ = pos.getZ() + .5;
}
case SOUTH -> {
offsetX = pos.getX() + .5;
offsetY = pos.getY() + .5;
offsetZ = pos.getZ() + .1337;
}
case WEST -> {
offsetX = pos.getX() + .937;
offsetY = pos.getY() + .5;
offsetZ = pos.getZ() + .5;
}
default -> {
offsetX = pos.getX() + .5;
offsetY = pos.getY() + .5;
offsetZ = pos.getZ() + .5;
}
}
} else {
offsetX = pos.getX() + .5;
offsetY = pos.getY() + .5;
offsetZ = pos.getZ() + .5;
}

event.renderer.line(
RenderUtils.center.x,
RenderUtils.center.y,
RenderUtils.center.z,
offsetX,
offsetY,
offsetZ,
esp.tracerColor
);
} catch (Exception err) {
err.printStackTrace();
}
}
}
}
}

0 comments on commit 7763f63

Please sign in to comment.