feat: added HudModule and remade Hud mods
This commit is contained in:
parent
b7808b7938
commit
2e9321c305
4 changed files with 166 additions and 4 deletions
|
@ -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(
|
public <T> ForgeConfigSpec.ConfigValue<T> option(
|
||||||
String name,
|
String name,
|
||||||
String comment,
|
String comment,
|
||||||
|
@ -69,9 +108,10 @@ public abstract class Module {
|
||||||
.then(
|
.then(
|
||||||
Commands.argument(name, argument)
|
Commands.argument(name, argument)
|
||||||
.executes( ctx -> {
|
.executes( ctx -> {
|
||||||
conf.set(ctx.getArgument(name, clazz));
|
T value = ctx.getArgument(name, clazz);
|
||||||
|
conf.set(value);
|
||||||
conf.save();
|
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;
|
return 1;
|
||||||
}))
|
}))
|
||||||
.executes(ctx -> {
|
.executes(ctx -> {
|
||||||
|
@ -95,7 +135,7 @@ public abstract class Module {
|
||||||
public final void enable() {
|
public final void enable() {
|
||||||
MinecraftForge.EVENT_BUS.register(this);
|
MinecraftForge.EVENT_BUS.register(this);
|
||||||
this.enabled.set(true);
|
this.enabled.set(true);
|
||||||
this.enabled.save();
|
// this.enabled.save();
|
||||||
this.onEnabled();
|
this.onEnabled();
|
||||||
log(String.format("%s enabled", this.name));
|
log(String.format("%s enabled", this.name));
|
||||||
BoSCoVicino.LOGGER.info(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() {
|
public final void disable() {
|
||||||
MinecraftForge.EVENT_BUS.unregister(this);
|
MinecraftForge.EVENT_BUS.unregister(this);
|
||||||
this.enabled.set(false);
|
this.enabled.set(false);
|
||||||
this.enabled.save();
|
// this.enabled.save();
|
||||||
this.onDisabled();
|
this.onDisabled();
|
||||||
log(String.format("%s disabled", this.name));
|
log(String.format("%s disabled", this.name));
|
||||||
BoSCoVicino.LOGGER.info(String.format("%s disabled", this.name));
|
BoSCoVicino.LOGGER.info(String.format("%s disabled", this.name));
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
36
src/main/java/co/fantabos/bscv/modules/hud/Coordinates.java
Normal file
36
src/main/java/co/fantabos/bscv/modules/hud/Coordinates.java
Normal file
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
48
src/main/java/co/fantabos/bscv/modules/hud/HudModule.java
Normal file
48
src/main/java/co/fantabos/bscv/modules/hud/HudModule.java
Normal file
|
@ -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
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue