From 23cc6afc8f52e99097d565af9f97d7fee34e97ba Mon Sep 17 00:00:00 2001 From: alemidev Date: Mon, 30 Jan 2023 03:35:23 +0100 Subject: [PATCH] feat: added FastInteract and EntityList --- .../java/co/fantabos/bscv/BoSCoVicino.java | 4 ++ .../fantabos/bscv/modules/FastInteract.java | 46 +++++++++++++++ .../fantabos/bscv/modules/hud/EntityList.java | 58 +++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 src/main/java/co/fantabos/bscv/modules/FastInteract.java create mode 100644 src/main/java/co/fantabos/bscv/modules/hud/EntityList.java diff --git a/src/main/java/co/fantabos/bscv/BoSCoVicino.java b/src/main/java/co/fantabos/bscv/BoSCoVicino.java index 1808c99..23c1d48 100644 --- a/src/main/java/co/fantabos/bscv/BoSCoVicino.java +++ b/src/main/java/co/fantabos/bscv/BoSCoVicino.java @@ -65,8 +65,12 @@ public class BoSCoVicino { builder.pop(); BoSCoVicino.mods.add(new VanillaFlight(builder, this.dispatcher)); builder.pop(); + BoSCoVicino.mods.add(new FastInteract(builder, this.dispatcher)); + builder.pop(); BoSCoVicino.mods.add(new Coordinates(builder, this.dispatcher)); builder.pop(); + BoSCoVicino.mods.add(new EntityList(builder, this.dispatcher)); + builder.pop(); BoSCoVicino.mods.add(new ActiveModules(builder, this.dispatcher)); builder.pop(); diff --git a/src/main/java/co/fantabos/bscv/modules/FastInteract.java b/src/main/java/co/fantabos/bscv/modules/FastInteract.java new file mode 100644 index 0000000..f9d9d29 --- /dev/null +++ b/src/main/java/co/fantabos/bscv/modules/FastInteract.java @@ -0,0 +1,46 @@ +package co.fantabos.bscv.modules; + +import static co.fantabos.bscv.BoSCoVicino.log; + +import java.lang.reflect.Field; + +import com.mojang.brigadier.CommandDispatcher; + +import net.minecraft.command.CommandSource; +import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.event.TickEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; + +import co.fantabos.bscv.Module; +import co.fantabos.bscv.BoSCoVicino; + +public class FastInteract extends Module { + + Field delayField; + + public FastInteract(ForgeConfigSpec.Builder builder, CommandDispatcher dispatcher) { + super("FastInteract", Group.CORE, builder, dispatcher); + } + + @Override + protected void onEnabled() { + try { + delayField = BoSCoVicino.minecraft.getClass().getDeclaredField("field_71467_ac"); + delayField.setAccessible(true); + } catch (NoSuchFieldException e) { + log("! failed accessing delay field"); + this.disable(); + } + } + + @SubscribeEvent + public void onTick(TickEvent.ClientTickEvent event) { + if (BoSCoVicino.minecraft == null) return; + try { + this.delayField.set(BoSCoVicino.minecraft, 0); + } catch (IllegalAccessException e) { + log("! failed accessing delay field"); + this.disable(); + } + } +} diff --git a/src/main/java/co/fantabos/bscv/modules/hud/EntityList.java b/src/main/java/co/fantabos/bscv/modules/hud/EntityList.java new file mode 100644 index 0000000..ee013b7 --- /dev/null +++ b/src/main/java/co/fantabos/bscv/modules/hud/EntityList.java @@ -0,0 +1,58 @@ +package co.fantabos.bscv.modules.hud; + +import static co.fantabos.bscv.tools.Text.TextBuilder; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +import com.mojang.brigadier.CommandDispatcher; + +import co.fantabos.bscv.BoSCoVicino; +import net.minecraft.command.CommandSource; +import net.minecraft.entity.Entity; +import net.minecraftforge.client.event.RenderGameOverlayEvent; +import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; +import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.eventbus.api.SubscribeEvent; + +public class EntityList extends HudModule { + + public EntityList(ForgeConfigSpec.Builder builder, CommandDispatcher dispatcher) { + super("EntityList", builder, dispatcher); + } + + @SubscribeEvent + public void onRenderOverlay(RenderGameOverlayEvent event) { + if (event.getType() != ElementType.TEXT) return; + + List entities = new ArrayList<>(); + for (Entity e : BoSCoVicino.minecraft.level.entitiesForRendering()) { + // TODO do some filtering here? + entities.add(e.getName().getString()); + } + + List uniques = new ArrayList<>(); + for (String s : entities.stream().distinct().collect(Collectors.toList())) { + int num = Collections.frequency(entities, s); + if (num > 1) { + uniques.add(String.format("%s (%d)", s, num)); + } else { + uniques.add(s); + } + } + + int offset = 0; + for (String u : uniques) { + TextBuilder() + .txt(String.format("%s <", u)) + .anchor(this.anchor.get()) + .x(this.x.get()) + .y(this.y.get() + offset) + .scale(this.scale.get()) + .render(event.getMatrixStack(), event.getWindow()); + offset += BoSCoVicino.minecraft.font.lineHeight; + } + } +}