From 914c47dfb3b707be1ff68dc6127809f74a4bfb4d Mon Sep 17 00:00:00 2001 From: alemidev Date: Wed, 1 Feb 2023 20:30:37 +0100 Subject: fix: older version works on java 8 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 076ad3f..337221d 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { } dependencies { classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true - classpath "com.palantir.gradle.gitversion:gradle-git-version:0.15.0" + classpath "com.palantir.gradle.gitversion:gradle-git-version:0.13.0" } } apply plugin: 'net.minecraftforge.gradle' -- cgit v1.2.3-56-ga3b1 From 3a84231cb69eaca41285810f1e942a85838a39bd Mon Sep 17 00:00:00 2001 From: alemidev Date: Wed, 1 Feb 2023 20:37:21 +0100 Subject: i fucking did it --- src/main/java/bscv/BoSCoVicino.java | 181 +++++++++++++++++++++ src/main/java/bscv/module/HudModule.java | 48 ++++++ src/main/java/bscv/module/Module.java | 154 ++++++++++++++++++ src/main/java/bscv/module/QuickModule.java | 92 +++++++++++ src/main/java/bscv/module/hud/ActiveModules.java | 40 +++++ src/main/java/bscv/module/hud/Coordinates.java | 37 +++++ src/main/java/bscv/module/hud/EntityList.java | 59 +++++++ src/main/java/bscv/module/hud/InfoDisplay.java | 134 +++++++++++++++ .../java/bscv/module/motion/VanillaFlight.java | 108 ++++++++++++ src/main/java/bscv/module/self/FastInteract.java | 46 ++++++ src/main/java/bscv/module/vision/Fullbright.java | 47 ++++++ src/main/java/bscv/tools/Anchor.java | 51 ++++++ src/main/java/bscv/tools/Text.java | 90 ++++++++++ src/main/java/bscv/tools/Utils.java | 10 ++ src/main/java/co/fantabos/bscv/BoSCoVicino.java | 181 --------------------- .../java/co/fantabos/bscv/module/HudModule.java | 48 ------ src/main/java/co/fantabos/bscv/module/Module.java | 154 ------------------ .../java/co/fantabos/bscv/module/QuickModule.java | 91 ----------- .../co/fantabos/bscv/module/hud/ActiveModules.java | 40 ----- .../co/fantabos/bscv/module/hud/Coordinates.java | 37 ----- .../co/fantabos/bscv/module/hud/EntityList.java | 59 ------- .../co/fantabos/bscv/module/hud/InfoDisplay.java | 134 --------------- .../fantabos/bscv/module/motion/VanillaFlight.java | 108 ------------ .../co/fantabos/bscv/module/self/FastInteract.java | 46 ------ .../co/fantabos/bscv/module/vision/Fullbright.java | 47 ------ src/main/java/co/fantabos/bscv/tools/Anchor.java | 51 ------ src/main/java/co/fantabos/bscv/tools/Text.java | 90 ---------- src/main/java/co/fantabos/bscv/tools/Utils.java | 10 -- 28 files changed, 1097 insertions(+), 1096 deletions(-) create mode 100644 src/main/java/bscv/BoSCoVicino.java create mode 100644 src/main/java/bscv/module/HudModule.java create mode 100644 src/main/java/bscv/module/Module.java create mode 100644 src/main/java/bscv/module/QuickModule.java create mode 100644 src/main/java/bscv/module/hud/ActiveModules.java create mode 100644 src/main/java/bscv/module/hud/Coordinates.java create mode 100644 src/main/java/bscv/module/hud/EntityList.java create mode 100644 src/main/java/bscv/module/hud/InfoDisplay.java create mode 100644 src/main/java/bscv/module/motion/VanillaFlight.java create mode 100644 src/main/java/bscv/module/self/FastInteract.java create mode 100644 src/main/java/bscv/module/vision/Fullbright.java create mode 100644 src/main/java/bscv/tools/Anchor.java create mode 100644 src/main/java/bscv/tools/Text.java create mode 100644 src/main/java/bscv/tools/Utils.java delete mode 100644 src/main/java/co/fantabos/bscv/BoSCoVicino.java delete mode 100644 src/main/java/co/fantabos/bscv/module/HudModule.java delete mode 100644 src/main/java/co/fantabos/bscv/module/Module.java delete mode 100644 src/main/java/co/fantabos/bscv/module/QuickModule.java delete mode 100644 src/main/java/co/fantabos/bscv/module/hud/ActiveModules.java delete mode 100644 src/main/java/co/fantabos/bscv/module/hud/Coordinates.java delete mode 100644 src/main/java/co/fantabos/bscv/module/hud/EntityList.java delete mode 100644 src/main/java/co/fantabos/bscv/module/hud/InfoDisplay.java delete mode 100644 src/main/java/co/fantabos/bscv/module/motion/VanillaFlight.java delete mode 100644 src/main/java/co/fantabos/bscv/module/self/FastInteract.java delete mode 100644 src/main/java/co/fantabos/bscv/module/vision/Fullbright.java delete mode 100644 src/main/java/co/fantabos/bscv/tools/Anchor.java delete mode 100644 src/main/java/co/fantabos/bscv/tools/Text.java delete mode 100644 src/main/java/co/fantabos/bscv/tools/Utils.java diff --git a/src/main/java/bscv/BoSCoVicino.java b/src/main/java/bscv/BoSCoVicino.java new file mode 100644 index 0000000..c198c46 --- /dev/null +++ b/src/main/java/bscv/BoSCoVicino.java @@ -0,0 +1,181 @@ +package bscv; + +import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.player.ClientPlayerEntity; +import net.minecraft.command.CommandSource; +import net.minecraft.command.Commands; +import net.minecraft.util.text.StringTextComponent; +import net.minecraftforge.client.event.ClientChatEvent; +import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.RegistryEvent; +import net.minecraftforge.event.world.WorldEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.ModLoadingContext; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.config.ModConfig.Type; +import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; +import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.exceptions.CommandSyntaxException; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +import bscv.module.Module; +import bscv.module.vision.*; +import bscv.module.motion.*; +import bscv.module.self.*; +import bscv.module.hud.*; + +// The value here should match an entry in the META-INF/mods.toml file +@Mod("bscv") +public class BoSCoVicino { + public static String MOD_ID = "bscv"; + + // Directly reference a log4j logger. + public static final Logger LOGGER = LogManager.getLogger(); + + public static Minecraft minecraft; + + public static List mods; + + private final CommandDispatcher dispatcher = new CommandDispatcher<>(); + + public static ForgeConfigSpec spec; + + public BoSCoVicino() { + // Register the setup method for modloading + FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientSetup); + + // Store minecraft instance + BoSCoVicino.minecraft = Minecraft.getInstance(); + + // load and register mods + BoSCoVicino.mods = new ArrayList(); + + ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder(); + + // TODO also push! + // modules cannot easily pop from their builder, but here we can't easily get + // the module name yet. We should push and pop the builder ourselves and not + // bother the modules themselves. + + BoSCoVicino.mods.add(new Fullbright(builder, this.dispatcher)); + builder.pop(); + BoSCoVicino.mods.add(new VanillaFlight(builder, this.dispatcher)); + builder.pop(); + BoSCoVicino.mods.add(new FastInteract(builder, this.dispatcher)); + builder.pop(); + BoSCoVicino.mods.add(new InfoDisplay(builder, this.dispatcher)); + builder.pop(); + BoSCoVicino.mods.add(new Coordinates(builder, this.dispatcher)); + builder.pop(); + BoSCoVicino.mods.add(new EntityList(builder, this.dispatcher)); + builder.pop(); + BoSCoVicino.mods.add(new ActiveModules(builder, this.dispatcher)); + builder.pop(); + + BoSCoVicino.spec = builder.build(); + + // register config handler + ModLoadingContext.get().registerConfig(Type.CLIENT, spec, "bscv.toml"); + + // Register ourselves for server and other game events we are interested in + MinecraftForge.EVENT_BUS.register(this); + } + + public static void log(String message) { + BoSCoVicino.minecraft.gui.getChat().addMessage(new StringTextComponent(message)); + } + + private void clientSetup(final FMLClientSetupEvent event) { + LOGGER.info("Initializing modules"); + + for (Module m : BoSCoVicino.mods) { + if (m.enabled.get()) m.enable(); + } + + // TEMPORARY! add command to regenerate suggestions + dispatcher.register( + Commands.literal("hints") + .executes(ctx -> { + ClientPlayerEntity player = BoSCoVicino.minecraft.player; + if (player != null) { + try { + Field commands = player.connection.getClass().getDeclaredField("field_195517_n"); // "commands", it's obfuscated + commands.setAccessible(true); + commands.set(player.connection, this.dispatcher); + LOGGER.info("Rebuild HINTS"); + log("> rebuilt hints"); + return 1; + } catch (NoSuchFieldException e) { + log("! no such field error"); + LOGGER.error("No such field Exception while rebuilding hints"); + return 0; + } catch (IllegalAccessException e) { + log("! illegal access error"); + LOGGER.error("Illegal Access Exception while rebuilding hints"); + return 0; + } + } else { + log("! local player is NULL"); + LOGGER.error("Local player is NULL"); + return 0; + } + }) + ); + } + + @SubscribeEvent + public void onClientChatEvent(ClientChatEvent event) { + if (event.getMessage().startsWith("/")) { + CommandSource source = BoSCoVicino.minecraft.player.createCommandSourceStack(); // TODO player could be NULL + try { + LOGGER.info(String.format("Running command %s", event.getMessage())); + this.dispatcher.execute(event.getMessage().substring(1), source); + BoSCoVicino.minecraft.gui.getChat().addRecentChat(event.getMessage()); + event.setCanceled(true); + } catch (CommandSyntaxException e) { + LOGGER.error(String.format("Syntax error in command : %s", e.toString())); + } + } + } + + @SubscribeEvent + public void onWorldLoad(WorldEvent.Load event) { + // TEMPORARY! add command to regenerate suggestions + ClientPlayerEntity player = BoSCoVicino.minecraft.player; + if (player != null) { + try { + Field commands = player.connection.getClass().getDeclaredField("field_195517_n"); // "commands", it's obfuscated + commands.setAccessible(true); + commands.set(player.connection, this.dispatcher); + LOGGER.info("Rebuild HINTS"); + log("> rebuilt hints"); + } catch (NoSuchFieldException e) { + LOGGER.error("No such field Exception while rebuilding hints"); + } catch (IllegalAccessException e) { + LOGGER.error("Illegal Access Exception while rebuilding hints"); + } + } else { + LOGGER.error("Local player is NULL"); + } + } + + // You can use EventBusSubscriber to automatically subscribe events on the contained class (this is subscribing to the MOD + // Event bus for receiving Registry Events) + @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD) + public static class RegistryEvents { + @SubscribeEvent + public static void onBlocksRegistry(final RegistryEvent.Register blockRegistryEvent) { + // register a new block here + LOGGER.info("HELLO from Register Block"); + } + } +} diff --git a/src/main/java/bscv/module/HudModule.java b/src/main/java/bscv/module/HudModule.java new file mode 100644 index 0000000..529001e --- /dev/null +++ b/src/main/java/bscv/module/HudModule.java @@ -0,0 +1,48 @@ +package bscv.module; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.DoubleArgumentType; +import com.mojang.brigadier.arguments.IntegerArgumentType; + +import bscv.module.Module; +import 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/bscv/module/Module.java b/src/main/java/bscv/module/Module.java new file mode 100644 index 0000000..c840ebf --- /dev/null +++ b/src/main/java/bscv/module/Module.java @@ -0,0 +1,154 @@ +package bscv.module; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.ArgumentType; + +import bscv.BoSCoVicino; +import net.minecraft.command.CommandSource; +import net.minecraft.command.Commands; +import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.common.MinecraftForge; + +import static 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/bscv/module/QuickModule.java b/src/main/java/bscv/module/QuickModule.java new file mode 100644 index 0000000..2a7ff6c --- /dev/null +++ b/src/main/java/bscv/module/QuickModule.java @@ -0,0 +1,92 @@ +package bscv.module; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.StringArgumentType; + +import net.minecraft.client.settings.KeyBinding; +import net.minecraft.client.util.InputMappings; +import net.minecraft.command.CommandSource; +import net.minecraft.command.Commands; +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 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/bscv/module/hud/ActiveModules.java b/src/main/java/bscv/module/hud/ActiveModules.java new file mode 100644 index 0000000..c884261 --- /dev/null +++ b/src/main/java/bscv/module/hud/ActiveModules.java @@ -0,0 +1,40 @@ +package bscv.module.hud; + +import static bscv.tools.Text.TextBuilder; + +import com.mojang.brigadier.CommandDispatcher; + +import 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 bscv.module.HudModule; +import 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/bscv/module/hud/Coordinates.java b/src/main/java/bscv/module/hud/Coordinates.java new file mode 100644 index 0000000..3f0bef0 --- /dev/null +++ b/src/main/java/bscv/module/hud/Coordinates.java @@ -0,0 +1,37 @@ +package bscv.module.hud; + +import com.mojang.brigadier.CommandDispatcher; + +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; + +import static bscv.tools.Text.TextBuilder; +import bscv.BoSCoVicino; +import bscv.module.HudModule; + +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/bscv/module/hud/EntityList.java b/src/main/java/bscv/module/hud/EntityList.java new file mode 100644 index 0000000..4f6f135 --- /dev/null +++ b/src/main/java/bscv/module/hud/EntityList.java @@ -0,0 +1,59 @@ +package bscv.module.hud; + +import static 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 bscv.BoSCoVicino; +import 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/bscv/module/hud/InfoDisplay.java b/src/main/java/bscv/module/hud/InfoDisplay.java new file mode 100644 index 0000000..5602bff --- /dev/null +++ b/src/main/java/bscv/module/hud/InfoDisplay.java @@ -0,0 +1,134 @@ +package bscv.module.hud; + +import static bscv.tools.Text.TextBuilder; + +import java.util.ArrayDeque; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.BoolArgumentType; + +import bscv.BoSCoVicino; +import 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 { + + + 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 (BoSCoVicino.minecraft.player != null) { + this.instant_speed = + this.last_position.distanceTo(BoSCoVicino.minecraft.player.position()); + this.last_position = BoSCoVicino.minecraft.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 = BoSCoVicino.minecraft; + 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/bscv/module/motion/VanillaFlight.java b/src/main/java/bscv/module/motion/VanillaFlight.java new file mode 100644 index 0000000..8557e88 --- /dev/null +++ b/src/main/java/bscv/module/motion/VanillaFlight.java @@ -0,0 +1,108 @@ +package 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 bscv.BoSCoVicino; +import 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 { + + 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 = BoSCoVicino.minecraft.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 (BoSCoVicino.minecraft.player != null) { + this.couldFlyBefore = BoSCoVicino.minecraft.player.abilities.mayfly; + this.flyingSpeedBefore = BoSCoVicino.minecraft.player.abilities.getFlyingSpeed(); + BoSCoVicino.log(String.format("Flying speed before = %f", this.flyingSpeedBefore)); + } + } + + @Override + protected void onDisabled() { + ClientPlayerEntity player = BoSCoVicino.minecraft.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/bscv/module/self/FastInteract.java b/src/main/java/bscv/module/self/FastInteract.java new file mode 100644 index 0000000..cf40801 --- /dev/null +++ b/src/main/java/bscv/module/self/FastInteract.java @@ -0,0 +1,46 @@ +package bscv.module.self; + +import static 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 bscv.module.QuickModule; +import bscv.BoSCoVicino; + +public class FastInteract extends QuickModule { + + Field delayField; + + public FastInteract(ForgeConfigSpec.Builder builder, CommandDispatcher dispatcher) { + super("FastInteract", Group.SELF, UNBOUND, 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/bscv/module/vision/Fullbright.java b/src/main/java/bscv/module/vision/Fullbright.java new file mode 100644 index 0000000..183b933 --- /dev/null +++ b/src/main/java/bscv/module/vision/Fullbright.java @@ -0,0 +1,47 @@ +package 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 bscv.module.QuickModule; +import 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/bscv/tools/Anchor.java b/src/main/java/bscv/tools/Anchor.java new file mode 100644 index 0000000..7f24333 --- /dev/null +++ b/src/main/java/bscv/tools/Anchor.java @@ -0,0 +1,51 @@ +package bscv.tools; + +import bscv.BoSCoVicino; +import net.minecraft.client.MainWindow; +import net.minecraft.client.gui.screen.ChatScreen; +import net.minecraft.util.math.vector.Vector2f; + +public enum Anchor { + + TOPLEFT("TOPLEFT"), TOPCENTER("TOPCENTER"), TOPRIGHT("TOPRIGHT"), + MIDDLELEFT("MIDDLELEFT"), MIDDLECENTER("MIDDLECENTER"), MIDDLERIGHT("MIDDLERIGHT"), + BOTTOMLEFT("BOTTOMLEFT"), BOTTOMCENTER("BOTTOMCENTER"), BOTTOMRIGHT("BOTTOMRIGHT"); + + private Anchor(String in) { } + + public Vector2f translate(Vector2f in, int textWidth, int lineHeight, float scale, MainWindow window) { + int offset = 0; + switch (this) { + case BOTTOMLEFT: + case BOTTOMCENTER: + case BOTTOMRIGHT: + if (BoSCoVicino.minecraft.screen instanceof ChatScreen) { + offset = 15; + } + default: + } + // TODO de-spaghetti this mess + switch (this) { + case TOPLEFT: + return new Vector2f(in.x, in.y); + case TOPCENTER: + return new Vector2f((window.getWidth() / (scale * 4.0f)) + in.x - (textWidth / 2), in.y); + case TOPRIGHT: + return new Vector2f((window.getWidth() / (scale * 2.0f)) - (in.x + textWidth), in.y); + case MIDDLELEFT: + return new Vector2f(in.x, (window.getHeight() / (scale * 4.0f)) + in.y - (lineHeight / 2)); + case MIDDLECENTER: + return new Vector2f((window.getWidth() / (scale * 4.0f)) + in.x - (textWidth / 2), (window.getHeight() / (scale * 4.0f)) + in.y - (lineHeight / 2)); + case MIDDLERIGHT: + return new Vector2f((window.getWidth() / (scale * 2.0f)) - (in.x + textWidth ), (window.getHeight() / (scale * 4.0f)) + in.y - (lineHeight / 2)); + case BOTTOMLEFT: + return new Vector2f(in.x, (window.getHeight() / (scale * 2.0f)) - (in.y + lineHeight + offset)); + case BOTTOMCENTER: + return new Vector2f((window.getWidth() / (scale * 4.0f)) + in.x - (textWidth / 2), (window.getHeight() / (scale * 2.0f)) - (in.y + lineHeight + offset)); + case BOTTOMRIGHT: + return new Vector2f((window.getWidth() / (scale * 4.0f)) - (in.x + textWidth), (window.getHeight() / (scale * 2.0f)) - (in.y + lineHeight + offset)); + default: + return new Vector2f(0.0f, 0.0f); + } + } +} diff --git a/src/main/java/bscv/tools/Text.java b/src/main/java/bscv/tools/Text.java new file mode 100644 index 0000000..b366914 --- /dev/null +++ b/src/main/java/bscv/tools/Text.java @@ -0,0 +1,90 @@ +package bscv.tools; + +import com.mojang.blaze3d.matrix.MatrixStack; +import com.mojang.blaze3d.systems.RenderSystem; + +import bscv.BoSCoVicino; +import bscv.tools.Anchor; +import net.minecraft.client.MainWindow; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.util.math.vector.Vector2f; +import net.minecraft.util.text.Color; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.StringTextComponent; +import net.minecraft.util.text.Style; + + +public final class Text { + String text; + Anchor anchor; + Style style; + int x; + int y; + double scale; + + private Text() { + this.text = ""; + this.anchor = Anchor.TOPLEFT; + this.style = Style.EMPTY.withColor(Color.fromRgb(16777215)); + this.x = 0; + this.y = 0; + this.scale = 1.0; + } + + public static Text TextBuilder() { + return new Text(); + } + + public Text txt(String txt) { + this.text = txt; + return this; + } + + public Text anchor(Anchor a) { + this.anchor = a; + return this; + } + + public Text style(Style in) { + this.style = in; + return this; + } + + public Text x(int x) { + this.x = x; + return this; + } + + public Text y(int y) { + this.y = y; + return this; + } + + public Text scale(double scale) { + this.scale = scale; + return this; + } + + public void render(MatrixStack stack, MainWindow window) { + FontRenderer font = BoSCoVicino.minecraft.font; + ITextComponent text = new StringTextComponent(this.text).setStyle(this.style); + Vector2f abs_coords = this.anchor.translate( + new Vector2f(this.x, this.y), + font.width(text), + font.lineHeight, + (float) this.scale, + window + ); + // TODO is there any non-deprecated way? + RenderSystem.pushMatrix(); + RenderSystem.scaled(this.scale, this.scale, this.scale); + font.drawShadow( + stack, + text, + abs_coords.x, + abs_coords.y, + 10 // ???? TODO! + ); + RenderSystem.popMatrix(); + } +} diff --git a/src/main/java/bscv/tools/Utils.java b/src/main/java/bscv/tools/Utils.java new file mode 100644 index 0000000..ddfd75b --- /dev/null +++ b/src/main/java/bscv/tools/Utils.java @@ -0,0 +1,10 @@ +package bscv.tools; + +import java.util.function.Function; +import java.util.function.Supplier; + +public class Utils { + public static O coalesce(I val, Function f, Supplier fallback) { + return val == null ? fallback.get() : f.apply(val); + } +} diff --git a/src/main/java/co/fantabos/bscv/BoSCoVicino.java b/src/main/java/co/fantabos/bscv/BoSCoVicino.java deleted file mode 100644 index bd0864c..0000000 --- a/src/main/java/co/fantabos/bscv/BoSCoVicino.java +++ /dev/null @@ -1,181 +0,0 @@ -package co.fantabos.bscv; - -import net.minecraft.block.Block; -import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.player.ClientPlayerEntity; -import net.minecraft.command.CommandSource; -import net.minecraft.command.Commands; -import net.minecraft.util.text.StringTextComponent; -import net.minecraftforge.client.event.ClientChatEvent; -import net.minecraftforge.common.ForgeConfigSpec; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.RegistryEvent; -import net.minecraftforge.event.world.WorldEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.ModLoadingContext; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.config.ModConfig.Type; -import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.exceptions.CommandSyntaxException; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; - -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") -public class BoSCoVicino { - public static String MOD_ID = "bscv"; - - // Directly reference a log4j logger. - public static final Logger LOGGER = LogManager.getLogger(); - - public static Minecraft minecraft; - - public static List mods; - - private final CommandDispatcher dispatcher = new CommandDispatcher<>(); - - public static ForgeConfigSpec spec; - - public BoSCoVicino() { - // Register the setup method for modloading - FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientSetup); - - // Store minecraft instance - BoSCoVicino.minecraft = Minecraft.getInstance(); - - // load and register mods - BoSCoVicino.mods = new ArrayList(); - - ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder(); - - // TODO also push! - // modules cannot easily pop from their builder, but here we can't easily get - // the module name yet. We should push and pop the builder ourselves and not - // bother the modules themselves. - - BoSCoVicino.mods.add(new Fullbright(builder, this.dispatcher)); - builder.pop(); - BoSCoVicino.mods.add(new VanillaFlight(builder, this.dispatcher)); - builder.pop(); - BoSCoVicino.mods.add(new FastInteract(builder, this.dispatcher)); - builder.pop(); - BoSCoVicino.mods.add(new InfoDisplay(builder, this.dispatcher)); - builder.pop(); - BoSCoVicino.mods.add(new Coordinates(builder, this.dispatcher)); - builder.pop(); - BoSCoVicino.mods.add(new EntityList(builder, this.dispatcher)); - builder.pop(); - BoSCoVicino.mods.add(new ActiveModules(builder, this.dispatcher)); - builder.pop(); - - BoSCoVicino.spec = builder.build(); - - // register config handler - ModLoadingContext.get().registerConfig(Type.CLIENT, spec, "bscv.toml"); - - // Register ourselves for server and other game events we are interested in - MinecraftForge.EVENT_BUS.register(this); - } - - public static void log(String message) { - BoSCoVicino.minecraft.gui.getChat().addMessage(new StringTextComponent(message)); - } - - private void clientSetup(final FMLClientSetupEvent event) { - LOGGER.info("Initializing modules"); - - for (Module m : BoSCoVicino.mods) { - if (m.enabled.get()) m.enable(); - } - - // TEMPORARY! add command to regenerate suggestions - dispatcher.register( - Commands.literal("hints") - .executes(ctx -> { - ClientPlayerEntity player = BoSCoVicino.minecraft.player; - if (player != null) { - try { - Field commands = player.connection.getClass().getDeclaredField("field_195517_n"); // "commands", it's obfuscated - commands.setAccessible(true); - commands.set(player.connection, this.dispatcher); - LOGGER.info("Rebuild HINTS"); - log("> rebuilt hints"); - return 1; - } catch (NoSuchFieldException e) { - log("! no such field error"); - LOGGER.error("No such field Exception while rebuilding hints"); - return 0; - } catch (IllegalAccessException e) { - log("! illegal access error"); - LOGGER.error("Illegal Access Exception while rebuilding hints"); - return 0; - } - } else { - log("! local player is NULL"); - LOGGER.error("Local player is NULL"); - return 0; - } - }) - ); - } - - @SubscribeEvent - public void onClientChatEvent(ClientChatEvent event) { - if (event.getMessage().startsWith("/")) { - CommandSource source = BoSCoVicino.minecraft.player.createCommandSourceStack(); // TODO player could be NULL - try { - LOGGER.info(String.format("Running command %s", event.getMessage())); - this.dispatcher.execute(event.getMessage().substring(1), source); - BoSCoVicino.minecraft.gui.getChat().addRecentChat(event.getMessage()); - event.setCanceled(true); - } catch (CommandSyntaxException e) { - LOGGER.error(String.format("Syntax error in command : %s", e.toString())); - } - } - } - - @SubscribeEvent - public void onWorldLoad(WorldEvent.Load event) { - // TEMPORARY! add command to regenerate suggestions - ClientPlayerEntity player = BoSCoVicino.minecraft.player; - if (player != null) { - try { - Field commands = player.connection.getClass().getDeclaredField("field_195517_n"); // "commands", it's obfuscated - commands.setAccessible(true); - commands.set(player.connection, this.dispatcher); - LOGGER.info("Rebuild HINTS"); - log("> rebuilt hints"); - } catch (NoSuchFieldException e) { - LOGGER.error("No such field Exception while rebuilding hints"); - } catch (IllegalAccessException e) { - LOGGER.error("Illegal Access Exception while rebuilding hints"); - } - } else { - LOGGER.error("Local player is NULL"); - } - } - - // You can use EventBusSubscriber to automatically subscribe events on the contained class (this is subscribing to the MOD - // Event bus for receiving Registry Events) - @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD) - public static class RegistryEvents { - @SubscribeEvent - public static void onBlocksRegistry(final RegistryEvent.Register blockRegistryEvent) { - // register a new block here - LOGGER.info("HELLO from Register Block"); - } - } -} diff --git a/src/main/java/co/fantabos/bscv/module/HudModule.java b/src/main/java/co/fantabos/bscv/module/HudModule.java deleted file mode 100644 index 61abcc9..0000000 --- a/src/main/java/co/fantabos/bscv/module/HudModule.java +++ /dev/null @@ -1,48 +0,0 @@ -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 deleted file mode 100644 index 67beb13..0000000 --- a/src/main/java/co/fantabos/bscv/module/Module.java +++ /dev/null @@ -1,154 +0,0 @@ -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/QuickModule.java b/src/main/java/co/fantabos/bscv/module/QuickModule.java deleted file mode 100644 index b79d2bb..0000000 --- a/src/main/java/co/fantabos/bscv/module/QuickModule.java +++ /dev/null @@ -1,91 +0,0 @@ -package co.fantabos.bscv.module; - -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.arguments.StringArgumentType; - -import net.minecraft.client.settings.KeyBinding; -import net.minecraft.client.util.InputMappings; -import net.minecraft.command.CommandSource; -import net.minecraft.command.Commands; -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 co.fantabos.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/co/fantabos/bscv/module/hud/ActiveModules.java b/src/main/java/co/fantabos/bscv/module/hud/ActiveModules.java deleted file mode 100644 index ea748b2..0000000 --- a/src/main/java/co/fantabos/bscv/module/hud/ActiveModules.java +++ /dev/null @@ -1,40 +0,0 @@ -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 deleted file mode 100644 index bc1b73f..0000000 --- a/src/main/java/co/fantabos/bscv/module/hud/Coordinates.java +++ /dev/null @@ -1,37 +0,0 @@ -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 deleted file mode 100644 index 5b6d24d..0000000 --- a/src/main/java/co/fantabos/bscv/module/hud/EntityList.java +++ /dev/null @@ -1,59 +0,0 @@ -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/hud/InfoDisplay.java b/src/main/java/co/fantabos/bscv/module/hud/InfoDisplay.java deleted file mode 100644 index a715a1a..0000000 --- a/src/main/java/co/fantabos/bscv/module/hud/InfoDisplay.java +++ /dev/null @@ -1,134 +0,0 @@ -package co.fantabos.bscv.module.hud; - -import static co.fantabos.bscv.tools.Text.TextBuilder; - -import java.util.ArrayDeque; - -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.arguments.BoolArgumentType; - -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.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 { - - - 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 (BoSCoVicino.minecraft.player != null) { - this.instant_speed = - this.last_position.distanceTo(BoSCoVicino.minecraft.player.position()); - this.last_position = BoSCoVicino.minecraft.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 = BoSCoVicino.minecraft; - 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/co/fantabos/bscv/module/motion/VanillaFlight.java b/src/main/java/co/fantabos/bscv/module/motion/VanillaFlight.java deleted file mode 100644 index 2c32a39..0000000 --- a/src/main/java/co/fantabos/bscv/module/motion/VanillaFlight.java +++ /dev/null @@ -1,108 +0,0 @@ -package co.fantabos.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 co.fantabos.bscv.BoSCoVicino; -import co.fantabos.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 { - - 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 = BoSCoVicino.minecraft.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 (BoSCoVicino.minecraft.player != null) { - this.couldFlyBefore = BoSCoVicino.minecraft.player.abilities.mayfly; - this.flyingSpeedBefore = BoSCoVicino.minecraft.player.abilities.getFlyingSpeed(); - BoSCoVicino.log(String.format("Flying speed before = %f", this.flyingSpeedBefore)); - } - } - - @Override - protected void onDisabled() { - ClientPlayerEntity player = BoSCoVicino.minecraft.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/co/fantabos/bscv/module/self/FastInteract.java b/src/main/java/co/fantabos/bscv/module/self/FastInteract.java deleted file mode 100644 index eba065f..0000000 --- a/src/main/java/co/fantabos/bscv/module/self/FastInteract.java +++ /dev/null @@ -1,46 +0,0 @@ -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, UNBOUND, 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 deleted file mode 100644 index 77bdbce..0000000 --- a/src/main/java/co/fantabos/bscv/module/vision/Fullbright.java +++ /dev/null @@ -1,47 +0,0 @@ -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/tools/Anchor.java b/src/main/java/co/fantabos/bscv/tools/Anchor.java deleted file mode 100644 index 8d31b41..0000000 --- a/src/main/java/co/fantabos/bscv/tools/Anchor.java +++ /dev/null @@ -1,51 +0,0 @@ -package co.fantabos.bscv.tools; - -import co.fantabos.bscv.BoSCoVicino; -import net.minecraft.client.MainWindow; -import net.minecraft.client.gui.screen.ChatScreen; -import net.minecraft.util.math.vector.Vector2f; - -public enum Anchor { - - TOPLEFT("TOPLEFT"), TOPCENTER("TOPCENTER"), TOPRIGHT("TOPRIGHT"), - MIDDLELEFT("MIDDLELEFT"), MIDDLECENTER("MIDDLECENTER"), MIDDLERIGHT("MIDDLERIGHT"), - BOTTOMLEFT("BOTTOMLEFT"), BOTTOMCENTER("BOTTOMCENTER"), BOTTOMRIGHT("BOTTOMRIGHT"); - - private Anchor(String in) { } - - public Vector2f translate(Vector2f in, int textWidth, int lineHeight, float scale, MainWindow window) { - int offset = 0; - switch (this) { - case BOTTOMLEFT: - case BOTTOMCENTER: - case BOTTOMRIGHT: - if (BoSCoVicino.minecraft.screen instanceof ChatScreen) { - offset = 15; - } - default: - } - // TODO de-spaghetti this mess - switch (this) { - case TOPLEFT: - return new Vector2f(in.x, in.y); - case TOPCENTER: - return new Vector2f((window.getWidth() / (scale * 4.0f)) + in.x - (textWidth / 2), in.y); - case TOPRIGHT: - return new Vector2f((window.getWidth() / (scale * 2.0f)) - (in.x + textWidth), in.y); - case MIDDLELEFT: - return new Vector2f(in.x, (window.getHeight() / (scale * 4.0f)) + in.y - (lineHeight / 2)); - case MIDDLECENTER: - return new Vector2f((window.getWidth() / (scale * 4.0f)) + in.x - (textWidth / 2), (window.getHeight() / (scale * 4.0f)) + in.y - (lineHeight / 2)); - case MIDDLERIGHT: - return new Vector2f((window.getWidth() / (scale * 2.0f)) - (in.x + textWidth ), (window.getHeight() / (scale * 4.0f)) + in.y - (lineHeight / 2)); - case BOTTOMLEFT: - return new Vector2f(in.x, (window.getHeight() / (scale * 2.0f)) - (in.y + lineHeight + offset)); - case BOTTOMCENTER: - return new Vector2f((window.getWidth() / (scale * 4.0f)) + in.x - (textWidth / 2), (window.getHeight() / (scale * 2.0f)) - (in.y + lineHeight + offset)); - case BOTTOMRIGHT: - return new Vector2f((window.getWidth() / (scale * 4.0f)) - (in.x + textWidth), (window.getHeight() / (scale * 2.0f)) - (in.y + lineHeight + offset)); - default: - return new Vector2f(0.0f, 0.0f); - } - } -} diff --git a/src/main/java/co/fantabos/bscv/tools/Text.java b/src/main/java/co/fantabos/bscv/tools/Text.java deleted file mode 100644 index 8c8adb5..0000000 --- a/src/main/java/co/fantabos/bscv/tools/Text.java +++ /dev/null @@ -1,90 +0,0 @@ -package co.fantabos.bscv.tools; - -import com.mojang.blaze3d.matrix.MatrixStack; -import com.mojang.blaze3d.systems.RenderSystem; - -import co.fantabos.bscv.BoSCoVicino; -import co.fantabos.bscv.tools.Anchor; -import net.minecraft.client.MainWindow; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.util.math.vector.Vector2f; -import net.minecraft.util.text.Color; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.StringTextComponent; -import net.minecraft.util.text.Style; - - -public final class Text { - String text; - Anchor anchor; - Style style; - int x; - int y; - double scale; - - private Text() { - this.text = ""; - this.anchor = Anchor.TOPLEFT; - this.style = Style.EMPTY.withColor(Color.fromRgb(16777215)); - this.x = 0; - this.y = 0; - this.scale = 1.0; - } - - public static Text TextBuilder() { - return new Text(); - } - - public Text txt(String txt) { - this.text = txt; - return this; - } - - public Text anchor(Anchor a) { - this.anchor = a; - return this; - } - - public Text style(Style in) { - this.style = in; - return this; - } - - public Text x(int x) { - this.x = x; - return this; - } - - public Text y(int y) { - this.y = y; - return this; - } - - public Text scale(double scale) { - this.scale = scale; - return this; - } - - public void render(MatrixStack stack, MainWindow window) { - FontRenderer font = BoSCoVicino.minecraft.font; - ITextComponent text = new StringTextComponent(this.text).setStyle(this.style); - Vector2f abs_coords = this.anchor.translate( - new Vector2f(this.x, this.y), - font.width(text), - font.lineHeight, - (float) this.scale, - window - ); - // TODO is there any non-deprecated way? - RenderSystem.pushMatrix(); - RenderSystem.scaled(this.scale, this.scale, this.scale); - font.drawShadow( - stack, - text, - abs_coords.x, - abs_coords.y, - 10 // ???? TODO! - ); - RenderSystem.popMatrix(); - } -} diff --git a/src/main/java/co/fantabos/bscv/tools/Utils.java b/src/main/java/co/fantabos/bscv/tools/Utils.java deleted file mode 100644 index 07d8355..0000000 --- a/src/main/java/co/fantabos/bscv/tools/Utils.java +++ /dev/null @@ -1,10 +0,0 @@ -package co.fantabos.bscv.tools; - -import java.util.function.Function; -import java.util.function.Supplier; - -public class Utils { - public static O coalesce(I val, Function f, Supplier fallback) { - return val == null ? fallback.get() : f.apply(val); - } -} -- cgit v1.2.3-56-ga3b1