From 16b4246ac7fec7845849e98a3f7715f2ab10650c Mon Sep 17 00:00:00 2001 From: alemi Date: Mon, 13 Feb 2023 18:27:04 +0100 Subject: chore: plural --- src/main/java/ftbsc/bscv/module/HudModule.java | 47 ------ src/main/java/ftbsc/bscv/module/Module.java | 159 --------------------- src/main/java/ftbsc/bscv/module/QuickModule.java | 90 ------------ .../java/ftbsc/bscv/module/hud/ActiveModules.java | 41 ------ .../java/ftbsc/bscv/module/hud/Coordinates.java | 35 ----- .../java/ftbsc/bscv/module/hud/EntityList.java | 59 -------- .../java/ftbsc/bscv/module/hud/InfoDisplay.java | 135 ----------------- .../ftbsc/bscv/module/motion/VanillaFlight.java | 109 -------------- .../java/ftbsc/bscv/module/self/FastInteract.java | 46 ------ src/main/java/ftbsc/bscv/module/self/Freecam.java | 131 ----------------- .../java/ftbsc/bscv/module/vision/Fullbright.java | 47 ------ src/main/java/ftbsc/bscv/modules/HudModule.java | 47 ++++++ src/main/java/ftbsc/bscv/modules/Module.java | 159 +++++++++++++++++++++ src/main/java/ftbsc/bscv/modules/QuickModule.java | 90 ++++++++++++ .../java/ftbsc/bscv/modules/hud/ActiveModules.java | 41 ++++++ .../java/ftbsc/bscv/modules/hud/Coordinates.java | 35 +++++ .../java/ftbsc/bscv/modules/hud/EntityList.java | 59 ++++++++ .../java/ftbsc/bscv/modules/hud/InfoDisplay.java | 135 +++++++++++++++++ .../ftbsc/bscv/modules/motion/VanillaFlight.java | 109 ++++++++++++++ .../java/ftbsc/bscv/modules/self/FastInteract.java | 46 ++++++ src/main/java/ftbsc/bscv/modules/self/Freecam.java | 131 +++++++++++++++++ .../java/ftbsc/bscv/modules/vision/Fullbright.java | 47 ++++++ 22 files changed, 899 insertions(+), 899 deletions(-) delete mode 100644 src/main/java/ftbsc/bscv/module/HudModule.java delete mode 100644 src/main/java/ftbsc/bscv/module/Module.java delete mode 100644 src/main/java/ftbsc/bscv/module/QuickModule.java delete mode 100644 src/main/java/ftbsc/bscv/module/hud/ActiveModules.java delete mode 100644 src/main/java/ftbsc/bscv/module/hud/Coordinates.java delete mode 100644 src/main/java/ftbsc/bscv/module/hud/EntityList.java delete mode 100644 src/main/java/ftbsc/bscv/module/hud/InfoDisplay.java delete mode 100644 src/main/java/ftbsc/bscv/module/motion/VanillaFlight.java delete mode 100644 src/main/java/ftbsc/bscv/module/self/FastInteract.java delete mode 100644 src/main/java/ftbsc/bscv/module/self/Freecam.java delete mode 100644 src/main/java/ftbsc/bscv/module/vision/Fullbright.java create mode 100644 src/main/java/ftbsc/bscv/modules/HudModule.java create mode 100644 src/main/java/ftbsc/bscv/modules/Module.java create mode 100644 src/main/java/ftbsc/bscv/modules/QuickModule.java create mode 100644 src/main/java/ftbsc/bscv/modules/hud/ActiveModules.java create mode 100644 src/main/java/ftbsc/bscv/modules/hud/Coordinates.java create mode 100644 src/main/java/ftbsc/bscv/modules/hud/EntityList.java create mode 100644 src/main/java/ftbsc/bscv/modules/hud/InfoDisplay.java create mode 100644 src/main/java/ftbsc/bscv/modules/motion/VanillaFlight.java create mode 100644 src/main/java/ftbsc/bscv/modules/self/FastInteract.java create mode 100644 src/main/java/ftbsc/bscv/modules/self/Freecam.java create mode 100644 src/main/java/ftbsc/bscv/modules/vision/Fullbright.java diff --git a/src/main/java/ftbsc/bscv/module/HudModule.java b/src/main/java/ftbsc/bscv/module/HudModule.java deleted file mode 100644 index d1f0842..0000000 --- a/src/main/java/ftbsc/bscv/module/HudModule.java +++ /dev/null @@ -1,47 +0,0 @@ -package ftbsc.bscv.module; - -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.arguments.DoubleArgumentType; -import com.mojang.brigadier.arguments.IntegerArgumentType; - -import ftbsc.bscv.tools.Anchor; -import net.minecraft.command.CommandSource; -import net.minecraftforge.common.ForgeConfigSpec; -import net.minecraftforge.server.command.EnumArgument; - -public abstract class HudModule extends Module { - - public final ForgeConfigSpec.ConfigValue x; - public final ForgeConfigSpec.ConfigValue y; - public final ForgeConfigSpec.ConfigValue scale; - public final ForgeConfigSpec.EnumValue anchor; - - protected HudModule(String name, ForgeConfigSpec.Builder builder, CommandDispatcher dispatcher) { - super(name, Group.HUD, builder, dispatcher); - - this.x = this.option( - "x", "horizontal offset", 0, - IntegerArgumentType.integer(0), Integer.class, - builder, dispatcher - ); - - this.y = this.option( - "y", "vertical offset", 0, - IntegerArgumentType.integer(0), Integer.class, - builder, dispatcher - ); - - this.scale = this.option( - "scale", "scale of element", 1.0, - DoubleArgumentType.doubleArg(0.0), Double.class, - builder, dispatcher - ); - - this.anchor = this.optionEnum( - "anchor", "origin point for coordinates", Anchor.TOPLEFT, - EnumArgument.enumArgument(Anchor.class), Anchor.class, - builder, dispatcher - ); - } - -} diff --git a/src/main/java/ftbsc/bscv/module/Module.java b/src/main/java/ftbsc/bscv/module/Module.java deleted file mode 100644 index 84153a7..0000000 --- a/src/main/java/ftbsc/bscv/module/Module.java +++ /dev/null @@ -1,159 +0,0 @@ -package ftbsc.bscv.module; - -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.arguments.ArgumentType; - -import ftbsc.bscv.BoSCoVicino; -import net.minecraft.command.CommandSource; -import net.minecraft.command.Commands; -import net.minecraftforge.common.ForgeConfigSpec; -import net.minecraftforge.common.MinecraftForge; - -import static ftbsc.bscv.BoSCoVicino.log; - -public abstract class Module { - public enum Group { - SELF, - HUD, - BUILD, - DEFENSE, - VISION, - MOTION, - } - - public final String name; - public final Group group; - public final ForgeConfigSpec.ConfigValue enabled; - - protected Module(String name, Group group, ForgeConfigSpec.Builder builder, CommandDispatcher dispatcher) { - this.name = name; - this.group = group; - - builder.push(this.name.toLowerCase()); - this.enabled = builder - .comment(String.format("Enables %s", this.name)) - .define("enabled", false); - - dispatcher.register( - Commands.literal(this.name.toLowerCase()) - .then( - Commands.literal("toggle") - .executes(ctx -> { - this.toggle(); - return 1; - }) - ) - .executes(ctx -> { - log(String.format("=[ %s ]%s", this.name, this.enabled.get() ? "+" : "")); - // TODO: print all mod options! - return 1; - }) - ); - } - - public Module done(ForgeConfigSpec.Builder builder) { - builder.pop(); - return this; - } - - - // TODO can I merge these two option into one? Maybe redo with builder pattern? - - public > ForgeConfigSpec.EnumValue optionEnum( - String name, - String comment, - T fallback, - ArgumentType argument, - Class clazz, - ForgeConfigSpec.Builder builder, - CommandDispatcher dispatcher - ) { - ForgeConfigSpec.EnumValue conf = builder - .comment(comment) - .defineEnum(name, fallback); - - dispatcher.register( - Commands.literal(this.name.toLowerCase()) - .then( - Commands.literal(name) - .then( - Commands.argument(name, argument) - .executes( ctx -> { - T value = ctx.getArgument(name, clazz); - conf.set(value); - conf.save(); - log(String.format("> %s -> %s", String.join(".", conf.getPath()), conf.get().toString())); - return 1; - })) - .executes(ctx -> { - log(String.format("> %s: %s", String.join(".", conf.getPath()), conf.get().toString())); - return 1; - }) - ) - ); - - return conf; - } - - public ForgeConfigSpec.ConfigValue option( - String name, - String comment, - T fallback, - ArgumentType argument, - Class clazz, - ForgeConfigSpec.Builder builder, - CommandDispatcher dispatcher - ) { - ForgeConfigSpec.ConfigValue conf = builder - .comment(comment) - .define(name, fallback); - - dispatcher.register( - Commands.literal(this.name.toLowerCase()) - .then( - Commands.literal(name) - .then( - Commands.argument(name, argument) - .executes( ctx -> { - T value = ctx.getArgument(name, clazz); - conf.set(value); - conf.save(); - log(String.format("> %s -> %s", String.join(".", conf.getPath()), conf.get().toString())); - return 1; - })) - .executes(ctx -> { - log(String.format("> %s: %s", name, conf.get().toString())); - return 1; - }) - ) - ); - - return conf; - } - - protected void onEnabled() {} - protected void onDisabled() {} - - public final void toggle() { - if (this.enabled.get()) this.disable(); - else this.enable(); - } - - public final void enable() { - MinecraftForge.EVENT_BUS.register(this); - this.enabled.set(true); - // this.enabled.save(); - this.onEnabled(); - log(String.format("%s enabled", this.name)); - BoSCoVicino.LOGGER.info(String.format("%s enabled", this.name)); - } - - public final void disable() { - MinecraftForge.EVENT_BUS.unregister(this); - this.enabled.set(false); - // this.enabled.save(); - this.onDisabled(); - log(String.format("%s disabled", this.name)); - BoSCoVicino.LOGGER.info(String.format("%s disabled", this.name)); - } -} diff --git a/src/main/java/ftbsc/bscv/module/QuickModule.java b/src/main/java/ftbsc/bscv/module/QuickModule.java deleted file mode 100644 index 8eefa55..0000000 --- a/src/main/java/ftbsc/bscv/module/QuickModule.java +++ /dev/null @@ -1,90 +0,0 @@ -package ftbsc.bscv.module; - -import com.mojang.brigadier.CommandDispatcher; - -import net.minecraft.client.settings.KeyBinding; -import net.minecraft.client.util.InputMappings; -import net.minecraft.command.CommandSource; -import net.minecraftforge.client.event.InputEvent; -import net.minecraftforge.common.ForgeConfigSpec; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.client.registry.ClientRegistry; - -import ftbsc.bscv.BoSCoVicino; - -// TODO rename -public class QuickModule extends Module { - - public static final int UNBOUND = InputMappings.UNKNOWN.getValue(); - - private class ToggleHook { - private final KeyBinding key; - private final Module mod; - private boolean debounce; - // TODO all examples show isPressed() to get a debounced value - // but it seems to be missing? making my own debounce for now - protected ToggleHook(KeyBinding key, Module mod) { - this.key = key; - this.mod = mod; - this.debounce = false; - } - - private void onInput() { - if (this.debounce) { - if (!this.key.isDown()) { - this.debounce = false; - } - } else { - if (this.key.isDown()) { - this.mod.toggle(); - this.debounce = true; - } - } - } - - @SubscribeEvent - public void onKeyPress(InputEvent.KeyInputEvent event) { this.onInput(); } - @SubscribeEvent - public void onKeyPress(InputEvent.MouseInputEvent event) { this.onInput(); } - } - - public final KeyBinding keybind; - - public QuickModule(String name, Group group, int default_key, ForgeConfigSpec.Builder builder, CommandDispatcher dispatcher) { - super(name, group, builder, dispatcher); - - this.keybind = new KeyBinding(key_name(name), default_key, key_category()); - ClientRegistry.registerKeyBinding(this.keybind); - - // register a separate subclass on the hook, so that it's always listening - MinecraftForge.EVENT_BUS.register(new ToggleHook(this.keybind, this)); - - // dispatcher.register( - // Commands.literal(this.name.toLowerCase()) - // .then( - // Commands.literal("bind") - // .then( - // Commands.argument("key", StringArgumentType.word()) - // .executes( ctx -> { - // this.keybind.setKey( - // InputMappings.getKey( // TODO it's not this easy! - // StringArgumentType.getString(ctx, "key") - // ) - // ); - // return 1; - // }) - // ) - // ) - // ); - } - - private static String key_name(String name) { - return String.format("key.%s.%s", BoSCoVicino.MOD_ID, name); - } - - private static String key_category() { - return String.format("key.category.%s", BoSCoVicino.MOD_ID); - } - -} diff --git a/src/main/java/ftbsc/bscv/module/hud/ActiveModules.java b/src/main/java/ftbsc/bscv/module/hud/ActiveModules.java deleted file mode 100644 index cd0a197..0000000 --- a/src/main/java/ftbsc/bscv/module/hud/ActiveModules.java +++ /dev/null @@ -1,41 +0,0 @@ -package ftbsc.bscv.module.hud; - -import static ftbsc.bscv.tools.Text.TextBuilder; - -import com.mojang.brigadier.CommandDispatcher; - -import ftbsc.bscv.BoSCoVicino; -import ftbsc.bscv.ICommons; -import net.minecraft.command.CommandSource; -import net.minecraftforge.client.event.RenderGameOverlayEvent; -import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; -import net.minecraftforge.common.ForgeConfigSpec; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import ftbsc.bscv.module.HudModule; -import ftbsc.bscv.module.Module; - -public class ActiveModules extends HudModule implements ICommons { - - public ActiveModules(ForgeConfigSpec.Builder builder, CommandDispatcher dispatcher) { - super("ActiveModules", builder, dispatcher); - } - - @SubscribeEvent - public void onRenderOverlay(RenderGameOverlayEvent event) { - if (event.getType() == ElementType.TEXT) { - int offset = 0; - for (Module m : BoSCoVicino.mods) { - if (m.enabled.get() && m.group != Group.HUD) { - TextBuilder() - .txt(String.format("%s <", m.name)) - .anchor(this.anchor.get()) - .x(this.x.get()) - .y(this.y.get() + offset) - .scale(this.scale.get()) - .render(event.getMatrixStack(), event.getWindow()); - offset += MC.font.lineHeight; - } - } - } - } -} diff --git a/src/main/java/ftbsc/bscv/module/hud/Coordinates.java b/src/main/java/ftbsc/bscv/module/hud/Coordinates.java deleted file mode 100644 index b4e972c..0000000 --- a/src/main/java/ftbsc/bscv/module/hud/Coordinates.java +++ /dev/null @@ -1,35 +0,0 @@ -package ftbsc.bscv.module.hud; - -import com.mojang.brigadier.CommandDispatcher; - -import net.minecraft.command.CommandSource; -import net.minecraft.util.math.vector.Vector3d; -import net.minecraftforge.client.event.RenderGameOverlayEvent; -import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; -import net.minecraftforge.common.ForgeConfigSpec; -import net.minecraftforge.eventbus.api.SubscribeEvent; - -import static ftbsc.bscv.tools.Text.TextBuilder; -import ftbsc.bscv.ICommons; -import ftbsc.bscv.module.HudModule; - -public class Coordinates extends HudModule implements ICommons { - - public Coordinates(ForgeConfigSpec.Builder builder, CommandDispatcher dispatcher) { - super("Coordinates", builder, dispatcher); - } - - @SubscribeEvent - public void onRenderOverlay(RenderGameOverlayEvent event) { - if (event.getType() == ElementType.TEXT && MC.player != null) { - Vector3d position = MC.player.position(); - TextBuilder() - .txt(String.format("[ X %.1f | %.1f Z ] %.1f Y", position.x(), position.z(), position.y())) - .anchor(this.anchor.get()) - .x(this.x.get()) - .y(this.y.get()) - .scale(this.scale.get()) - .render(event.getMatrixStack(), event.getWindow()); - } - } -} diff --git a/src/main/java/ftbsc/bscv/module/hud/EntityList.java b/src/main/java/ftbsc/bscv/module/hud/EntityList.java deleted file mode 100644 index acb45b3..0000000 --- a/src/main/java/ftbsc/bscv/module/hud/EntityList.java +++ /dev/null @@ -1,59 +0,0 @@ -package ftbsc.bscv.module.hud; - -import static ftbsc.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 ftbsc.bscv.ICommons; -import ftbsc.bscv.module.HudModule; -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 implements ICommons { - - 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 : MC.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 += MC.font.lineHeight; - } - } -} diff --git a/src/main/java/ftbsc/bscv/module/hud/InfoDisplay.java b/src/main/java/ftbsc/bscv/module/hud/InfoDisplay.java deleted file mode 100644 index dd7103f..0000000 --- a/src/main/java/ftbsc/bscv/module/hud/InfoDisplay.java +++ /dev/null @@ -1,135 +0,0 @@ -package ftbsc.bscv.module.hud; - -import static ftbsc.bscv.tools.Text.TextBuilder; - -import java.util.ArrayDeque; - -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.arguments.BoolArgumentType; - -import ftbsc.bscv.BoSCoVicino; -import ftbsc.bscv.ICommons; -import ftbsc.bscv.module.HudModule; -import net.minecraft.client.Minecraft; -import net.minecraft.command.CommandSource; -import net.minecraft.util.math.vector.Vector3d; -import net.minecraft.util.text.Color; -import net.minecraft.util.text.Style; -import net.minecraftforge.client.event.RenderGameOverlayEvent; -import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; -import net.minecraftforge.common.ForgeConfigSpec; -import net.minecraftforge.event.TickEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; - -public class InfoDisplay extends HudModule implements ICommons { - - - private Vector3d last_position = new Vector3d(0.0, 0.0, 0.0); - private double instant_speed = 0.0; - private double average_speed = 0.0; - private ArrayDeque history_speed = new ArrayDeque<>(); - - public final ForgeConfigSpec.ConfigValue logo; - public final ForgeConfigSpec.ConfigValue speed; - public final ForgeConfigSpec.ConfigValue time; - // public final ForgeConfigSpec.ConfigValue fps; - // public final ForgeConfigSpec.ConfigValue biome; - // public final ForgeConfigSpec.ConfigValue latency; - // public final ForgeConfigSpec.ConfigValue tps; - // public final ForgeConfigSpec.ConfigValue light; - // public final ForgeConfigSpec.ConfigValue saturation; - // public final ForgeConfigSpec.ConfigValue system_time; - // public final ForgeConfigSpec.ConfigValue damage_value; - // public final ForgeConfigSpec.ConfigValue effects_list; - // public final ForgeConfigSpec.ConfigValue item_quantity; - // public final ForgeConfigSpec.ConfigValue client_chunk_size; - - public InfoDisplay(ForgeConfigSpec.Builder builder, CommandDispatcher dispatcher) { - super("InfoDisplay", builder, dispatcher); - - this.logo = this.option( - "logo", "show logo at top of list", true, - BoolArgumentType.bool(), Boolean.class, - builder, dispatcher - ); - - this.speed = this.option( - "speed", "show speed meter", true, - BoolArgumentType.bool(), Boolean.class, - builder, dispatcher - ); - - this.time = this.option( - "time", "show world time", true, - BoolArgumentType.bool(), Boolean.class, - builder, dispatcher - ); - } - - @SubscribeEvent - public void onTick(TickEvent.ClientTickEvent event) { - if (!this.speed.get()) return; - if (MC.player != null) { - this.instant_speed = - this.last_position.distanceTo(MC.player.position()); - this.last_position = MC.player.position(); - } else { - this.instant_speed = 0.0; - } - - this.history_speed.push(this.instant_speed); - while (this.history_speed.size() >= 100) { // TODO customize this parameter - this.history_speed.pop(); - } - - double buf = 0.0; - for (double v : this.history_speed) { buf += v; } - this.average_speed = buf / this.history_speed.size(); - } - - @SubscribeEvent - public void onRenderOverlay(RenderGameOverlayEvent event) { - if (event.getType() != ElementType.TEXT) return; - - Minecraft mc = MC; - int offset = 0; - double scale = this.scale.get(); - if (this.logo.get()) { - TextBuilder() - .txt("BSCV") - .anchor(this.anchor.get()) - .x(this.x.get() / 4) - .y(this.y.get() / 4) - .style(Style.EMPTY.withColor(Color.fromRgb(12542314)).withBold(true)) - .scale(scale * 4.0) - .render(event.getMatrixStack(), event.getWindow()); - offset += mc.font.lineHeight * scale * 4.0; - } - - if (this.time.get()) { - long daytime = 0; - if (mc.level != null) { - daytime = mc.level.dayTime(); - } - TextBuilder() - .txt(String.format("> time: %d/1200 (%d day)", (daytime / 20) % 1200, daytime / (20 * 1200) )) - .anchor(this.anchor.get()) - .x(this.x.get()) - .y(this.y.get() + offset) - .scale(scale) - .render(event.getMatrixStack(), event.getWindow()); - offset += mc.font.lineHeight * scale; - } - - if (this.speed.get()) { - TextBuilder() - .txt(String.format("> speed: %.1f [%.1f] m/s", this.instant_speed * 20.0, this.average_speed * 20.0)) - .anchor(this.anchor.get()) - .x(this.x.get()) - .y(this.y.get() + offset) - .scale(scale) - .render(event.getMatrixStack(), event.getWindow()); - offset += mc.font.lineHeight * scale; - } - } -} diff --git a/src/main/java/ftbsc/bscv/module/motion/VanillaFlight.java b/src/main/java/ftbsc/bscv/module/motion/VanillaFlight.java deleted file mode 100644 index f29699b..0000000 --- a/src/main/java/ftbsc/bscv/module/motion/VanillaFlight.java +++ /dev/null @@ -1,109 +0,0 @@ -package ftbsc.bscv.module.motion; - -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.arguments.BoolArgumentType; -import com.mojang.brigadier.arguments.DoubleArgumentType; -import com.mojang.brigadier.arguments.IntegerArgumentType; - -import ftbsc.bscv.BoSCoVicino; -import ftbsc.bscv.ICommons; -import ftbsc.bscv.module.QuickModule; -import net.minecraft.client.entity.player.ClientPlayerEntity; -import net.minecraft.command.CommandSource; -import net.minecraftforge.common.ForgeConfigSpec; -import net.minecraftforge.event.TickEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; - -public class VanillaFlight extends QuickModule implements ICommons { - - public final ForgeConfigSpec.ConfigValue force; - public final ForgeConfigSpec.ConfigValue speed; - public final ForgeConfigSpec.ConfigValue antikick; - public final ForgeConfigSpec.ConfigValue antikick_magnitude; - public final ForgeConfigSpec.ConfigValue antikick_cycle; - - private final float minDescent = 0.03125f; - private final int maxTicks = 80; - private int tick = 0; - - public VanillaFlight(ForgeConfigSpec.Builder builder, CommandDispatcher dispatcher) { - super("VanillaFlight", Group.MOTION, UNBOUND, builder, dispatcher); - - this.force = this.option( - "force", "force enable flight on user", false, - BoolArgumentType.bool(), Boolean.class, - builder, dispatcher - ); - - this.speed = this.option( - "speed", "flight speed to set", 0.05, - DoubleArgumentType.doubleArg(0.0), Double.class, - builder, dispatcher - ); - - this.antikick = this.option( - "antikick", "prevent vanilla flight kick by descending", false, - BoolArgumentType.bool(), Boolean.class, - builder, dispatcher - ); - - this.antikick_magnitude = this.option( - "magnitude", "magnitude of antikick push", 1.0, - DoubleArgumentType.doubleArg(0.0), Double.class, - builder, dispatcher - ); - - this.antikick_cycle = this.option( - "cycle", "how often to run antikick routine", 0, - IntegerArgumentType.integer(0, 79), Integer.class, - builder, dispatcher - ); - } - - private boolean couldFlyBefore = false; - private float flyingSpeedBefore = 0.05f; - - @SubscribeEvent - public void onTick(TickEvent.ClientTickEvent event) { - ClientPlayerEntity player = MC.player; - if (player == null) return; - - player.abilities.mayfly = true; - player.abilities.setFlyingSpeed(this.speed.get().floatValue()); - if (this.force.get()) { - player.abilities.flying = true; - } - if (this.antikick.get()) { - if (this.tick != 0 && this.tick % (maxTicks - this.antikick_cycle.get()) == 0) { - player.push(0.0, -(this.antikick_magnitude.get() * minDescent), 0.0); - this.tick = 0; - } else if (this.tick == 0) { - player.push(0.0, this.antikick_magnitude.get() * minDescent, 0.0); - this.tick++; - } else { - this.tick++; - } - } - } - - @Override - protected void onEnabled() { - if (MC.player != null) { - this.couldFlyBefore = MC.player.abilities.mayfly; - this.flyingSpeedBefore = MC.player.abilities.getFlyingSpeed(); - BoSCoVicino.log(String.format("Flying speed before = %f", this.flyingSpeedBefore)); - } - } - - @Override - protected void onDisabled() { - ClientPlayerEntity player = MC.player; - if (player != null) { - player.abilities.mayfly = this.couldFlyBefore; - player.abilities.setFlyingSpeed(this.flyingSpeedBefore); - if (this.force.get()) { - player.abilities.flying = false; - } - } - } -} diff --git a/src/main/java/ftbsc/bscv/module/self/FastInteract.java b/src/main/java/ftbsc/bscv/module/self/FastInteract.java deleted file mode 100644 index 15cba96..0000000 --- a/src/main/java/ftbsc/bscv/module/self/FastInteract.java +++ /dev/null @@ -1,46 +0,0 @@ -package ftbsc.bscv.module.self; - -import static ftbsc.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 ftbsc.bscv.module.QuickModule; -import ftbsc.bscv.ICommons; - -public class FastInteract extends QuickModule implements ICommons { - - Field delayField; - - public FastInteract(ForgeConfigSpec.Builder builder, CommandDispatcher dispatcher) { - super("FastInteract", Group.SELF, UNBOUND, builder, dispatcher); - } - - @Override - protected void onEnabled() { - try { - delayField = MC.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 (MC == null) return; - try { - this.delayField.set(MC, 0); - } catch (IllegalAccessException e) { - log("! failed accessing delay field"); - this.disable(); - } - } -} diff --git a/src/main/java/ftbsc/bscv/module/self/Freecam.java b/src/main/java/ftbsc/bscv/module/self/Freecam.java deleted file mode 100644 index 2161ce9..0000000 --- a/src/main/java/ftbsc/bscv/module/self/Freecam.java +++ /dev/null @@ -1,131 +0,0 @@ -package ftbsc.bscv.module.self; - -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.arguments.BoolArgumentType; -import com.mojang.brigadier.arguments.DoubleArgumentType; - -import ftbsc.bscv.BoSCoVicino; -import ftbsc.bscv.events.PacketEvent; -import ftbsc.bscv.ICommons; -import ftbsc.bscv.module.QuickModule; -import ftbsc.bscv.tools.Keyboard; -import net.minecraft.client.entity.player.RemoteClientPlayerEntity; -import net.minecraft.client.network.play.NetworkPlayerInfo; -import net.minecraft.command.CommandSource; -import net.minecraft.network.play.client.CPlayerPacket; -import net.minecraft.util.math.vector.Vector3d; -import net.minecraft.world.GameType; -import net.minecraftforge.common.ForgeConfigSpec; -import net.minecraftforge.event.TickEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; - -public class Freecam extends QuickModule implements ICommons { - - public final ForgeConfigSpec.ConfigValue log; - public final ForgeConfigSpec.ConfigValue speed; - public final ForgeConfigSpec.ConfigValue drift; - - private Vector3d prev_pos = new Vector3d(0.0, 0.0, 0.0); - private float prev_speed = 0.05f; - private GameType prev_gamemode = GameType.SURVIVAL; - private MockPlayer mock_player; - - public Freecam(ForgeConfigSpec.Builder builder, CommandDispatcher dispatcher) { - super("Freecam", Group.SELF, UNBOUND, builder, dispatcher); - - this.log = this.option( - "log", "log canceled packets", false, - BoolArgumentType.bool(), Boolean.class, - builder, dispatcher - ); - - this.speed = this.option( - "speed", "flight speed in freecam", 0.05, - DoubleArgumentType.doubleArg(0.0), Double.class, - builder, dispatcher - ); - - this.drift = this.option( - "drift", "allow inertia drift in freecam", true, - BoolArgumentType.bool(), Boolean.class, - builder, dispatcher - ); - } - - @SubscribeEvent - public void onPacket(PacketEvent event) { - if (MC.player == null) return; - if (event.outgoing && event.packet instanceof CPlayerPacket) { // TODO must ignore more packets than just this - if (this.log.get()) { - BoSCoVicino.log(String.format("[X] %s", event.packet.getClass().getName())); - } - event.setCanceled(true); - } - } - - @SubscribeEvent - protected void onTick(TickEvent.ClientTickEvent event) { - if (MC.player == null) return; - MC.player.abilities.setFlyingSpeed(this.speed.get().floatValue()); - if (!this.drift.get() && !Keyboard.isStrafing()) { - MC.player.setDeltaMovement(Vector3d.ZERO); - } - } - - @Override - protected void onEnabled() { - if (MC.player == null) { - BoSCoVicino.log("[!] Can only enable freecam while in-game"); - this.disable(); - } - - this.prev_speed = MC.player.abilities.getFlyingSpeed(); - this.prev_pos = MC.player.position(); - this.prev_gamemode = MC.gameMode.getPlayerMode(); - MC.gameMode.setLocalMode(GameType.SPECTATOR); - MC.player.noCulling = true; - if (MC.getConnection() != null) { - NetworkPlayerInfo info = MC.getConnection().getPlayerInfo( - MC.player.getGameProfile().getId() - ); - info.gameMode = GameType.SPECTATOR; // ACCESSTRANSFORMER: public net.minecraft.client.network.play.NetworkPlayerInfo field_178866_b - } - - this.mock_player = new MockPlayer(); - this.mock_player.setPosAndOldPos(this.prev_pos.x, this.prev_pos.y, this.prev_pos.z); - this.mock_player.setYBodyRot(MC.player.yBodyRot); - MC.level.addPlayer(-666, this.mock_player); - } - - @Override - protected void onDisabled() { - if (MC.player == null) return; - MC.gameMode.setLocalMode(this.prev_gamemode); - MC.player.noCulling = false; - MC.player.abilities.setFlyingSpeed(this.prev_speed); - if (MC.getConnection() != null) { - NetworkPlayerInfo info = MC.getConnection().getPlayerInfo( - MC.player.getGameProfile().getId() - ); - info.gameMode = this.prev_gamemode; // ACCESSTRANSFORMER: public net.minecraft.client.network.play.NetworkPlayerInfo field_178866_b - } - MC.player.setPos(this.prev_pos.x, this.prev_pos.y, this.prev_pos.z); - MC.player.setDeltaMovement(Vector3d.ZERO); - MC.level.removeEntity(this.mock_player.getId()); - this.mock_player = null; // get rid of reference - } - - private class MockPlayer extends RemoteClientPlayerEntity { - public MockPlayer() { - super(MC.level, MC.player.getGameProfile()); - this.setId(-666); // TODO hax - } - - @Override - public boolean isSpectator() { return false; } - - @Override - public boolean isCreative() { return false; } - - } -} diff --git a/src/main/java/ftbsc/bscv/module/vision/Fullbright.java b/src/main/java/ftbsc/bscv/module/vision/Fullbright.java deleted file mode 100644 index 21abca7..0000000 --- a/src/main/java/ftbsc/bscv/module/vision/Fullbright.java +++ /dev/null @@ -1,47 +0,0 @@ -package ftbsc.bscv.module.vision; - -import java.awt.event.KeyEvent; - -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.arguments.StringArgumentType; - -import net.minecraft.command.CommandSource; -import net.minecraft.potion.Effect; -import net.minecraft.potion.EffectInstance; -import net.minecraftforge.common.ForgeConfigSpec; -import net.minecraftforge.event.TickEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; - -import ftbsc.bscv.module.QuickModule; -import ftbsc.bscv.ICommons; - -public class Fullbright extends QuickModule implements ICommons { - - private final ForgeConfigSpec.ConfigValue mode; - - public Fullbright(ForgeConfigSpec.Builder builder, CommandDispatcher dispatcher) { - super("Fullbright", Group.VISION, KeyEvent.VK_V, builder, dispatcher); - - this.mode = this.option( - "mode", "either potion or potion", "potion", - StringArgumentType.string(), String.class, - builder, dispatcher - ); - } - - @SubscribeEvent - public void onTick(TickEvent.ClientTickEvent event) { - if (MC == null) return; - if (MC.player == null) return; - if (this.mode.get().equals("potion")) { - MC.player.addEffect(new EffectInstance(Effect.byId(16), 5204)); - } - } - - @Override - protected void onDisabled() { - if (this.mode.get().equals("potion")) { - MC.player.removeEffect(Effect.byId(16)); - } - } -} diff --git a/src/main/java/ftbsc/bscv/modules/HudModule.java b/src/main/java/ftbsc/bscv/modules/HudModule.java new file mode 100644 index 0000000..d1f0842 --- /dev/null +++ b/src/main/java/ftbsc/bscv/modules/HudModule.java @@ -0,0 +1,47 @@ +package ftbsc.bscv.module; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.DoubleArgumentType; +import com.mojang.brigadier.arguments.IntegerArgumentType; + +import ftbsc.bscv.tools.Anchor; +import net.minecraft.command.CommandSource; +import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.server.command.EnumArgument; + +public abstract class HudModule extends Module { + + public final ForgeConfigSpec.ConfigValue x; + public final ForgeConfigSpec.ConfigValue y; + public final ForgeConfigSpec.ConfigValue scale; + public final ForgeConfigSpec.EnumValue anchor; + + protected HudModule(String name, ForgeConfigSpec.Builder builder, CommandDispatcher dispatcher) { + super(name, Group.HUD, builder, dispatcher); + + this.x = this.option( + "x", "horizontal offset", 0, + IntegerArgumentType.integer(0), Integer.class, + builder, dispatcher + ); + + this.y = this.option( + "y", "vertical offset", 0, + IntegerArgumentType.integer(0), Integer.class, + builder, dispatcher + ); + + this.scale = this.option( + "scale", "scale of element", 1.0, + DoubleArgumentType.doubleArg(0.0), Double.class, + builder, dispatcher + ); + + this.anchor = this.optionEnum( + "anchor", "origin point for coordinates", Anchor.TOPLEFT, + EnumArgument.enumArgument(Anchor.class), Anchor.class, + builder, dispatcher + ); + } + +} diff --git a/src/main/java/ftbsc/bscv/modules/Module.java b/src/main/java/ftbsc/bscv/modules/Module.java new file mode 100644 index 0000000..84153a7 --- /dev/null +++ b/src/main/java/ftbsc/bscv/modules/Module.java @@ -0,0 +1,159 @@ +package ftbsc.bscv.module; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.ArgumentType; + +import ftbsc.bscv.BoSCoVicino; +import net.minecraft.command.CommandSource; +import net.minecraft.command.Commands; +import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.common.MinecraftForge; + +import static ftbsc.bscv.BoSCoVicino.log; + +public abstract class Module { + public enum Group { + SELF, + HUD, + BUILD, + DEFENSE, + VISION, + MOTION, + } + + public final String name; + public final Group group; + public final ForgeConfigSpec.ConfigValue enabled; + + protected Module(String name, Group group, ForgeConfigSpec.Builder builder, CommandDispatcher dispatcher) { + this.name = name; + this.group = group; + + builder.push(this.name.toLowerCase()); + this.enabled = builder + .comment(String.format("Enables %s", this.name)) + .define("enabled", false); + + dispatcher.register( + Commands.literal(this.name.toLowerCase()) + .then( + Commands.literal("toggle") + .executes(ctx -> { + this.toggle(); + return 1; + }) + ) + .executes(ctx -> { + log(String.format("=[ %s ]%s", this.name, this.enabled.get() ? "+" : "")); + // TODO: print all mod options! + return 1; + }) + ); + } + + public Module done(ForgeConfigSpec.Builder builder) { + builder.pop(); + return this; + } + + + // TODO can I merge these two option into one? Maybe redo with builder pattern? + + public > ForgeConfigSpec.EnumValue optionEnum( + String name, + String comment, + T fallback, + ArgumentType argument, + Class clazz, + ForgeConfigSpec.Builder builder, + CommandDispatcher dispatcher + ) { + ForgeConfigSpec.EnumValue conf = builder + .comment(comment) + .defineEnum(name, fallback); + + dispatcher.register( + Commands.literal(this.name.toLowerCase()) + .then( + Commands.literal(name) + .then( + Commands.argument(name, argument) + .executes( ctx -> { + T value = ctx.getArgument(name, clazz); + conf.set(value); + conf.save(); + log(String.format("> %s -> %s", String.join(".", conf.getPath()), conf.get().toString())); + return 1; + })) + .executes(ctx -> { + log(String.format("> %s: %s", String.join(".", conf.getPath()), conf.get().toString())); + return 1; + }) + ) + ); + + return conf; + } + + public ForgeConfigSpec.ConfigValue option( + String name, + String comment, + T fallback, + ArgumentType argument, + Class clazz, + ForgeConfigSpec.Builder builder, + CommandDispatcher dispatcher + ) { + ForgeConfigSpec.ConfigValue conf = builder + .comment(comment) + .define(name, fallback); + + dispatcher.register( + Commands.literal(this.name.toLowerCase()) + .then( + Commands.literal(name) + .then( + Commands.argument(name, argument) + .executes( ctx -> { + T value = ctx.getArgument(name, clazz); + conf.set(value); + conf.save(); + log(String.format("> %s -> %s", String.join(".", conf.getPath()), conf.get().toString())); + return 1; + })) + .executes(ctx -> { + log(String.format("> %s: %s", name, conf.get().toString())); + return 1; + }) + ) + ); + + return conf; + } + + protected void onEnabled() {} + protected void onDisabled() {} + + public final void toggle() { + if (this.enabled.get()) this.disable(); + else this.enable(); + } + + public final void enable() { + MinecraftForge.EVENT_BUS.register(this); + this.enabled.set(true); + // this.enabled.save(); + this.onEnabled(); + log(String.format("%s enabled", this.name)); + BoSCoVicino.LOGGER.info(String.format("%s enabled", this.name)); + } + + public final void disable() { + MinecraftForge.EVENT_BUS.unregister(this); + this.enabled.set(false); + // this.enabled.save(); + this.onDisabled(); + log(String.format("%s disabled", this.name)); + BoSCoVicino.LOGGER.info(String.format("%s disabled", this.name)); + } +} diff --git a/src/main/java/ftbsc/bscv/modules/QuickModule.java b/src/main/java/ftbsc/bscv/modules/QuickModule.java new file mode 100644 index 0000000..8eefa55 --- /dev/null +++ b/src/main/java/ftbsc/bscv/modules/QuickModule.java @@ -0,0 +1,90 @@ +package ftbsc.bscv.module; + +import com.mojang.brigadier.CommandDispatcher; + +import net.minecraft.client.settings.KeyBinding; +import net.minecraft.client.util.InputMappings; +import net.minecraft.command.CommandSource; +import net.minecraftforge.client.event.InputEvent; +import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.client.registry.ClientRegistry; + +import ftbsc.bscv.BoSCoVicino; + +// TODO rename +public class QuickModule extends Module { + + public static final int UNBOUND = InputMappings.UNKNOWN.getValue(); + + private class ToggleHook { + private final KeyBinding key; + private final Module mod; + private boolean debounce; + // TODO all examples show isPressed() to get a debounced value + // but it seems to be missing? making my own debounce for now + protected ToggleHook(KeyBinding key, Module mod) { + this.key = key; + this.mod = mod; + this.debounce = false; + } + + private void onInput() { + if (this.debounce) { + if (!this.key.isDown()) { + this.debounce = false; + } + } else { + if (this.key.isDown()) { + this.mod.toggle(); + this.debounce = true; + } + } + } + + @SubscribeEvent + public void onKeyPress(InputEvent.KeyInputEvent event) { this.onInput(); } + @SubscribeEvent + public void onKeyPress(InputEvent.MouseInputEvent event) { this.onInput(); } + } + + public final KeyBinding keybind; + + public QuickModule(String name, Group group, int default_key, ForgeConfigSpec.Builder builder, CommandDispatcher dispatcher) { + super(name, group, builder, dispatcher); + + this.keybind = new KeyBinding(key_name(name), default_key, key_category()); + ClientRegistry.registerKeyBinding(this.keybind); + + // register a separate subclass on the hook, so that it's always listening + MinecraftForge.EVENT_BUS.register(new ToggleHook(this.keybind, this)); + + // dispatcher.register( + // Commands.literal(this.name.toLowerCase()) + // .then( + // Commands.literal("bind") + // .then( + // Commands.argument("key", StringArgumentType.word()) + // .executes( ctx -> { + // this.keybind.setKey( + // InputMappings.getKey( // TODO it's not this easy! + // StringArgumentType.getString(ctx, "key") + // ) + // ); + // return 1; + // }) + // ) + // ) + // ); + } + + private static String key_name(String name) { + return String.format("key.%s.%s", BoSCoVicino.MOD_ID, name); + } + + private static String key_category() { + return String.format("key.category.%s", BoSCoVicino.MOD_ID); + } + +} diff --git a/src/main/java/ftbsc/bscv/modules/hud/ActiveModules.java b/src/main/java/ftbsc/bscv/modules/hud/ActiveModules.java new file mode 100644 index 0000000..cd0a197 --- /dev/null +++ b/src/main/java/ftbsc/bscv/modules/hud/ActiveModules.java @@ -0,0 +1,41 @@ +package ftbsc.bscv.module.hud; + +import static ftbsc.bscv.tools.Text.TextBuilder; + +import com.mojang.brigadier.CommandDispatcher; + +import ftbsc.bscv.BoSCoVicino; +import ftbsc.bscv.ICommons; +import net.minecraft.command.CommandSource; +import net.minecraftforge.client.event.RenderGameOverlayEvent; +import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; +import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import ftbsc.bscv.module.HudModule; +import ftbsc.bscv.module.Module; + +public class ActiveModules extends HudModule implements ICommons { + + public ActiveModules(ForgeConfigSpec.Builder builder, CommandDispatcher dispatcher) { + super("ActiveModules", builder, dispatcher); + } + + @SubscribeEvent + public void onRenderOverlay(RenderGameOverlayEvent event) { + if (event.getType() == ElementType.TEXT) { + int offset = 0; + for (Module m : BoSCoVicino.mods) { + if (m.enabled.get() && m.group != Group.HUD) { + TextBuilder() + .txt(String.format("%s <", m.name)) + .anchor(this.anchor.get()) + .x(this.x.get()) + .y(this.y.get() + offset) + .scale(this.scale.get()) + .render(event.getMatrixStack(), event.getWindow()); + offset += MC.font.lineHeight; + } + } + } + } +} diff --git a/src/main/java/ftbsc/bscv/modules/hud/Coordinates.java b/src/main/java/ftbsc/bscv/modules/hud/Coordinates.java new file mode 100644 index 0000000..b4e972c --- /dev/null +++ b/src/main/java/ftbsc/bscv/modules/hud/Coordinates.java @@ -0,0 +1,35 @@ +package ftbsc.bscv.module.hud; + +import com.mojang.brigadier.CommandDispatcher; + +import net.minecraft.command.CommandSource; +import net.minecraft.util.math.vector.Vector3d; +import net.minecraftforge.client.event.RenderGameOverlayEvent; +import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; +import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.eventbus.api.SubscribeEvent; + +import static ftbsc.bscv.tools.Text.TextBuilder; +import ftbsc.bscv.ICommons; +import ftbsc.bscv.module.HudModule; + +public class Coordinates extends HudModule implements ICommons { + + public Coordinates(ForgeConfigSpec.Builder builder, CommandDispatcher dispatcher) { + super("Coordinates", builder, dispatcher); + } + + @SubscribeEvent + public void onRenderOverlay(RenderGameOverlayEvent event) { + if (event.getType() == ElementType.TEXT && MC.player != null) { + Vector3d position = MC.player.position(); + TextBuilder() + .txt(String.format("[ X %.1f | %.1f Z ] %.1f Y", position.x(), position.z(), position.y())) + .anchor(this.anchor.get()) + .x(this.x.get()) + .y(this.y.get()) + .scale(this.scale.get()) + .render(event.getMatrixStack(), event.getWindow()); + } + } +} diff --git a/src/main/java/ftbsc/bscv/modules/hud/EntityList.java b/src/main/java/ftbsc/bscv/modules/hud/EntityList.java new file mode 100644 index 0000000..acb45b3 --- /dev/null +++ b/src/main/java/ftbsc/bscv/modules/hud/EntityList.java @@ -0,0 +1,59 @@ +package ftbsc.bscv.module.hud; + +import static ftbsc.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 ftbsc.bscv.ICommons; +import ftbsc.bscv.module.HudModule; +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 implements ICommons { + + 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 : MC.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 += MC.font.lineHeight; + } + } +} diff --git a/src/main/java/ftbsc/bscv/modules/hud/InfoDisplay.java b/src/main/java/ftbsc/bscv/modules/hud/InfoDisplay.java new file mode 100644 index 0000000..dd7103f --- /dev/null +++ b/src/main/java/ftbsc/bscv/modules/hud/InfoDisplay.java @@ -0,0 +1,135 @@ +package ftbsc.bscv.module.hud; + +import static ftbsc.bscv.tools.Text.TextBuilder; + +import java.util.ArrayDeque; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.BoolArgumentType; + +import ftbsc.bscv.BoSCoVicino; +import ftbsc.bscv.ICommons; +import ftbsc.bscv.module.HudModule; +import net.minecraft.client.Minecraft; +import net.minecraft.command.CommandSource; +import net.minecraft.util.math.vector.Vector3d; +import net.minecraft.util.text.Color; +import net.minecraft.util.text.Style; +import net.minecraftforge.client.event.RenderGameOverlayEvent; +import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; +import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.event.TickEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; + +public class InfoDisplay extends HudModule implements ICommons { + + + private Vector3d last_position = new Vector3d(0.0, 0.0, 0.0); + private double instant_speed = 0.0; + private double average_speed = 0.0; + private ArrayDeque history_speed = new ArrayDeque<>(); + + public final ForgeConfigSpec.ConfigValue logo; + public final ForgeConfigSpec.ConfigValue speed; + public final ForgeConfigSpec.ConfigValue time; + // public final ForgeConfigSpec.ConfigValue fps; + // public final ForgeConfigSpec.ConfigValue biome; + // public final ForgeConfigSpec.ConfigValue latency; + // public final ForgeConfigSpec.ConfigValue tps; + // public final ForgeConfigSpec.ConfigValue light; + // public final ForgeConfigSpec.ConfigValue saturation; + // public final ForgeConfigSpec.ConfigValue system_time; + // public final ForgeConfigSpec.ConfigValue damage_value; + // public final ForgeConfigSpec.ConfigValue effects_list; + // public final ForgeConfigSpec.ConfigValue item_quantity; + // public final ForgeConfigSpec.ConfigValue client_chunk_size; + + public InfoDisplay(ForgeConfigSpec.Builder builder, CommandDispatcher dispatcher) { + super("InfoDisplay", builder, dispatcher); + + this.logo = this.option( + "logo", "show logo at top of list", true, + BoolArgumentType.bool(), Boolean.class, + builder, dispatcher + ); + + this.speed = this.option( + "speed", "show speed meter", true, + BoolArgumentType.bool(), Boolean.class, + builder, dispatcher + ); + + this.time = this.option( + "time", "show world time", true, + BoolArgumentType.bool(), Boolean.class, + builder, dispatcher + ); + } + + @SubscribeEvent + public void onTick(TickEvent.ClientTickEvent event) { + if (!this.speed.get()) return; + if (MC.player != null) { + this.instant_speed = + this.last_position.distanceTo(MC.player.position()); + this.last_position = MC.player.position(); + } else { + this.instant_speed = 0.0; + } + + this.history_speed.push(this.instant_speed); + while (this.history_speed.size() >= 100) { // TODO customize this parameter + this.history_speed.pop(); + } + + double buf = 0.0; + for (double v : this.history_speed) { buf += v; } + this.average_speed = buf / this.history_speed.size(); + } + + @SubscribeEvent + public void onRenderOverlay(RenderGameOverlayEvent event) { + if (event.getType() != ElementType.TEXT) return; + + Minecraft mc = MC; + int offset = 0; + double scale = this.scale.get(); + if (this.logo.get()) { + TextBuilder() + .txt("BSCV") + .anchor(this.anchor.get()) + .x(this.x.get() / 4) + .y(this.y.get() / 4) + .style(Style.EMPTY.withColor(Color.fromRgb(12542314)).withBold(true)) + .scale(scale * 4.0) + .render(event.getMatrixStack(), event.getWindow()); + offset += mc.font.lineHeight * scale * 4.0; + } + + if (this.time.get()) { + long daytime = 0; + if (mc.level != null) { + daytime = mc.level.dayTime(); + } + TextBuilder() + .txt(String.format("> time: %d/1200 (%d day)", (daytime / 20) % 1200, daytime / (20 * 1200) )) + .anchor(this.anchor.get()) + .x(this.x.get()) + .y(this.y.get() + offset) + .scale(scale) + .render(event.getMatrixStack(), event.getWindow()); + offset += mc.font.lineHeight * scale; + } + + if (this.speed.get()) { + TextBuilder() + .txt(String.format("> speed: %.1f [%.1f] m/s", this.instant_speed * 20.0, this.average_speed * 20.0)) + .anchor(this.anchor.get()) + .x(this.x.get()) + .y(this.y.get() + offset) + .scale(scale) + .render(event.getMatrixStack(), event.getWindow()); + offset += mc.font.lineHeight * scale; + } + } +} diff --git a/src/main/java/ftbsc/bscv/modules/motion/VanillaFlight.java b/src/main/java/ftbsc/bscv/modules/motion/VanillaFlight.java new file mode 100644 index 0000000..f29699b --- /dev/null +++ b/src/main/java/ftbsc/bscv/modules/motion/VanillaFlight.java @@ -0,0 +1,109 @@ +package ftbsc.bscv.module.motion; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.BoolArgumentType; +import com.mojang.brigadier.arguments.DoubleArgumentType; +import com.mojang.brigadier.arguments.IntegerArgumentType; + +import ftbsc.bscv.BoSCoVicino; +import ftbsc.bscv.ICommons; +import ftbsc.bscv.module.QuickModule; +import net.minecraft.client.entity.player.ClientPlayerEntity; +import net.minecraft.command.CommandSource; +import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.event.TickEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; + +public class VanillaFlight extends QuickModule implements ICommons { + + public final ForgeConfigSpec.ConfigValue force; + public final ForgeConfigSpec.ConfigValue speed; + public final ForgeConfigSpec.ConfigValue antikick; + public final ForgeConfigSpec.ConfigValue antikick_magnitude; + public final ForgeConfigSpec.ConfigValue antikick_cycle; + + private final float minDescent = 0.03125f; + private final int maxTicks = 80; + private int tick = 0; + + public VanillaFlight(ForgeConfigSpec.Builder builder, CommandDispatcher dispatcher) { + super("VanillaFlight", Group.MOTION, UNBOUND, builder, dispatcher); + + this.force = this.option( + "force", "force enable flight on user", false, + BoolArgumentType.bool(), Boolean.class, + builder, dispatcher + ); + + this.speed = this.option( + "speed", "flight speed to set", 0.05, + DoubleArgumentType.doubleArg(0.0), Double.class, + builder, dispatcher + ); + + this.antikick = this.option( + "antikick", "prevent vanilla flight kick by descending", false, + BoolArgumentType.bool(), Boolean.class, + builder, dispatcher + ); + + this.antikick_magnitude = this.option( + "magnitude", "magnitude of antikick push", 1.0, + DoubleArgumentType.doubleArg(0.0), Double.class, + builder, dispatcher + ); + + this.antikick_cycle = this.option( + "cycle", "how often to run antikick routine", 0, + IntegerArgumentType.integer(0, 79), Integer.class, + builder, dispatcher + ); + } + + private boolean couldFlyBefore = false; + private float flyingSpeedBefore = 0.05f; + + @SubscribeEvent + public void onTick(TickEvent.ClientTickEvent event) { + ClientPlayerEntity player = MC.player; + if (player == null) return; + + player.abilities.mayfly = true; + player.abilities.setFlyingSpeed(this.speed.get().floatValue()); + if (this.force.get()) { + player.abilities.flying = true; + } + if (this.antikick.get()) { + if (this.tick != 0 && this.tick % (maxTicks - this.antikick_cycle.get()) == 0) { + player.push(0.0, -(this.antikick_magnitude.get() * minDescent), 0.0); + this.tick = 0; + } else if (this.tick == 0) { + player.push(0.0, this.antikick_magnitude.get() * minDescent, 0.0); + this.tick++; + } else { + this.tick++; + } + } + } + + @Override + protected void onEnabled() { + if (MC.player != null) { + this.couldFlyBefore = MC.player.abilities.mayfly; + this.flyingSpeedBefore = MC.player.abilities.getFlyingSpeed(); + BoSCoVicino.log(String.format("Flying speed before = %f", this.flyingSpeedBefore)); + } + } + + @Override + protected void onDisabled() { + ClientPlayerEntity player = MC.player; + if (player != null) { + player.abilities.mayfly = this.couldFlyBefore; + player.abilities.setFlyingSpeed(this.flyingSpeedBefore); + if (this.force.get()) { + player.abilities.flying = false; + } + } + } +} diff --git a/src/main/java/ftbsc/bscv/modules/self/FastInteract.java b/src/main/java/ftbsc/bscv/modules/self/FastInteract.java new file mode 100644 index 0000000..15cba96 --- /dev/null +++ b/src/main/java/ftbsc/bscv/modules/self/FastInteract.java @@ -0,0 +1,46 @@ +package ftbsc.bscv.module.self; + +import static ftbsc.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 ftbsc.bscv.module.QuickModule; +import ftbsc.bscv.ICommons; + +public class FastInteract extends QuickModule implements ICommons { + + Field delayField; + + public FastInteract(ForgeConfigSpec.Builder builder, CommandDispatcher dispatcher) { + super("FastInteract", Group.SELF, UNBOUND, builder, dispatcher); + } + + @Override + protected void onEnabled() { + try { + delayField = MC.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 (MC == null) return; + try { + this.delayField.set(MC, 0); + } catch (IllegalAccessException e) { + log("! failed accessing delay field"); + this.disable(); + } + } +} diff --git a/src/main/java/ftbsc/bscv/modules/self/Freecam.java b/src/main/java/ftbsc/bscv/modules/self/Freecam.java new file mode 100644 index 0000000..2161ce9 --- /dev/null +++ b/src/main/java/ftbsc/bscv/modules/self/Freecam.java @@ -0,0 +1,131 @@ +package ftbsc.bscv.module.self; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.BoolArgumentType; +import com.mojang.brigadier.arguments.DoubleArgumentType; + +import ftbsc.bscv.BoSCoVicino; +import ftbsc.bscv.events.PacketEvent; +import ftbsc.bscv.ICommons; +import ftbsc.bscv.module.QuickModule; +import ftbsc.bscv.tools.Keyboard; +import net.minecraft.client.entity.player.RemoteClientPlayerEntity; +import net.minecraft.client.network.play.NetworkPlayerInfo; +import net.minecraft.command.CommandSource; +import net.minecraft.network.play.client.CPlayerPacket; +import net.minecraft.util.math.vector.Vector3d; +import net.minecraft.world.GameType; +import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.event.TickEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; + +public class Freecam extends QuickModule implements ICommons { + + public final ForgeConfigSpec.ConfigValue log; + public final ForgeConfigSpec.ConfigValue speed; + public final ForgeConfigSpec.ConfigValue drift; + + private Vector3d prev_pos = new Vector3d(0.0, 0.0, 0.0); + private float prev_speed = 0.05f; + private GameType prev_gamemode = GameType.SURVIVAL; + private MockPlayer mock_player; + + public Freecam(ForgeConfigSpec.Builder builder, CommandDispatcher dispatcher) { + super("Freecam", Group.SELF, UNBOUND, builder, dispatcher); + + this.log = this.option( + "log", "log canceled packets", false, + BoolArgumentType.bool(), Boolean.class, + builder, dispatcher + ); + + this.speed = this.option( + "speed", "flight speed in freecam", 0.05, + DoubleArgumentType.doubleArg(0.0), Double.class, + builder, dispatcher + ); + + this.drift = this.option( + "drift", "allow inertia drift in freecam", true, + BoolArgumentType.bool(), Boolean.class, + builder, dispatcher + ); + } + + @SubscribeEvent + public void onPacket(PacketEvent event) { + if (MC.player == null) return; + if (event.outgoing && event.packet instanceof CPlayerPacket) { // TODO must ignore more packets than just this + if (this.log.get()) { + BoSCoVicino.log(String.format("[X] %s", event.packet.getClass().getName())); + } + event.setCanceled(true); + } + } + + @SubscribeEvent + protected void onTick(TickEvent.ClientTickEvent event) { + if (MC.player == null) return; + MC.player.abilities.setFlyingSpeed(this.speed.get().floatValue()); + if (!this.drift.get() && !Keyboard.isStrafing()) { + MC.player.setDeltaMovement(Vector3d.ZERO); + } + } + + @Override + protected void onEnabled() { + if (MC.player == null) { + BoSCoVicino.log("[!] Can only enable freecam while in-game"); + this.disable(); + } + + this.prev_speed = MC.player.abilities.getFlyingSpeed(); + this.prev_pos = MC.player.position(); + this.prev_gamemode = MC.gameMode.getPlayerMode(); + MC.gameMode.setLocalMode(GameType.SPECTATOR); + MC.player.noCulling = true; + if (MC.getConnection() != null) { + NetworkPlayerInfo info = MC.getConnection().getPlayerInfo( + MC.player.getGameProfile().getId() + ); + info.gameMode = GameType.SPECTATOR; // ACCESSTRANSFORMER: public net.minecraft.client.network.play.NetworkPlayerInfo field_178866_b + } + + this.mock_player = new MockPlayer(); + this.mock_player.setPosAndOldPos(this.prev_pos.x, this.prev_pos.y, this.prev_pos.z); + this.mock_player.setYBodyRot(MC.player.yBodyRot); + MC.level.addPlayer(-666, this.mock_player); + } + + @Override + protected void onDisabled() { + if (MC.player == null) return; + MC.gameMode.setLocalMode(this.prev_gamemode); + MC.player.noCulling = false; + MC.player.abilities.setFlyingSpeed(this.prev_speed); + if (MC.getConnection() != null) { + NetworkPlayerInfo info = MC.getConnection().getPlayerInfo( + MC.player.getGameProfile().getId() + ); + info.gameMode = this.prev_gamemode; // ACCESSTRANSFORMER: public net.minecraft.client.network.play.NetworkPlayerInfo field_178866_b + } + MC.player.setPos(this.prev_pos.x, this.prev_pos.y, this.prev_pos.z); + MC.player.setDeltaMovement(Vector3d.ZERO); + MC.level.removeEntity(this.mock_player.getId()); + this.mock_player = null; // get rid of reference + } + + private class MockPlayer extends RemoteClientPlayerEntity { + public MockPlayer() { + super(MC.level, MC.player.getGameProfile()); + this.setId(-666); // TODO hax + } + + @Override + public boolean isSpectator() { return false; } + + @Override + public boolean isCreative() { return false; } + + } +} diff --git a/src/main/java/ftbsc/bscv/modules/vision/Fullbright.java b/src/main/java/ftbsc/bscv/modules/vision/Fullbright.java new file mode 100644 index 0000000..21abca7 --- /dev/null +++ b/src/main/java/ftbsc/bscv/modules/vision/Fullbright.java @@ -0,0 +1,47 @@ +package ftbsc.bscv.module.vision; + +import java.awt.event.KeyEvent; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.StringArgumentType; + +import net.minecraft.command.CommandSource; +import net.minecraft.potion.Effect; +import net.minecraft.potion.EffectInstance; +import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.event.TickEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; + +import ftbsc.bscv.module.QuickModule; +import ftbsc.bscv.ICommons; + +public class Fullbright extends QuickModule implements ICommons { + + private final ForgeConfigSpec.ConfigValue mode; + + public Fullbright(ForgeConfigSpec.Builder builder, CommandDispatcher dispatcher) { + super("Fullbright", Group.VISION, KeyEvent.VK_V, builder, dispatcher); + + this.mode = this.option( + "mode", "either potion or potion", "potion", + StringArgumentType.string(), String.class, + builder, dispatcher + ); + } + + @SubscribeEvent + public void onTick(TickEvent.ClientTickEvent event) { + if (MC == null) return; + if (MC.player == null) return; + if (this.mode.get().equals("potion")) { + MC.player.addEffect(new EffectInstance(Effect.byId(16), 5204)); + } + } + + @Override + protected void onDisabled() { + if (this.mode.get().equals("potion")) { + MC.player.removeEffect(Effect.byId(16)); + } + } +} -- cgit v1.2.3-56-ga3b1