Add mod-menu, fix backward compat bugs, ready for 1.17
This commit is contained in:
parent
e8f29b2d30
commit
e4fe4b2388
@ -28,7 +28,7 @@ dependencies {
|
||||
|
||||
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||
|
||||
// modImplementation "com.terraformersmc:modmenu:${project.modmenu_version}"
|
||||
modImplementation "com.terraformersmc:modmenu:${project.modmenu_version}"
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||
modImplementation include("io.github.cottonmc:LibGui:${project.libgui_version}")
|
||||
}
|
||||
|
||||
@ -1,11 +1,14 @@
|
||||
package me.bionicbeanie.mods.savecoords.gui.impl;
|
||||
|
||||
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
|
||||
|
||||
import me.bionicbeanie.mods.savecoords.IFileStore;
|
||||
import me.bionicbeanie.mods.savecoords.IKeyBinds;
|
||||
import me.bionicbeanie.mods.savecoords.IModGui;
|
||||
import me.bionicbeanie.mods.savecoords.IPlayerLocator;
|
||||
import me.bionicbeanie.mods.savecoords.impl.Factory;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
|
||||
//All of this works because single-threaded initialization!! Sed lyf :(
|
||||
public class DIContainer {
|
||||
@ -16,7 +19,7 @@ public class DIContainer {
|
||||
private static IPlayerLocator playerLocator;
|
||||
private static IModGui modGui;
|
||||
private static IKeyBinds keyBinds;
|
||||
//private static ConfigScreenFactory<Screen> modMenuScreenFactory;
|
||||
private static ConfigScreenFactory<Screen> modMenuScreenFactory;
|
||||
private static PingPositionOperation pingPositionOperation;
|
||||
|
||||
public static IModGui getModGui() {
|
||||
@ -29,25 +32,25 @@ public class DIContainer {
|
||||
return keyBinds;
|
||||
}
|
||||
|
||||
// public static ConfigScreenFactory<Screen> getModMenuScreenFactory() {
|
||||
// initialize();
|
||||
//
|
||||
// if (modMenuScreenFactory == null) {
|
||||
// modMenuScreenFactory = (parent) -> {
|
||||
// ConfigViewHandler handler = new ConfigViewHandler();
|
||||
//
|
||||
// handler.onSave(() -> {
|
||||
// new SaveConfigsOperation(keyBinds, fileStore, handler::getState).run();
|
||||
// guiController.closeScreen();
|
||||
// });
|
||||
//
|
||||
// handler.onBack(() -> guiController.closeScreen());
|
||||
//
|
||||
// return handler.createView(keyBinds.getAllBinds());
|
||||
// };
|
||||
// }
|
||||
// return modMenuScreenFactory;
|
||||
// }
|
||||
public static ConfigScreenFactory<Screen> getModMenuScreenFactory() {
|
||||
initialize();
|
||||
|
||||
if (modMenuScreenFactory == null) {
|
||||
modMenuScreenFactory = (parent) -> {
|
||||
ConfigViewHandler handler = new ConfigViewHandler();
|
||||
|
||||
handler.onSave(() -> {
|
||||
new SaveConfigsOperation(keyBinds, fileStore, handler::getState).run();
|
||||
guiController.closeScreen();
|
||||
});
|
||||
|
||||
handler.onBack(() -> guiController.closeScreen());
|
||||
|
||||
return handler.createView(keyBinds.getAllBinds());
|
||||
};
|
||||
}
|
||||
return modMenuScreenFactory;
|
||||
}
|
||||
|
||||
public static Runnable getPingPositionOperation() {
|
||||
initialize();
|
||||
|
||||
@ -82,8 +82,8 @@ class ListViewHandler extends ViewHandlerBase<Void> {
|
||||
List<PlayerPosition> positions = fileStore.listPositions();
|
||||
Collections.sort(positions, (p1, p2) -> {
|
||||
if (p1.getPositionMetadata() != null && p2.getPositionMetadata() != null) {
|
||||
return p2.getPositionMetadata().getLastModifiedMillis() > p1.getPositionMetadata().getLastModifiedMillis() ? 1
|
||||
: 0;
|
||||
return p2.getPositionMetadata().getLastModifiedMillis() > p1.getPositionMetadata()
|
||||
.getLastModifiedMillis() ? 1 : -1;
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
||||
@ -16,6 +16,7 @@ import com.google.gson.GsonBuilder;
|
||||
|
||||
import me.bionicbeanie.mods.savecoords.IFileStore;
|
||||
import me.bionicbeanie.mods.savecoords.model.ConfigData;
|
||||
import me.bionicbeanie.mods.savecoords.model.ConfigData.Config;
|
||||
import me.bionicbeanie.mods.savecoords.model.ModData;
|
||||
import me.bionicbeanie.mods.savecoords.model.PlayerPosition;
|
||||
|
||||
@ -28,7 +29,11 @@ class FileStore implements IFileStore {
|
||||
private Gson gson;
|
||||
|
||||
public FileStore(String baseDir) {
|
||||
this.gson = new GsonBuilder().setPrettyPrinting().setLenient(). create();
|
||||
this.gson = new GsonBuilder()
|
||||
.registerTypeAdapter(Config.class, new ConfigData.ConfigDeserializer())
|
||||
.setPrettyPrinting()
|
||||
.setLenient().create();
|
||||
|
||||
this.saveFilePath = Paths.get(baseDir, DEFAULT_DIR, DEFAULT_FILE);
|
||||
|
||||
try {
|
||||
@ -59,7 +64,6 @@ class FileStore implements IFileStore {
|
||||
public void writeDefaultWorldName(String defaultWorldName) throws IOException {
|
||||
ModData data = load();
|
||||
data.setDefaultWorldName(defaultWorldName);
|
||||
;
|
||||
|
||||
dump(data);
|
||||
}
|
||||
|
||||
@ -1,7 +1,15 @@
|
||||
package me.bionicbeanie.mods.savecoords.model;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
|
||||
public class ConfigData {
|
||||
|
||||
private Config[] keyConfigs;
|
||||
@ -31,7 +39,7 @@ public class ConfigData {
|
||||
this.keyConfigs = keyConfigs;
|
||||
}
|
||||
|
||||
public static class Config{
|
||||
public static class Config {
|
||||
private String name;
|
||||
private String type;
|
||||
private int code;
|
||||
@ -39,20 +47,51 @@ public class ConfigData {
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ConfigDeserializer implements JsonDeserializer<Config> {
|
||||
|
||||
@Override
|
||||
public Config deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
|
||||
throws JsonParseException {
|
||||
JsonObject jsonObject = json.getAsJsonObject();
|
||||
|
||||
String inputType = "KEYSYM";
|
||||
if (jsonObject.has("type")) {
|
||||
JsonElement elem = jsonObject.get("type");
|
||||
if("1".equalsIgnoreCase(elem.getAsString())) {
|
||||
inputType = "MOUSE";
|
||||
}else if("MOUSE".equalsIgnoreCase(elem.getAsString())) {
|
||||
inputType = "MOUSE";
|
||||
}
|
||||
}
|
||||
Config config = new Config();
|
||||
|
||||
config.setCode(jsonObject.get("code").getAsInt());
|
||||
config.setName(jsonObject.get("name").getAsString());
|
||||
config.setType(inputType);
|
||||
|
||||
return config;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
//package me.bionicbeanie.mods.savecoords.modmenu;
|
||||
//
|
||||
//import com.terraformersmc.modmenu.api.ConfigScreenFactory;
|
||||
//import com.terraformersmc.modmenu.api.ModMenuApi;
|
||||
//
|
||||
//import me.bionicbeanie.mods.savecoords.gui.impl.DIContainer;
|
||||
//
|
||||
//public class SaveCoordinatesModMenu implements ModMenuApi {
|
||||
//
|
||||
// @Override
|
||||
// public ConfigScreenFactory<?> getModConfigScreenFactory() {
|
||||
// return DIContainer.getModMenuScreenFactory();
|
||||
// }
|
||||
//}
|
||||
package me.bionicbeanie.mods.savecoords.modmenu;
|
||||
|
||||
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
|
||||
import com.terraformersmc.modmenu.api.ModMenuApi;
|
||||
|
||||
import me.bionicbeanie.mods.savecoords.gui.impl.DIContainer;
|
||||
|
||||
public class SaveCoordinatesModMenu implements ModMenuApi {
|
||||
|
||||
@Override
|
||||
public ConfigScreenFactory<?> getModConfigScreenFactory() {
|
||||
return DIContainer.getModMenuScreenFactory();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user