From 20125f6fb5f49378752332168cf5d50baec3cda1 Mon Sep 17 00:00:00 2001 From: alemidev Date: Mon, 30 Jan 2023 23:36:10 +0100 Subject: chore: refactor modules -> module --- src/main/java/co/fantabos/bscv/BoSCoVicino.java | 9 +- .../java/co/fantabos/bscv/module/HudModule.java | 48 +++++++ src/main/java/co/fantabos/bscv/module/Module.java | 154 +++++++++++++++++++++ .../co/fantabos/bscv/module/hud/ActiveModules.java | 40 ++++++ .../co/fantabos/bscv/module/hud/Coordinates.java | 37 +++++ .../co/fantabos/bscv/module/hud/EntityList.java | 59 ++++++++ .../fantabos/bscv/module/motion/VanillaFlight.java | 44 ++++++ .../co/fantabos/bscv/module/self/FastInteract.java | 46 ++++++ .../co/fantabos/bscv/module/vision/Fullbright.java | 47 +++++++ .../java/co/fantabos/bscv/modules/HudModule.java | 48 ------- src/main/java/co/fantabos/bscv/modules/Module.java | 153 -------------------- .../fantabos/bscv/modules/hud/ActiveModules.java | 39 ------ .../co/fantabos/bscv/modules/hud/Coordinates.java | 36 ----- .../co/fantabos/bscv/modules/hud/EntityList.java | 58 -------- .../bscv/modules/motion/VanillaFlight.java | 40 ------ .../fantabos/bscv/modules/self/FastInteract.java | 46 ------ .../fantabos/bscv/modules/vision/Fullbright.java | 45 ------ 17 files changed, 480 insertions(+), 469 deletions(-) create mode 100644 src/main/java/co/fantabos/bscv/module/HudModule.java create mode 100644 src/main/java/co/fantabos/bscv/module/Module.java create mode 100644 src/main/java/co/fantabos/bscv/module/hud/ActiveModules.java create mode 100644 src/main/java/co/fantabos/bscv/module/hud/Coordinates.java create mode 100644 src/main/java/co/fantabos/bscv/module/hud/EntityList.java create mode 100644 src/main/java/co/fantabos/bscv/module/motion/VanillaFlight.java create mode 100644 src/main/java/co/fantabos/bscv/module/self/FastInteract.java create mode 100644 src/main/java/co/fantabos/bscv/module/vision/Fullbright.java delete mode 100644 src/main/java/co/fantabos/bscv/modules/HudModule.java delete mode 100644 src/main/java/co/fantabos/bscv/modules/Module.java delete mode 100644 src/main/java/co/fantabos/bscv/modules/hud/ActiveModules.java delete mode 100644 src/main/java/co/fantabos/bscv/modules/hud/Coordinates.java delete mode 100644 src/main/java/co/fantabos/bscv/modules/hud/EntityList.java delete mode 100644 src/main/java/co/fantabos/bscv/modules/motion/VanillaFlight.java delete mode 100644 src/main/java/co/fantabos/bscv/modules/self/FastInteract.java delete mode 100644 src/main/java/co/fantabos/bscv/modules/vision/Fullbright.java (limited to 'src/main/java') diff --git a/src/main/java/co/fantabos/bscv/BoSCoVicino.java b/src/main/java/co/fantabos/bscv/BoSCoVicino.java index 10ae94b..a7dfb55 100644 --- a/src/main/java/co/fantabos/bscv/BoSCoVicino.java +++ b/src/main/java/co/fantabos/bscv/BoSCoVicino.java @@ -27,10 +27,11 @@ import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; -import co.fantabos.bscv.modules.vision.*; -import co.fantabos.bscv.modules.motion.*; -import co.fantabos.bscv.modules.self.*; -import co.fantabos.bscv.modules.hud.*; +import co.fantabos.bscv.module.Module; +import co.fantabos.bscv.module.vision.*; +import co.fantabos.bscv.module.motion.*; +import co.fantabos.bscv.module.self.*; +import co.fantabos.bscv.module.hud.*; // The value here should match an entry in the META-INF/mods.toml file @Mod("bscv") diff --git a/src/main/java/co/fantabos/bscv/module/HudModule.java b/src/main/java/co/fantabos/bscv/module/HudModule.java new file mode 100644 index 0000000..61abcc9 --- /dev/null +++ b/src/main/java/co/fantabos/bscv/module/HudModule.java @@ -0,0 +1,48 @@ +package co.fantabos.bscv.module; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.DoubleArgumentType; +import com.mojang.brigadier.arguments.IntegerArgumentType; + +import co.fantabos.bscv.module.Module; +import co.fantabos.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/co/fantabos/bscv/module/Module.java b/src/main/java/co/fantabos/bscv/module/Module.java new file mode 100644 index 0000000..67beb13 --- /dev/null +++ b/src/main/java/co/fantabos/bscv/module/Module.java @@ -0,0 +1,154 @@ +package co.fantabos.bscv.module; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.ArgumentType; + +import co.fantabos.bscv.BoSCoVicino; +import net.minecraft.command.CommandSource; +import net.minecraft.command.Commands; +import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.common.MinecraftForge; + +import static co.fantabos.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; + }) + ); + } + + + // 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/co/fantabos/bscv/module/hud/ActiveModules.java b/src/main/java/co/fantabos/bscv/module/hud/ActiveModules.java new file mode 100644 index 0000000..ea748b2 --- /dev/null +++ b/src/main/java/co/fantabos/bscv/module/hud/ActiveModules.java @@ -0,0 +1,40 @@ +package co.fantabos.bscv.module.hud; + +import static co.fantabos.bscv.tools.Text.TextBuilder; + +import com.mojang.brigadier.CommandDispatcher; + +import co.fantabos.bscv.BoSCoVicino; +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 co.fantabos.bscv.module.HudModule; +import co.fantabos.bscv.module.Module; + +public class ActiveModules extends HudModule { + + 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 += BoSCoVicino.minecraft.font.lineHeight; + } + } + } + } +} diff --git a/src/main/java/co/fantabos/bscv/module/hud/Coordinates.java b/src/main/java/co/fantabos/bscv/module/hud/Coordinates.java new file mode 100644 index 0000000..bc1b73f --- /dev/null +++ b/src/main/java/co/fantabos/bscv/module/hud/Coordinates.java @@ -0,0 +1,37 @@ +package co.fantabos.bscv.module.hud; + +import static co.fantabos.bscv.tools.Text.TextBuilder; + +import com.mojang.brigadier.CommandDispatcher; + +import co.fantabos.bscv.BoSCoVicino; +import co.fantabos.bscv.module.HudModule; +import net.minecraft.client.Minecraft; +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; + +public class Coordinates extends HudModule { + + public Coordinates(ForgeConfigSpec.Builder builder, CommandDispatcher dispatcher) { + super("Coordinates", builder, dispatcher); + } + + @SubscribeEvent + public void onRenderOverlay(RenderGameOverlayEvent event) { + Minecraft mc = BoSCoVicino.minecraft; + 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/co/fantabos/bscv/module/hud/EntityList.java b/src/main/java/co/fantabos/bscv/module/hud/EntityList.java new file mode 100644 index 0000000..8480e82 --- /dev/null +++ b/src/main/java/co/fantabos/bscv/module/hud/EntityList.java @@ -0,0 +1,59 @@ +package co.fantabos.bscv.module.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 co.fantabos.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 { + + 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; + } + } +} diff --git a/src/main/java/co/fantabos/bscv/module/motion/VanillaFlight.java b/src/main/java/co/fantabos/bscv/module/motion/VanillaFlight.java new file mode 100644 index 0000000..2b20239 --- /dev/null +++ b/src/main/java/co/fantabos/bscv/module/motion/VanillaFlight.java @@ -0,0 +1,44 @@ +package co.fantabos.bscv.module.motion; + +import com.mojang.brigadier.CommandDispatcher; + +import co.fantabos.bscv.BoSCoVicino; +import co.fantabos.bscv.module.QuickModule; +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 { + + public final ForgeConfigSpec.ConfigValue force; + + public VanillaFlight(ForgeConfigSpec.Builder builder, CommandDispatcher dispatcher) { + super("VanillaFlight", Group.MOTION, -1, builder, dispatcher); + + + } + + private boolean couldFlyBefore = false; + + @SubscribeEvent + public void onTick(TickEvent.ClientTickEvent event) { + if (BoSCoVicino.minecraft.player != null) { + BoSCoVicino.minecraft.player.abilities.mayfly = true; + } + } + + @Override + protected void onEnabled() { + if (BoSCoVicino.minecraft.player != null) { + this.couldFlyBefore = BoSCoVicino.minecraft.player.abilities.mayfly; + } + } + + @Override + protected void onDisabled() { + if (BoSCoVicino.minecraft.player != null) { + BoSCoVicino.minecraft.player.abilities.mayfly = this.couldFlyBefore; + } + } +} diff --git a/src/main/java/co/fantabos/bscv/module/self/FastInteract.java b/src/main/java/co/fantabos/bscv/module/self/FastInteract.java new file mode 100644 index 0000000..1227aab --- /dev/null +++ b/src/main/java/co/fantabos/bscv/module/self/FastInteract.java @@ -0,0 +1,46 @@ +package co.fantabos.bscv.module.self; + +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.QuickModule; +import co.fantabos.bscv.BoSCoVicino; + +public class FastInteract extends QuickModule { + + Field delayField; + + public FastInteract(ForgeConfigSpec.Builder builder, CommandDispatcher dispatcher) { + super("FastInteract", Group.SELF, -1, 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/module/vision/Fullbright.java b/src/main/java/co/fantabos/bscv/module/vision/Fullbright.java new file mode 100644 index 0000000..77bdbce --- /dev/null +++ b/src/main/java/co/fantabos/bscv/module/vision/Fullbright.java @@ -0,0 +1,47 @@ +package co.fantabos.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 co.fantabos.bscv.module.QuickModule; +import co.fantabos.bscv.BoSCoVicino; + +public class Fullbright extends QuickModule { + + 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 (BoSCoVicino.minecraft == null) return; + if (BoSCoVicino.minecraft.player == null) return; + if (this.mode.get().equals("potion")) { + BoSCoVicino.minecraft.player.addEffect(new EffectInstance(Effect.byId(16), 5204)); + } + } + + @Override + protected void onDisabled() { + if (this.mode.get().equals("potion")) { + BoSCoVicino.minecraft.player.removeEffect(Effect.byId(16)); + } + } +} diff --git a/src/main/java/co/fantabos/bscv/modules/HudModule.java b/src/main/java/co/fantabos/bscv/modules/HudModule.java deleted file mode 100644 index 0327d78..0000000 --- a/src/main/java/co/fantabos/bscv/modules/HudModule.java +++ /dev/null @@ -1,48 +0,0 @@ -package co.fantabos.bscv.modules.hud; - -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.arguments.DoubleArgumentType; -import com.mojang.brigadier.arguments.IntegerArgumentType; - -import co.fantabos.bscv.Module; -import co.fantabos.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/co/fantabos/bscv/modules/Module.java b/src/main/java/co/fantabos/bscv/modules/Module.java deleted file mode 100644 index c6f4522..0000000 --- a/src/main/java/co/fantabos/bscv/modules/Module.java +++ /dev/null @@ -1,153 +0,0 @@ -package co.fantabos.bscv; - -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.arguments.ArgumentType; - -import net.minecraft.command.CommandSource; -import net.minecraft.command.Commands; -import net.minecraftforge.common.ForgeConfigSpec; -import net.minecraftforge.common.MinecraftForge; - -import static co.fantabos.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; - }) - ); - } - - - // 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/co/fantabos/bscv/modules/hud/ActiveModules.java b/src/main/java/co/fantabos/bscv/modules/hud/ActiveModules.java deleted file mode 100644 index ad195b8..0000000 --- a/src/main/java/co/fantabos/bscv/modules/hud/ActiveModules.java +++ /dev/null @@ -1,39 +0,0 @@ -package co.fantabos.bscv.modules.hud; - -import static co.fantabos.bscv.tools.Text.TextBuilder; - -import com.mojang.brigadier.CommandDispatcher; - -import co.fantabos.bscv.BoSCoVicino; -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 co.fantabos.bscv.Module; - -public class ActiveModules extends HudModule { - - 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 += BoSCoVicino.minecraft.font.lineHeight; - } - } - } - } -} diff --git a/src/main/java/co/fantabos/bscv/modules/hud/Coordinates.java b/src/main/java/co/fantabos/bscv/modules/hud/Coordinates.java deleted file mode 100644 index b7e0225..0000000 --- a/src/main/java/co/fantabos/bscv/modules/hud/Coordinates.java +++ /dev/null @@ -1,36 +0,0 @@ -package co.fantabos.bscv.modules.hud; - -import static co.fantabos.bscv.tools.Text.TextBuilder; - -import com.mojang.brigadier.CommandDispatcher; - -import co.fantabos.bscv.BoSCoVicino; -import net.minecraft.client.Minecraft; -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; - -public class Coordinates extends HudModule { - - public Coordinates(ForgeConfigSpec.Builder builder, CommandDispatcher dispatcher) { - super("Coordinates", builder, dispatcher); - } - - @SubscribeEvent - public void onRenderOverlay(RenderGameOverlayEvent event) { - Minecraft mc = BoSCoVicino.minecraft; - 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/co/fantabos/bscv/modules/hud/EntityList.java b/src/main/java/co/fantabos/bscv/modules/hud/EntityList.java deleted file mode 100644 index ee013b7..0000000 --- a/src/main/java/co/fantabos/bscv/modules/hud/EntityList.java +++ /dev/null @@ -1,58 +0,0 @@ -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; - } - } -} diff --git a/src/main/java/co/fantabos/bscv/modules/motion/VanillaFlight.java b/src/main/java/co/fantabos/bscv/modules/motion/VanillaFlight.java deleted file mode 100644 index 070b123..0000000 --- a/src/main/java/co/fantabos/bscv/modules/motion/VanillaFlight.java +++ /dev/null @@ -1,40 +0,0 @@ -package co.fantabos.bscv.modules.motion; - -import com.mojang.brigadier.CommandDispatcher; - -import co.fantabos.bscv.BoSCoVicino; -import co.fantabos.bscv.Module; -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 Module { - - public VanillaFlight(ForgeConfigSpec.Builder builder, CommandDispatcher dispatcher) { - super("VanillaFlight", Group.MOTION, builder, dispatcher); - } - - private boolean couldFlyBefore = false; - - @SubscribeEvent - public void onTick(TickEvent.ClientTickEvent event) { - if (BoSCoVicino.minecraft.player != null) { - BoSCoVicino.minecraft.player.abilities.mayfly = true; - } - } - - @Override - protected void onEnabled() { - if (BoSCoVicino.minecraft.player != null) { - this.couldFlyBefore = BoSCoVicino.minecraft.player.abilities.mayfly; - } - } - - @Override - protected void onDisabled() { - if (BoSCoVicino.minecraft.player != null) { - BoSCoVicino.minecraft.player.abilities.mayfly = this.couldFlyBefore; - } - } -} diff --git a/src/main/java/co/fantabos/bscv/modules/self/FastInteract.java b/src/main/java/co/fantabos/bscv/modules/self/FastInteract.java deleted file mode 100644 index 3d9d034..0000000 --- a/src/main/java/co/fantabos/bscv/modules/self/FastInteract.java +++ /dev/null @@ -1,46 +0,0 @@ -package co.fantabos.bscv.modules.self; - -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.SELF, 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/vision/Fullbright.java b/src/main/java/co/fantabos/bscv/modules/vision/Fullbright.java deleted file mode 100644 index 70199d9..0000000 --- a/src/main/java/co/fantabos/bscv/modules/vision/Fullbright.java +++ /dev/null @@ -1,45 +0,0 @@ -package co.fantabos.bscv.modules.vision; - -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 co.fantabos.bscv.Module; -import co.fantabos.bscv.BoSCoVicino; - -public class Fullbright extends Module { - - private final ForgeConfigSpec.ConfigValue mode; - - public Fullbright(ForgeConfigSpec.Builder builder, CommandDispatcher dispatcher) { - super("Fullbright", Group.VISION, 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 (BoSCoVicino.minecraft == null) return; - if (BoSCoVicino.minecraft.player == null) return; - if (this.mode.get().equals("potion")) { - BoSCoVicino.minecraft.player.addEffect(new EffectInstance(Effect.byId(16), 5204)); - } - } - - @Override - protected void onDisabled() { - if (this.mode.get().equals("potion")) { - BoSCoVicino.minecraft.player.removeEffect(Effect.byId(16)); - } - } -} -- cgit v1.2.3-56-ga3b1