diff options
Diffstat (limited to 'src/main/java')
4 files changed, 166 insertions, 4 deletions
diff --git a/src/main/java/co/fantabos/bscv/Module.java b/src/main/java/co/fantabos/bscv/Module.java index 35aac80..7cb6a30 100644 --- a/src/main/java/co/fantabos/bscv/Module.java +++ b/src/main/java/co/fantabos/bscv/Module.java @@ -49,6 +49,45 @@ public abstract class Module { ); } + + // TODO can I merge these two option into one? Maybe redo with builder pattern? + + public <T extends Enum<T>> ForgeConfigSpec.EnumValue<T> optionEnum( + String name, + String comment, + T fallback, + ArgumentType<T> argument, + Class<T> clazz, + ForgeConfigSpec.Builder builder, + CommandDispatcher<CommandSource> dispatcher + ) { + ForgeConfigSpec.EnumValue<T> 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 <T> ForgeConfigSpec.ConfigValue<T> option( String name, String comment, @@ -69,9 +108,10 @@ public abstract class Module { .then( Commands.argument(name, argument) .executes( ctx -> { - conf.set(ctx.getArgument(name, clazz)); + T value = ctx.getArgument(name, clazz); + conf.set(value); conf.save(); - log(String.format("> %s -> %s", name, conf.get().toString())); + log(String.format("> %s -> %s", String.join(".", conf.getPath()), conf.get().toString())); return 1; })) .executes(ctx -> { @@ -95,7 +135,7 @@ public abstract class Module { public final void enable() { MinecraftForge.EVENT_BUS.register(this); this.enabled.set(true); - this.enabled.save(); + // this.enabled.save(); this.onEnabled(); log(String.format("%s enabled", this.name)); BoSCoVicino.LOGGER.info(String.format("%s enabled", this.name)); @@ -104,7 +144,7 @@ public abstract class Module { public final void disable() { MinecraftForge.EVENT_BUS.unregister(this); this.enabled.set(false); - this.enabled.save(); + // 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 new file mode 100644 index 0000000..f7d2c8a --- /dev/null +++ b/src/main/java/co/fantabos/bscv/modules/hud/ActiveModules.java @@ -0,0 +1,38 @@ +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<CommandSource> dispatcher) { + super("ActiveModules", builder, dispatcher); + } + + @SubscribeEvent + public void onRenderOverlay(RenderGameOverlayEvent event) { + if (event.getType() == ElementType.TEXT) { + float offset = 0.0f; + 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) + .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 new file mode 100644 index 0000000..4acc893 --- /dev/null +++ b/src/main/java/co/fantabos/bscv/modules/hud/Coordinates.java @@ -0,0 +1,36 @@ +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<CommandSource> 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()) + .anchor(this.anchor.get()) + .x(this.x.get()) + .y(this.y.get()) + .render(event.getMatrixStack(), event.getWindow()); + } + } +} diff --git a/src/main/java/co/fantabos/bscv/modules/hud/HudModule.java b/src/main/java/co/fantabos/bscv/modules/hud/HudModule.java new file mode 100644 index 0000000..0327d78 --- /dev/null +++ b/src/main/java/co/fantabos/bscv/modules/hud/HudModule.java @@ -0,0 +1,48 @@ +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<Integer> x; + public final ForgeConfigSpec.ConfigValue<Integer> y; + public final ForgeConfigSpec.ConfigValue<Double> scale; + public final ForgeConfigSpec.EnumValue<Anchor> anchor; + + protected HudModule(String name, ForgeConfigSpec.Builder builder, CommandDispatcher<CommandSource> 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 + ); + } + +} |