summaryrefslogtreecommitdiff
path: root/src/main/java/ftbsc
diff options
context:
space:
mode:
author alemi <me@alemi.dev>2023-03-12 02:14:33 +0100
committer alemi <me@alemi.dev>2023-03-12 02:14:33 +0100
commit9eab4544b0040417cd7a51a5be300b9ac940871f (patch)
tree5d187e1702c4ee00c6d4696355f517571c9b0209 /src/main/java/ftbsc
parent28a7cb966037b0521009a6bd8467460e21b08031 (diff)
feat: new module UpdateESP0.3.6
Diffstat (limited to 'src/main/java/ftbsc')
-rw-r--r--src/main/java/ftbsc/bscv/modules/vision/UpdateESP.java150
1 files changed, 150 insertions, 0 deletions
diff --git a/src/main/java/ftbsc/bscv/modules/vision/UpdateESP.java b/src/main/java/ftbsc/bscv/modules/vision/UpdateESP.java
new file mode 100644
index 0000000..6db66f1
--- /dev/null
+++ b/src/main/java/ftbsc/bscv/modules/vision/UpdateESP.java
@@ -0,0 +1,150 @@
+package ftbsc.bscv.modules.vision;
+
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentLinkedQueue;
+
+import org.lwjgl.opengl.GL11;
+
+import com.google.auto.service.AutoService;
+import com.mojang.blaze3d.matrix.MatrixStack;
+import com.mojang.blaze3d.systems.RenderSystem;
+
+import ftbsc.bscv.api.ILoadable;
+import ftbsc.bscv.modules.QuickModule;
+import ftbsc.bscv.patches.PacketPatch.PacketEvent;
+import ftbsc.bscv.tools.Setting;
+import net.minecraft.client.renderer.BufferBuilder;
+import net.minecraft.client.renderer.Tessellator;
+import net.minecraft.client.renderer.WorldRenderer;
+import net.minecraft.client.renderer.WorldVertexBufferUploader;
+import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
+import net.minecraft.network.play.server.SChangeBlockPacket;
+import net.minecraft.network.play.server.SMultiBlockChangePacket;
+import net.minecraft.util.Tuple;
+import net.minecraft.util.math.vector.Vector3d;
+import net.minecraft.util.math.vector.Vector3i;
+import net.minecraftforge.client.event.RenderWorldLastEvent;
+import net.minecraftforge.common.ForgeConfigSpec;
+import net.minecraftforge.event.TickEvent;
+import net.minecraftforge.event.TickEvent.Phase;
+import net.minecraftforge.eventbus.api.SubscribeEvent;
+
+@AutoService(ILoadable.class)
+public class UpdateESP extends QuickModule {
+
+ public final ForgeConfigSpec.ConfigValue<Integer> duration;
+ public final ForgeConfigSpec.ConfigValue<Double> alpha;
+ public final ForgeConfigSpec.ConfigValue<Double> width;
+ public final ForgeConfigSpec.ConfigValue<Boolean> fade;
+
+ public UpdateESP() {
+ super();
+
+ this.updates = new ConcurrentLinkedQueue<>();
+
+ this.duration = Setting.Number.builder()
+ .min(0)
+ .fallback(250)
+ .name("duration")
+ .comment("how long to show block updates")
+ .build(this);
+
+ this.alpha = Setting.Decimal.builder()
+ .min(0.)
+ .max(1.)
+ .fallback(.25)
+ .name("alpha")
+ .comment("alpha channel value for highlights")
+ .build(this);
+
+ this.width = Setting.Decimal.builder()
+ .min(0.)
+ .fallback(1.)
+ .name("width")
+ .comment("line width for highlights")
+ .build(this);
+
+ this.fade = Setting.Bool.builder()
+ .fallback(true)
+ .name("fade")
+ .comment("gradually decrease alpha to disappear smoothly")
+ .build(this);
+ }
+
+ private final ConcurrentLinkedQueue<Tuple<Vector3i, Long>> updates;
+
+ private float getAlpha(float multiplier, long insert, long now, long duration) {
+ long age = now - insert;
+ if (age > duration) return 0.f;
+ return multiplier * (1.f - ((float) age / (float) duration));
+ }
+
+ @SubscribeEvent
+ public void onRenderWorld(RenderWorldLastEvent event) {
+ RenderSystem.pushMatrix(); // ??
+
+ RenderSystem.enableBlend();
+ RenderSystem.disableTexture();
+ RenderSystem.disableDepthTest();
+ RenderSystem.lineWidth(this.width.get().floatValue());
+
+ Vector3d projectedView = MC.gameRenderer.getMainCamera().getPosition().scale(-1);
+ MatrixStack stack = event.getMatrixStack();
+ stack.pushPose(); // ??
+ stack.translate(projectedView.x(), projectedView.y(), projectedView.z());
+
+ BufferBuilder builder = Tessellator.getInstance().getBuilder();
+ builder.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR);
+
+ long time = System.currentTimeMillis();
+ long duration = this.duration.get();
+ float multiplier = this.alpha.get().floatValue();
+ boolean fade = this.fade.get();
+
+ for (Tuple<Vector3i, Long> entry : this.updates) {
+ Vector3i pos = entry.getA();
+ WorldRenderer.renderLineBox(
+ stack, builder,
+ pos.getX(), pos.getY(), pos.getZ(), pos.getX() + 1, pos.getY() + 1, pos.getZ() + 1,
+ 1.f, 1.f, 1.f, fade ? this.getAlpha(multiplier, entry.getB(), time, duration) : multiplier
+ );
+ }
+
+ builder.end();
+ WorldVertexBufferUploader.end(builder);
+ stack.popPose(); // ??
+
+ RenderSystem.lineWidth(1.f);
+ RenderSystem.enableTexture();
+ RenderSystem.enableDepthTest();
+ RenderSystem.disableBlend();
+ RenderSystem.enableCull();
+
+ RenderSystem.popMatrix(); // ??
+ }
+
+ @SubscribeEvent
+ public void onTick(TickEvent.ClientTickEvent event) {
+ if (event.phase == Phase.END) return;
+ long time = System.currentTimeMillis();
+ long duration = this.duration.get();
+ while (this.updates.peek() != null && time - this.updates.peek().getB() > duration) {
+ this.updates.poll();
+ }
+ }
+
+
+ @SubscribeEvent
+ public void onPacket(PacketEvent.Incoming event) {
+ if (event.packet instanceof SChangeBlockPacket) {
+ SChangeBlockPacket packet = (SChangeBlockPacket) event.packet;
+ this.updates.add(new Tuple<>(packet.getPos(), System.currentTimeMillis()));
+ }
+
+ if (event.packet instanceof SMultiBlockChangePacket) {
+ SMultiBlockChangePacket packet = (SMultiBlockChangePacket) event.packet;
+ packet.runUpdates( (pos, state) -> this.updates.add(new Tuple<>(pos, System.currentTimeMillis())) );
+ }
+ }
+}