able to runClient, config saving works
This commit is contained in:
parent
9c73c8de30
commit
6c0bb42b73
15 changed files with 97 additions and 20 deletions
|
@ -3,10 +3,14 @@ package com.baseband.client;
|
||||||
import com.baseband.client.configuration.Updater;
|
import com.baseband.client.configuration.Updater;
|
||||||
import com.baseband.client.module.Module;
|
import com.baseband.client.module.Module;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.swing.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
@Mod(modid = "baseband_testing")
|
||||||
public class BaseBand {
|
public class BaseBand {
|
||||||
|
|
||||||
public static BaseBand INSTANCE; { INSTANCE = this; }
|
public static BaseBand INSTANCE; { INSTANCE = this; }
|
||||||
|
@ -20,6 +24,12 @@ public class BaseBand {
|
||||||
updater.populate();
|
updater.populate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Mod.EventHandler
|
||||||
|
public void onInit(FMLPostInitializationEvent event) {
|
||||||
|
onInit();
|
||||||
|
}
|
||||||
|
|
||||||
public void onInit() {
|
public void onInit() {
|
||||||
mc = Minecraft.getMinecraft();
|
mc = Minecraft.getMinecraft();
|
||||||
|
|
||||||
|
@ -28,6 +38,27 @@ public class BaseBand {
|
||||||
for (int i = 0; i < modules.length; i++) {
|
for (int i = 0; i < modules.length; i++) {
|
||||||
modules[i].register(this, mc);
|
modules[i].register(this, mc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (Updater updater : updaters) {
|
||||||
|
System.out.println("populating updater " + updater);
|
||||||
|
updater.populate();
|
||||||
|
}
|
||||||
|
|
||||||
|
new Thread(() -> {
|
||||||
|
while (true) {
|
||||||
|
for (Updater updater : updaters) {
|
||||||
|
System.out.println("polling updater " + updater);
|
||||||
|
updater.poll();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
|
||||||
|
new Thread(() -> JOptionPane.showMessageDialog(null, "Gaming")).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
|
|
@ -2,7 +2,7 @@ package com.baseband.client;
|
||||||
|
|
||||||
import com.baseband.client.module.Module;
|
import com.baseband.client.module.Module;
|
||||||
import com.baseband.client.module.command.Test;
|
import com.baseband.client.module.command.Test;
|
||||||
import de.tudbut.parsing.TCN;
|
import com.baseband.client.module.render.ClickGUI;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author TudbuT
|
* @author TudbuT
|
||||||
|
@ -14,6 +14,7 @@ public class Setup {
|
||||||
public final String REGISTRY_FILENAME = "baseband.db";
|
public final String REGISTRY_FILENAME = "baseband.db";
|
||||||
public final Module[] MODULES = new Module[] {
|
public final Module[] MODULES = new Module[] {
|
||||||
new Test(),
|
new Test(),
|
||||||
|
new ClickGUI()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -25,9 +25,10 @@ public class ConfigHandle {
|
||||||
return tcn;
|
return tcn;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updated() {
|
public void updated(String id) {
|
||||||
for (Updater updater : onUpdate) {
|
for (Updater updater : onUpdate) {
|
||||||
updater.onUpdateConfig();
|
if(updater.id.equals(id))
|
||||||
|
updater.onUpdateConfig();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
package com.baseband.client.configuration;
|
package com.baseband.client.configuration;
|
||||||
|
|
||||||
import com.baseband.client.Setup;
|
import com.baseband.client.Setup;
|
||||||
import de.tudbut.parsing.TCN;
|
|
||||||
import de.tudbut.tools.Registry;
|
import de.tudbut.tools.Registry;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class Configuration {
|
public class Configuration {
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.baseband.client.configuration;
|
package com.baseband.client.configuration;
|
||||||
|
|
||||||
|
import de.tudbut.tools.ReflectUtil;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
public class Updater {
|
public class Updater {
|
||||||
|
@ -13,6 +15,7 @@ public class Updater {
|
||||||
this.handle = handle;
|
this.handle = handle;
|
||||||
this.o = o;
|
this.o = o;
|
||||||
this.field = field;
|
this.field = field;
|
||||||
|
ReflectUtil.forceAccessible(field);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onUpdateConfig() {
|
void onUpdateConfig() {
|
||||||
|
@ -45,7 +48,7 @@ public class Updater {
|
||||||
field.getType() == double.class ||
|
field.getType() == double.class ||
|
||||||
field.getType() == boolean.class) {
|
field.getType() == boolean.class) {
|
||||||
handle.getContent().set(id, field.get(o));
|
handle.getContent().set(id, field.get(o));
|
||||||
handle.updated();
|
handle.updated(id);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException("Unhandled type of field: " + field.getType());
|
throw new IllegalStateException("Unhandled type of field: " + field.getType());
|
||||||
}
|
}
|
||||||
|
@ -63,11 +66,17 @@ public class Updater {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void populate() {
|
public void populate() {
|
||||||
onUpdateConfig();
|
if(handle.getContent().get(id) != null)
|
||||||
|
onUpdateConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Updater name(String id) {
|
public Updater name(String id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return this.handle.name + "::" + this.id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ public class EnumButton extends Component {
|
||||||
int finalI = i;
|
int finalI = i;
|
||||||
subComponents.add(button = new Button(enums[i].toString(), it -> {
|
subComponents.add(button = new Button(enums[i].toString(), it -> {
|
||||||
handle.getContent().set(field, finalI);
|
handle.getContent().set(field, finalI);
|
||||||
handle.updated();
|
handle.updated(field);
|
||||||
for (Component component : subComponents) {
|
for (Component component : subComponents) {
|
||||||
component.green = false;
|
component.green = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,6 @@ public class IntSlider extends Component {
|
||||||
this.mapper = mapper;
|
this.mapper = mapper;
|
||||||
this.adder = adder;
|
this.adder = adder;
|
||||||
this.updateMethod = updateMethod;
|
this.updateMethod = updateMethod;
|
||||||
update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IntSlider(String s, ConfigHandle handle, String field, Function<Integer, String> text, int mapper, int adder) {
|
public IntSlider(String s, ConfigHandle handle, String field, Function<Integer, String> text, int mapper, int adder) {
|
||||||
|
@ -51,7 +50,7 @@ public class IntSlider extends Component {
|
||||||
f = Math.max(Math.min(x, 100), 0) / 100f;
|
f = Math.max(Math.min(x, 100), 0) / 100f;
|
||||||
|
|
||||||
handle.getContent().set(field, Math.round(f * mapper + adder));
|
handle.getContent().set(field, Math.round(f * mapper + adder));
|
||||||
handle.updated();
|
handle.updated(field);
|
||||||
if(!updateMethod.apply(Math.round(f * mapper + adder))) {
|
if(!updateMethod.apply(Math.round(f * mapper + adder))) {
|
||||||
System.out.println("Something went wrong handling the sliders!");
|
System.out.println("Something went wrong handling the sliders!");
|
||||||
throw new RuntimeException();
|
throw new RuntimeException();
|
||||||
|
|
|
@ -26,7 +26,6 @@ public class Slider extends Component {
|
||||||
this.mapper = mapper;
|
this.mapper = mapper;
|
||||||
this.adder = adder;
|
this.adder = adder;
|
||||||
this.updateMethod = updateMethod;
|
this.updateMethod = updateMethod;
|
||||||
update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Slider(String s, ConfigHandle handle, String field, Function<Float, String> text, float mapper, float adder) {
|
public Slider(String s, ConfigHandle handle, String field, Function<Float, String> text, float mapper, float adder) {
|
||||||
|
@ -51,7 +50,7 @@ public class Slider extends Component {
|
||||||
f = Math.max(Math.min(x, 100), 0) / 100f;
|
f = Math.max(Math.min(x, 100), 0) / 100f;
|
||||||
|
|
||||||
handle.getContent().set(field, f * mapper + adder);
|
handle.getContent().set(field, f * mapper + adder);
|
||||||
handle.updated();
|
handle.updated(field);
|
||||||
if(!updateMethod.apply(f * mapper + adder)) {
|
if(!updateMethod.apply(f * mapper + adder)) {
|
||||||
System.out.println("Something went wrong handling the sliders!");
|
System.out.println("Something went wrong handling the sliders!");
|
||||||
throw new RuntimeException();
|
throw new RuntimeException();
|
||||||
|
|
|
@ -12,14 +12,12 @@ public class ToggleButton extends Component {
|
||||||
this.text = s;
|
this.text = s;
|
||||||
this.handle = handle;
|
this.handle = handle;
|
||||||
this.field = field;
|
this.field = field;
|
||||||
update();
|
|
||||||
}
|
}
|
||||||
public ToggleButton(String s, ConfigHandle handle, String field, Runnable lambda) {
|
public ToggleButton(String s, ConfigHandle handle, String field, Runnable lambda) {
|
||||||
this.lambda = lambda;
|
this.lambda = lambda;
|
||||||
this.text = s;
|
this.text = s;
|
||||||
this.handle = handle;
|
this.handle = handle;
|
||||||
this.field = field;
|
this.field = field;
|
||||||
update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -31,7 +29,7 @@ public class ToggleButton extends Component {
|
||||||
public synchronized void click(int x, int y, int mouseButton) {
|
public synchronized void click(int x, int y, int mouseButton) {
|
||||||
super.click(x, y, mouseButton);
|
super.click(x, y, mouseButton);
|
||||||
handle.getContent().set(field, green);
|
handle.getContent().set(field, green);
|
||||||
handle.updated();
|
handle.updated(field);
|
||||||
if(lambda != null)
|
if(lambda != null)
|
||||||
lambda.run();
|
lambda.run();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,20 +3,24 @@ package com.baseband.client.module;
|
||||||
import com.baseband.client.BaseBand;
|
import com.baseband.client.BaseBand;
|
||||||
import com.baseband.client.configuration.ConfigHandle;
|
import com.baseband.client.configuration.ConfigHandle;
|
||||||
import com.baseband.client.configuration.Configuration;
|
import com.baseband.client.configuration.Configuration;
|
||||||
|
import com.baseband.client.module.category.Command;
|
||||||
|
import com.baseband.client.module.category.Render;
|
||||||
import com.baseband.client.util.FieldUtil;
|
import com.baseband.client.util.FieldUtil;
|
||||||
import com.baseband.client.util.Marker;
|
import com.baseband.client.util.Marker;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
import java.lang.annotation.Annotation;
|
||||||
|
|
||||||
public enum Category {
|
public enum Category {
|
||||||
|
|
||||||
COMMAND("Commands"),
|
COMMAND("Commands", Command.class),
|
||||||
RENDER("Render")
|
RENDER("Render", Render.class)
|
||||||
|
|
||||||
;
|
;
|
||||||
|
|
||||||
Category(String name) {
|
Category(String name, Class<? extends Annotation> annotationClass) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.annotationClass = annotationClass;
|
||||||
try {
|
try {
|
||||||
handle = Configuration.register("Category/" + name.toLowerCase().replace(' ', '_'));
|
handle = Configuration.register("Category/" + name.toLowerCase().replace(' ', '_'));
|
||||||
BaseBand.registerUpdater(handle.linkWith(this, FieldUtil.findMarked(getClass(), 1)).name("x"));
|
BaseBand.registerUpdater(handle.linkWith(this, FieldUtil.findMarked(getClass(), 1)).name("x"));
|
||||||
|
@ -28,6 +32,7 @@ public enum Category {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Class<? extends Annotation> annotationClass;
|
||||||
private ConfigHandle handle;
|
private ConfigHandle handle;
|
||||||
@Marker(1)
|
@Marker(1)
|
||||||
public int x;
|
public int x;
|
||||||
|
@ -50,4 +55,8 @@ public enum Category {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Class<? extends Annotation> getAnnotationClass() {
|
||||||
|
return annotationClass;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,11 @@ public abstract class Module extends ToggleButton {
|
||||||
this.bb = bbInst;
|
this.bb = bbInst;
|
||||||
this.mc = mc;
|
this.mc = mc;
|
||||||
|
|
||||||
|
for (Category c : Category.values()) {
|
||||||
|
if(getClass().getDeclaredAnnotation(c.getAnnotationClass()) != null)
|
||||||
|
category = c;
|
||||||
|
}
|
||||||
|
|
||||||
subComponents.clear();
|
subComponents.clear();
|
||||||
|
|
||||||
ConfigHandle settings = config("Settings");
|
ConfigHandle settings = config("Settings");
|
||||||
|
@ -99,7 +104,7 @@ public abstract class Module extends ToggleButton {
|
||||||
}
|
}
|
||||||
|
|
||||||
handle = settings;
|
handle = settings;
|
||||||
BaseBand.registerUpdater(settings.linkWith(this, FieldUtil.findMarked(getClass(), 1)).name("Enabled"));
|
BaseBand.registerUpdater(settings.linkWith(this, FieldUtil.findMarked(Module.class, 1)).name("Enabled"));
|
||||||
|
|
||||||
setup();
|
setup();
|
||||||
}
|
}
|
||||||
|
@ -134,6 +139,7 @@ public abstract class Module extends ToggleButton {
|
||||||
try {
|
try {
|
||||||
ConfigHandle h = Configuration.register(getID() + "/" + handle);
|
ConfigHandle h = Configuration.register(getID() + "/" + handle);
|
||||||
ownedHandles.put(handle, h);
|
ownedHandles.put(handle, h);
|
||||||
|
System.out.println("Module " + toString() + " registered config: " + handle);
|
||||||
return h;
|
return h;
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.baseband.client.module.category;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
@Target(ElementType.TYPE)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface Command {
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.baseband.client.module.category;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
@Target(ElementType.TYPE)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface Render {
|
||||||
|
}
|
|
@ -3,17 +3,19 @@ package com.baseband.client.module.command;
|
||||||
import com.baseband.client.configuration.annotation.Config;
|
import com.baseband.client.configuration.annotation.Config;
|
||||||
import com.baseband.client.configuration.annotation.Range;
|
import com.baseband.client.configuration.annotation.Range;
|
||||||
import com.baseband.client.module.Module;
|
import com.baseband.client.module.Module;
|
||||||
|
import com.baseband.client.module.category.Command;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author TudbuT
|
* @author TudbuT
|
||||||
*
|
*
|
||||||
* Self-Test command, checks if everything is working
|
* Self-Test command, checks if everything is working
|
||||||
*/
|
*/
|
||||||
|
@Command
|
||||||
public class Test extends Module {
|
public class Test extends Module {
|
||||||
|
|
||||||
@Config("Int Setting")
|
@Config("Int Setting")
|
||||||
@Range("0..10")
|
@Range("0..10")
|
||||||
private int intSetting = 5;
|
public int intSetting = 5;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -3,7 +3,9 @@ package com.baseband.client.module.render;
|
||||||
import com.baseband.client.configuration.annotation.Config;
|
import com.baseband.client.configuration.annotation.Config;
|
||||||
import com.baseband.client.gui.GuiTTC;
|
import com.baseband.client.gui.GuiTTC;
|
||||||
import com.baseband.client.module.Module;
|
import com.baseband.client.module.Module;
|
||||||
|
import com.baseband.client.module.category.Render;
|
||||||
|
|
||||||
|
@Render
|
||||||
public class ClickGUI extends Module {
|
public class ClickGUI extends Module {
|
||||||
@Config("Mouse Fix")
|
@Config("Mouse Fix")
|
||||||
public boolean mouseFix;
|
public boolean mouseFix;
|
||||||
|
|
Loading…
Add table
Reference in a new issue