feat: implemented auto service for modules

This commit is contained in:
ftbsc 2023-02-28 23:00:03 +01:00
parent e82f1cc5e6
commit 930ccf34c7
24 changed files with 82 additions and 75 deletions

View file

@ -92,9 +92,11 @@ dependencies {
minecraft "net.minecraftforge:forge:${minecraftVersion}-${forgeVersion}"
implementation 'ftbsc:lll:0.2.2'
implementation 'ftbsc.lll:processor:0.1.1'
implementation 'com.google.auto.service:auto-service-annotations:1.0.1'
annotationProcessor 'com.squareup:javapoet:1.13.0'
annotationProcessor 'ftbsc:lll:0.2.2'
annotationProcessor 'ftbsc.lll:processor:0.1.1'
annotationProcessor 'com.google.auto.service:auto-service:1.0.1'
}
jar {

View file

@ -28,12 +28,6 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
import java.lang.reflect.Field;
import ftbsc.bscv.modules.vision.*;
import ftbsc.bscv.modules.motion.*;
import ftbsc.bscv.modules.self.*;
import ftbsc.bscv.modules.hud.*;
import ftbsc.bscv.modules.defense.*;
@Mod("bscv")
public class BoSCoVicino implements ICommons {
public static String MOD_ID = "bscv";
@ -52,24 +46,7 @@ public class BoSCoVicino implements ICommons {
ForgeConfigSpec.Builder cfg = new ForgeConfigSpec.Builder();
CommandDispatcher<CommandSource> dp = this.dispatcher;
this.modManager = new ModManager(cfg, dp);
this.modManager.registerMod(new AutoDisconnect());
this.modManager.registerMod(new ActiveModules());
this.modManager.registerMod(new VanillaFlight());
this.modManager.registerMod(new FastInteract());
this.modManager.registerMod(new InfoDisplay());
this.modManager.registerMod(new Coordinates());
this.modManager.registerMod(new EntityList());
this.modManager.registerMod(new PlayerList());
this.modManager.registerMod(new Fullbright());
this.modManager.registerMod(new AntiHunger());
this.modManager.registerMod(new PortalGui());
this.modManager.registerMod(new AutoFish());
this.modManager.registerMod(new AutoTool());
this.modManager.registerMod(new Freecam());
this.modManager.registerMod(new BoatFly());
this.modManager.registerMod(new Aura());
BoSCoVicino.modManager = new ModManager(cfg, dp);
BoSCoVicino.spec = cfg.build();
@ -90,7 +67,7 @@ public class BoSCoVicino implements ICommons {
private void clientSetup(final FMLClientSetupEvent event) {
LOGGER.info("Initializing modules");
for (IModule<?> m : modManager.mods) {
for (IModule m : modManager.mods) {
if (m.isEnabled()) m.enable();
}
@ -127,7 +104,7 @@ public class BoSCoVicino implements ICommons {
dispatcher.register(
Commands.literal("toggle-all")
.executes(ctx -> {
for (IModule<?> mod : modManager.mods) {
for (IModule mod : modManager.mods) {
if (mod.isEnabled()) {
mod.disable();
mod.enable();

View file

@ -3,8 +3,8 @@ package ftbsc.bscv.api;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.common.MinecraftForge;
public interface IModule<T extends Enum<T>> extends ICommand {
T getGroup();
public interface IModule extends ICommand {
String getGroup();
ForgeConfigSpec.Builder getConfigBuilder();

View file

@ -5,7 +5,6 @@ import com.mojang.brigadier.arguments.BoolArgumentType;
import ftbsc.bscv.BoSCoVicino;
import ftbsc.bscv.api.IModule;
import ftbsc.bscv.system.ModManager;
import net.minecraft.command.CommandSource;
import net.minecraft.command.Commands;
import net.minecraftforge.common.ForgeConfigSpec;
@ -13,16 +12,7 @@ import net.minecraftforge.common.MinecraftForge;
import static ftbsc.bscv.BoSCoVicino.log;
public abstract class AbstractModule implements IModule<AbstractModule.Group> {
public enum Group {
SELF,
HUD,
BUILD,
DEFENSE,
VISION,
MOTION,
}
public abstract class AbstractModule implements IModule {
protected ForgeConfigSpec.ConfigValue<Boolean> enabled;
@Override
@ -31,9 +21,9 @@ public abstract class AbstractModule implements IModule<AbstractModule.Group> {
}
@Override
public Group getGroup() {
public String getGroup() {
String[] pkg = this.getClass().getPackage().getName().split("\\.");
return Group.valueOf(pkg[pkg.length - 1].toUpperCase());
return pkg[pkg.length - 1].toUpperCase();
}
@Override

View file

@ -1,11 +1,8 @@
package ftbsc.bscv.modules;
import com.mojang.brigadier.CommandDispatcher;
import ftbsc.bscv.ICommons;
import ftbsc.bscv.tools.Anchor;
import ftbsc.bscv.tools.Setting;
import net.minecraft.command.CommandSource;
import net.minecraftforge.common.ForgeConfigSpec;
public abstract class HudModule extends AbstractModule {
@ -16,8 +13,8 @@ public abstract class HudModule extends AbstractModule {
public final ForgeConfigSpec.ConfigValue<Anchor> anchor;
@Override
public Group getGroup() {
return Group.HUD;
public String getGroup() {
return "HUD";
}
protected HudModule() {

View file

@ -1,19 +1,18 @@
package ftbsc.bscv.modules;
import com.mojang.brigadier.CommandDispatcher;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.client.util.InputMappings;
import net.minecraft.command.CommandSource;
import net.minecraftforge.client.event.InputEvent;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import ftbsc.bscv.BoSCoVicino;
import ftbsc.bscv.api.ILoadable;
import com.google.auto.service.AutoService;
// TODO rename
@AutoService(ILoadable.class)
public abstract class QuickModule extends AbstractModule {
public static final int UNBOUND = InputMappings.UNKNOWN.getValue();

View file

@ -9,7 +9,10 @@ import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.TickEvent.Phase;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import ftbsc.bscv.api.ILoadable;
import com.google.auto.service.AutoService;
@AutoService(ILoadable.class)
public class Aura extends QuickModule implements ICommons {
@Override

View file

@ -9,14 +9,17 @@ import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import static ftbsc.bscv.tools.Text.TextBuilder;
import ftbsc.bscv.api.ILoadable;
import com.google.auto.service.AutoService;
@AutoService(ILoadable.class)
public class ActiveModules extends HudModule implements ICommons {
@SubscribeEvent
public void onRenderOverlay(RenderGameOverlayEvent event) {
if (event.getType() == ElementType.TEXT) {
int offset = 0;
for (IModule<?> m : BoSCoVicino.modManager.mods) {
if (m.isEnabled() && m.getGroup() != Group.HUD) {
for (IModule m : BoSCoVicino.modManager.mods) {
if (m.isEnabled() && m.getGroup().equalsIgnoreCase("HUD")) {
TextBuilder()
.txt(String.format("%s <", m.getName()))
.anchor(this.anchor.get())

View file

@ -1,18 +1,19 @@
package ftbsc.bscv.modules.hud;
import com.mojang.brigadier.CommandDispatcher;
import net.minecraft.command.CommandSource;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import static ftbsc.bscv.tools.Text.TextBuilder;
import com.google.auto.service.AutoService;
import ftbsc.bscv.ICommons;
import ftbsc.bscv.modules.HudModule;
import ftbsc.bscv.api.ILoadable;
@AutoService(ILoadable.class)
public class Coordinates extends HudModule implements ICommons {
@SubscribeEvent
public void onRenderOverlay(RenderGameOverlayEvent event) {

View file

@ -21,7 +21,10 @@ import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import ftbsc.bscv.api.ILoadable;
import com.google.auto.service.AutoService;
@AutoService(ILoadable.class)
public class EntityList extends HudModule implements ICommons {
public final ForgeConfigSpec.ConfigValue<String> search;

View file

@ -20,7 +20,10 @@ import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.TickEvent.Phase;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import ftbsc.bscv.api.ILoadable;
import com.google.auto.service.AutoService;
@AutoService(ILoadable.class)
public class InfoDisplay extends HudModule implements ICommons {
private Vector3d last_position = new Vector3d(0.0, 0.0, 0.0);

View file

@ -13,7 +13,10 @@ import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import ftbsc.bscv.api.ILoadable;
import com.google.auto.service.AutoService;
@AutoService(ILoadable.class)
public class PlayerList extends HudModule implements ICommons {
@SubscribeEvent

View file

@ -1,12 +1,12 @@
package ftbsc.bscv.modules.motion;
import com.mojang.brigadier.CommandDispatcher;
import com.google.auto.service.AutoService;
import ftbsc.bscv.ICommons;
import ftbsc.bscv.api.ILoadable;
import ftbsc.bscv.events.BoatEvent;
import ftbsc.bscv.modules.AbstractModule;
import ftbsc.bscv.tools.Keyboard;
import ftbsc.bscv.tools.Setting;
import net.minecraft.command.CommandSource;
import net.minecraft.entity.Entity;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.common.ForgeConfigSpec;
@ -14,6 +14,7 @@ import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.TickEvent.Phase;
import net.minecraftforge.eventbus.api.SubscribeEvent;
@AutoService(ILoadable.class)
public class BoatFly extends AbstractModule implements ICommons {
public final ForgeConfigSpec.ConfigValue<Double> speed;

View file

@ -14,7 +14,10 @@ import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.TickEvent.Phase;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import ftbsc.bscv.api.ILoadable;
import com.google.auto.service.AutoService;
@AutoService(ILoadable.class)
public class VanillaFlight extends QuickModule implements ICommons {
@Override

View file

@ -9,7 +9,10 @@ import net.minecraft.network.play.client.CPlayerPacket;
import net.minecraft.network.play.client.CEntityActionPacket.Action;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import ftbsc.bscv.api.ILoadable;
import com.google.auto.service.AutoService;
@AutoService(ILoadable.class)
public class AntiHunger extends AbstractModule implements ICommons {
public final ForgeConfigSpec.ConfigValue<Boolean> sprint;

View file

@ -12,7 +12,10 @@ import net.minecraft.network.play.server.SUpdateHealthPacket;
import net.minecraft.util.text.StringTextComponent;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import ftbsc.bscv.api.ILoadable;
import com.google.auto.service.AutoService;
@AutoService(ILoadable.class)
public class AutoDisconnect extends AbstractModule implements ICommons {
public final ForgeConfigSpec.ConfigValue<Double> threshold;

View file

@ -10,7 +10,10 @@ import net.minecraft.util.Hand;
import net.minecraft.util.SoundEvents;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import ftbsc.bscv.api.ILoadable;
import com.google.auto.service.AutoService;
@AutoService(ILoadable.class)
public class AutoFish extends AbstractModule implements ICommons {
public final ForgeConfigSpec.ConfigValue<Boolean> recast;

View file

@ -13,7 +13,10 @@ import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraftforge.client.event.InputEvent;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import ftbsc.bscv.api.ILoadable;
import com.google.auto.service.AutoService;
@AutoService(ILoadable.class)
public class AutoTool extends AbstractModule implements ICommons {
public final ForgeConfigSpec.ConfigValue<Integer> limit;

View file

@ -13,7 +13,10 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
import ftbsc.bscv.modules.QuickModule;
import ftbsc.bscv.ICommons;
import ftbsc.bscv.api.ILoadable;
import com.google.auto.service.AutoService;
@AutoService(ILoadable.class)
public class FastInteract extends QuickModule implements ICommons {
@Override
protected int getDefaultKey() {

View file

@ -17,7 +17,10 @@ import net.minecraft.world.GameType;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import ftbsc.bscv.api.ILoadable;
import com.google.auto.service.AutoService;
@AutoService(ILoadable.class)
public class Freecam extends QuickModule implements ICommons {
public final ForgeConfigSpec.ConfigValue<Boolean> log;

View file

@ -4,7 +4,10 @@ import ftbsc.bscv.ICommons;
import ftbsc.bscv.modules.AbstractModule;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import ftbsc.bscv.api.ILoadable;
import com.google.auto.service.AutoService;
@AutoService(ILoadable.class)
public class PortalGui extends AbstractModule implements ICommons {
@SubscribeEvent

View file

@ -8,7 +8,10 @@ import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import java.awt.event.KeyEvent;
import ftbsc.bscv.api.ILoadable;
import com.google.auto.service.AutoService;
@AutoService(ILoadable.class)
public class Fullbright extends QuickModule implements ICommons {
@Override
protected int getDefaultKey() {

View file

@ -1,37 +1,37 @@
package ftbsc.bscv.system;
import com.mojang.brigadier.CommandDispatcher;
import ftbsc.bscv.BoSCoVicino;
import ftbsc.bscv.api.ILoadable;
import ftbsc.bscv.api.IModule;
import ftbsc.bscv.modules.AbstractModule;
import ftbsc.bscv.modules.defense.Aura;
import ftbsc.bscv.modules.hud.*;
import ftbsc.bscv.modules.motion.BoatFly;
import ftbsc.bscv.modules.motion.VanillaFlight;
import ftbsc.bscv.modules.self.*;
import ftbsc.bscv.modules.vision.Fullbright;
import net.minecraft.command.CommandSource;
import net.minecraftforge.common.ForgeConfigSpec;
import java.util.HashSet;
import java.util.Optional;
import java.util.ServiceLoader;
import java.util.Set;
public class ModManager {
private Optional<ForgeConfigSpec.Builder> cfgBuilder;
private Optional<CommandDispatcher<CommandSource>> dispatcher;
public final Set<IModule<? extends Enum<?>> > mods;
public final Set<IModule> mods;
public final Set<String> categories;
public ModManager(ForgeConfigSpec.Builder cfgBuilder, CommandDispatcher<CommandSource> dispatcher) {
this.cfgBuilder = Optional.of(cfgBuilder);
this.dispatcher = Optional.of(dispatcher);
this.mods = new HashSet<>();
}
this.categories = new HashSet<>();
public void registerMod(IModule<? extends Enum<?>> mod) {
this.mods.add(mod);
this.cfgBuilder.get().pop(); // TODO solved by AutoService, soon TM
for (ILoadable module : ServiceLoader.load(ILoadable.class)) {
if(module instanceof IModule) {
IModule mod = (IModule) module;
this.mods.add(mod);
this.categories.add(mod.getGroup());
this.cfgBuilder.get().pop(); // TODO solved by AutoService, soon TM
}
}
}
public void finalize() {

View file

@ -4,7 +4,6 @@ import static ftbsc.bscv.BoSCoVicino.log;
import java.util.Optional;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.arguments.BoolArgumentType;
import com.mojang.brigadier.arguments.DoubleArgumentType;
@ -12,7 +11,6 @@ import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
import ftbsc.bscv.api.IModule;
import net.minecraft.command.CommandSource;
import net.minecraft.command.Commands;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.server.command.EnumArgument;
@ -51,7 +49,7 @@ public abstract class Setting<T> {
abstract Class<T> clazz();
public ForgeConfigSpec.ConfigValue<T> build(IModule<?> module) {
public ForgeConfigSpec.ConfigValue<T> build(IModule module) {
ForgeConfigSpec.ConfigValue<T> conf = this.value(module.getConfigBuilder());
module.getDispatcher().register(