Add modmenu integration
This commit is contained in:
parent
bec6906b7e
commit
72456cf349
14
README.md
14
README.md
@ -1,8 +1,8 @@
|
||||
<img src="src/main/resources/assets/savecoords/icon.png" align="right" width="150px"/>
|
||||
|
||||
# Save Coordinates Fabric MC
|
||||
# Save Coordinates Fabric Mod
|
||||
|
||||
<a href ="https://github.com/cool-mist/SaveCoordinates/releases"><img src = "https://img.shields.io/github/v/release/cool-mist/SaveCoordinates?style=flat-square" /></a>
|
||||
<img src = "https://img.shields.io/github/v/release/cool-mist/SaveCoordinates?style=flat-square" /> <a href = "https://www.curseforge.com/minecraft/mc-mods/savecoordinates/files"><img src = "https://cf.way2muchnoise.eu/versions/savecoordinates_latest.svg"/> </a>
|
||||
|
||||
## Dependencies
|
||||
|
||||
@ -14,8 +14,8 @@ Minecraft|1.16.5
|
||||
|
||||
## Usage
|
||||
|
||||
- Press `H` for menu
|
||||
- Select `Save` to save the coordinate
|
||||
- Select `Ping` to ping the coordinate to other players
|
||||
- Select `List` to view saved coordinates
|
||||
- Select `+` to edit coordinate
|
||||
- Press `H` for menu (This is the default keybinding to open the mod ui)
|
||||
- Select `SAVE` to save the coordinate
|
||||
- Select `PING` to ping the coordinate to other players
|
||||
- Select `LIST` to view saved coordinates
|
||||
- Select `CONF` to update default keybinding
|
||||
@ -15,6 +15,11 @@ repositories {
|
||||
name = "CottonMC"
|
||||
url = "https://server.bbkr.space/artifactory/libs-release"
|
||||
}
|
||||
|
||||
maven {
|
||||
name = "TerraformersMC"
|
||||
url = "https://maven.terraformersmc.com/releases"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@ -23,6 +28,7 @@ dependencies {
|
||||
|
||||
modImplementation "net.fabricmc:fabric-loader:${project.loader_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}")
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
|
||||
loader_version=0.11.3
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 1.16.5-0.0.3
|
||||
mod_version = 1.16.5-1.0.0
|
||||
maven_group = me.bionicbeanie.mods.savecoords
|
||||
archives_base_name = save-coordinates
|
||||
|
||||
@ -19,4 +19,5 @@ org.gradle.jvmargs=-Xmx1G
|
||||
# https://github.com/CottonMC/LibGui/wiki/Setup
|
||||
libgui_version=3.4.0+1.16.5
|
||||
|
||||
clothconfig_version=4.11.26
|
||||
#https://maven.terraformersmc.com/releases/com/terraformersmc/modmenu/
|
||||
modmenu_version=1.16.9
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
package me.bionicbeanie.mods.savecoords;
|
||||
|
||||
public interface IModGui{
|
||||
void open();
|
||||
}
|
||||
@ -1,24 +1,17 @@
|
||||
package me.bionicbeanie.mods.savecoords;
|
||||
|
||||
import me.bionicbeanie.mods.savecoords.gui.IKeyBindConfiguration;
|
||||
import me.bionicbeanie.mods.savecoords.gui.impl.ModGui;
|
||||
import me.bionicbeanie.mods.savecoords.impl.Factory;
|
||||
import me.bionicbeanie.mods.savecoords.gui.impl.ModDI;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
|
||||
public class SaveCoordinatesClient implements ClientModInitializer {
|
||||
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
IFileStore fileStore = Factory.createFileStore(MinecraftClient.getInstance().runDirectory.getAbsolutePath());
|
||||
IKeyBindConfiguration keyBindConfiguration = Factory.createKeyBindConfiguration(fileStore);
|
||||
|
||||
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
||||
while (keyBindConfiguration.getDefaultKeyBinding().wasPressed()) {
|
||||
ModGui.start(client, fileStore, keyBindConfiguration);
|
||||
while (ModDI.getKeyBindConfiguration().getDefaultKeyBinding().wasPressed()) {
|
||||
ModDI.getModGui().open();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -78,8 +78,13 @@ class ListViewHandler extends ViewHandlerBase<Void> {
|
||||
private List<PlayerPosition> getPositions(IFileStore fileStore) {
|
||||
try {
|
||||
List<PlayerPosition> positions = fileStore.listPositions();
|
||||
Collections.sort(positions, (p1, p2) -> p2.getPositionMetadata().getLastModified()
|
||||
.compareTo(p1.getPositionMetadata().getLastModified()));
|
||||
Collections.sort(positions, (p1, p2) -> {
|
||||
if(p1.getPositionMetadata() != null && p2.getPositionMetadata() != null) {
|
||||
return p2.getPositionMetadata().getLastModified().compareTo(p1.getPositionMetadata().getLastModified());
|
||||
}
|
||||
|
||||
return -1;
|
||||
});
|
||||
return positions;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@ -148,8 +153,11 @@ class ListViewHandler extends ViewHandlerBase<Void> {
|
||||
this.icon.setImage(ResourceUtils.CreateWorldIconIdentifier(position.getWorldDimension()));
|
||||
this.location.setText(new LiteralText(position.getLocationName()));
|
||||
this.location.setColor(0x3939ac);
|
||||
this.world.setText(new LiteralText("[" + position.getPositionMetadata().getWorldName() + "]"));
|
||||
this.world.setColor(0xb80000);
|
||||
if(position.getPositionMetadata() != null) {
|
||||
this.world.setText(new LiteralText("[" + position.getPositionMetadata().getWorldName() + "]"));
|
||||
this.world.setColor(0xb80000);
|
||||
}
|
||||
|
||||
this.coordinates
|
||||
.setText(new LiteralText(position.getX() + ", " + position.getY() + ", " + position.getZ()));
|
||||
this.deleteButton.setOnClick(() -> onDelete.accept(position));
|
||||
|
||||
@ -0,0 +1,73 @@
|
||||
package me.bionicbeanie.mods.savecoords.gui.impl;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
|
||||
|
||||
import me.bionicbeanie.mods.savecoords.IFileStore;
|
||||
import me.bionicbeanie.mods.savecoords.IModGui;
|
||||
import me.bionicbeanie.mods.savecoords.IPlayerLocator;
|
||||
import me.bionicbeanie.mods.savecoords.gui.IKeyBindConfiguration;
|
||||
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 ModDI {
|
||||
|
||||
private static boolean initialized = false;
|
||||
private static IFileStore fileStore;
|
||||
private static IKeyBindConfiguration keyBindConfiguration;
|
||||
private static GuiController guiController;
|
||||
private static IPlayerLocator playerLocator;
|
||||
private static IModGui modGui;
|
||||
private static ConfigScreenFactory<Screen> modMenuScreenFactory;
|
||||
|
||||
public static IKeyBindConfiguration getKeyBindConfiguration() {
|
||||
initialize();
|
||||
return keyBindConfiguration;
|
||||
}
|
||||
|
||||
public static IModGui getModGui() {
|
||||
initialize();
|
||||
return modGui;
|
||||
}
|
||||
|
||||
public static ConfigScreenFactory<Screen> getModMenuScreenFactory(){
|
||||
if(modMenuScreenFactory == null) {
|
||||
modMenuScreenFactory = (parent) -> {
|
||||
ConfigViewHandler handler = new ConfigViewHandler();
|
||||
|
||||
handler.onSave(() -> {
|
||||
new SaveConfigsOperation(keyBindConfiguration, handler::getState).run();
|
||||
guiController.openScreen(parent);
|
||||
});
|
||||
|
||||
handler.onBack(() -> guiController.openScreen(parent));
|
||||
|
||||
try {
|
||||
return handler.createView(fileStore.readConfigData());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
}
|
||||
return modMenuScreenFactory;
|
||||
}
|
||||
|
||||
private static void initialize() {
|
||||
if(!initialized) {
|
||||
|
||||
initialized = true;
|
||||
|
||||
MinecraftClient minecraftClient = MinecraftClient.getInstance();
|
||||
fileStore = Factory.createFileStore(minecraftClient.runDirectory.getAbsolutePath());
|
||||
keyBindConfiguration = Factory.createKeyBindConfiguration(fileStore);
|
||||
guiController = new GuiController(minecraftClient);
|
||||
playerLocator = Factory.CreatePlayerLocator(minecraftClient);
|
||||
modGui = new SaveCoordinatesGui(fileStore, playerLocator, keyBindConfiguration, guiController);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,18 +0,0 @@
|
||||
package me.bionicbeanie.mods.savecoords.gui.impl;
|
||||
|
||||
import me.bionicbeanie.mods.savecoords.IFileStore;
|
||||
import me.bionicbeanie.mods.savecoords.IPlayerLocator;
|
||||
import me.bionicbeanie.mods.savecoords.gui.IGuiController;
|
||||
import me.bionicbeanie.mods.savecoords.gui.IKeyBindConfiguration;
|
||||
import me.bionicbeanie.mods.savecoords.impl.Factory;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
|
||||
public class ModGui {
|
||||
|
||||
public static void start(MinecraftClient client, IFileStore fileStore, IKeyBindConfiguration keyBindConfiguration) {
|
||||
IGuiController controller = new GuiController(client);
|
||||
IPlayerLocator locator = Factory.CreatePlayerLocator(client);
|
||||
|
||||
new SaveCoordinatesGui(fileStore, locator, keyBindConfiguration, controller);
|
||||
}
|
||||
}
|
||||
@ -10,15 +10,14 @@ public class SaveConfigsOperation extends ViewOperationBase<ConfigData>{
|
||||
|
||||
private IKeyBindConfiguration keyBindConfiguration;
|
||||
|
||||
public SaveConfigsOperation(IFileStore fileStore, IKeyBindConfiguration keyBindConfiguration, Supplier<ConfigData> stateSupplier) {
|
||||
super(fileStore, stateSupplier);
|
||||
public SaveConfigsOperation(IKeyBindConfiguration keyBindConfiguration, Supplier<ConfigData> stateSupplier) {
|
||||
super(null, stateSupplier);
|
||||
|
||||
this.keyBindConfiguration = keyBindConfiguration;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executeOperation(IFileStore fileStore, ConfigData state) throws Exception {
|
||||
fileStore.writeConfigs(state);
|
||||
this.keyBindConfiguration.setDefaultKeyBinding(state.getDefaultKeyBindingCode());
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ package me.bionicbeanie.mods.savecoords.gui.impl;
|
||||
import java.io.IOException;
|
||||
|
||||
import me.bionicbeanie.mods.savecoords.IFileStore;
|
||||
import me.bionicbeanie.mods.savecoords.IModGui;
|
||||
import me.bionicbeanie.mods.savecoords.IPlayerLocator;
|
||||
import me.bionicbeanie.mods.savecoords.gui.IGuiController;
|
||||
import me.bionicbeanie.mods.savecoords.gui.IKeyBindConfiguration;
|
||||
@ -10,8 +11,9 @@ import me.bionicbeanie.mods.savecoords.gui.IViewHandler;
|
||||
import me.bionicbeanie.mods.savecoords.model.ConfigData;
|
||||
import me.bionicbeanie.mods.savecoords.model.PlayerPosition;
|
||||
import me.bionicbeanie.mods.savecoords.model.PlayerRawPosition;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
|
||||
public class SaveCoordinatesGui {
|
||||
public class SaveCoordinatesGui implements IModGui {
|
||||
|
||||
private IGuiController screenController;
|
||||
private IFileStore fileStore;
|
||||
@ -32,9 +34,23 @@ public class SaveCoordinatesGui {
|
||||
this.listHandler = CreateListViewHandler();
|
||||
this.configHandler = CreateConfigHandler();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
showDefaultView(null);
|
||||
}
|
||||
|
||||
private Screen createConfigScreen() {
|
||||
try {
|
||||
return this.configHandler.createView(fileStore.readConfigData());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private IViewHandler<PlayerPosition> CreateDefaultViewHandler() {
|
||||
DefaultViewHandler handler = new DefaultViewHandler(fileStore, locator);
|
||||
|
||||
@ -84,7 +100,7 @@ public class SaveCoordinatesGui {
|
||||
}
|
||||
|
||||
private void onSaveConfigs() {
|
||||
new SaveConfigsOperation(fileStore, keyBindConfiguration, configHandler::getState).run();
|
||||
new SaveConfigsOperation(keyBindConfiguration, configHandler::getState).run();
|
||||
showDefaultView(null);
|
||||
}
|
||||
|
||||
@ -97,10 +113,7 @@ public class SaveCoordinatesGui {
|
||||
}
|
||||
|
||||
private void showConfigView() {
|
||||
try {
|
||||
screenController.openScreen(this.configHandler.createView(fileStore.readConfigData()));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
screenController.openScreen(createConfigScreen());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -52,7 +52,8 @@ class FileStore implements IFileStore {
|
||||
public ConfigData readConfigData() throws IOException {
|
||||
ModData data = load();
|
||||
|
||||
return data.getConfigData();
|
||||
ConfigData ret = data.getConfigData();
|
||||
return ret != null ? ret : new ConfigData();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -10,11 +10,13 @@ import net.minecraft.client.util.InputUtil;
|
||||
|
||||
class KeyBindConfiguration implements IKeyBindConfiguration {
|
||||
|
||||
KeyBinding defaultKeyBinding;
|
||||
private KeyBinding defaultKeyBinding;
|
||||
private IFileStore fileStore;
|
||||
|
||||
KeyBindConfiguration(IFileStore fileStore) {
|
||||
this.fileStore = fileStore;
|
||||
try {
|
||||
defaultKeyBinding = createDefaultKeyBinding(fileStore);
|
||||
this.defaultKeyBinding = createDefaultKeyBinding(fileStore);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException();
|
||||
@ -28,10 +30,22 @@ class KeyBindConfiguration implements IKeyBindConfiguration {
|
||||
|
||||
@Override
|
||||
public void setDefaultKeyBinding(int keyCode) {
|
||||
writeConfigs(keyCode);
|
||||
defaultKeyBinding.setBoundKey(InputUtil.Type.KEYSYM.createFromCode(keyCode));
|
||||
KeyBinding.updateKeysByCode();
|
||||
}
|
||||
|
||||
private void writeConfigs(int keyCode) {
|
||||
try {
|
||||
ConfigData data = fileStore.readConfigData();
|
||||
data.setDefaultKeyBindingCode(keyCode);
|
||||
|
||||
fileStore.writeConfigs(data);
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private KeyBinding createDefaultKeyBinding(IFileStore fileStore) throws IOException {
|
||||
|
||||
ConfigData configData = fileStore.readConfigData();
|
||||
|
||||
@ -0,0 +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.ModDI;
|
||||
|
||||
public class SaveCoordinatesModMenu implements ModMenuApi {
|
||||
|
||||
@Override
|
||||
public ConfigScreenFactory<?> getModConfigScreenFactory() {
|
||||
return ModDI.getModMenuScreenFactory();
|
||||
}
|
||||
}
|
||||
@ -15,7 +15,7 @@ public class ResourceUtils {
|
||||
public static Identifier CreateWorldIconIdentifier(String dimension) {
|
||||
|
||||
if (dimension == null)
|
||||
return CreateIdentifier("nonExistent");
|
||||
return CreateIdentifier("nonexistent");
|
||||
if (dimension.contains("overworld"))
|
||||
return CreateIdentifier("overworld");
|
||||
if (dimension.contains("nether"))
|
||||
@ -23,7 +23,7 @@ public class ResourceUtils {
|
||||
if (dimension.contains("end"))
|
||||
return CreateIdentifier("end");
|
||||
|
||||
return CreateIdentifier("nonExistent");
|
||||
return CreateIdentifier("nonexistent");
|
||||
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 195 B After Width: | Height: | Size: 208 B |
@ -1,36 +1,35 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "savecoords",
|
||||
"version": "${version}",
|
||||
|
||||
"name": "Save Coordinates",
|
||||
"description": "Fabric mod to store the current coordinates",
|
||||
"authors": [
|
||||
"cool-mist"
|
||||
],
|
||||
"contact": {
|
||||
"homepage": "https://mods.bionicbeanie.me/SaveCoordinates",
|
||||
"sources": "https://github.com/cool-mist/SaveCoordinates"
|
||||
},
|
||||
|
||||
"license": "CC0-1.0",
|
||||
"icon": "assets/savecoords/icon.png",
|
||||
|
||||
"environment": "*",
|
||||
"entrypoints": {
|
||||
"client": [
|
||||
"me.bionicbeanie.mods.savecoords.SaveCoordinatesClient"
|
||||
]
|
||||
},
|
||||
"mixins": [
|
||||
],
|
||||
|
||||
"depends": {
|
||||
"fabricloader": ">=0.7.4",
|
||||
"fabric": "*",
|
||||
"minecraft": "1.16.x"
|
||||
},
|
||||
"suggests": {
|
||||
"another-mod": "*"
|
||||
}
|
||||
"schemaVersion": 1,
|
||||
"id": "savecoords",
|
||||
"version": "${version}",
|
||||
"name": "Save Coordinates",
|
||||
"description": "SaveCoordinates is a client side coordinate manager mod. This helps to avoid context switching when looking for or sharing in-game coordinates",
|
||||
"authors": [
|
||||
"cool-mist"
|
||||
],
|
||||
"contact": {
|
||||
"homepage": "https://github.com/cool-mist/SaveCoordinates",
|
||||
"sources": "https://github.com/cool-mist/SaveCoordinates",
|
||||
"issues" : "https://github.com/cool-mist/SaveCoordinates/issues"
|
||||
},
|
||||
"license": "LGPLv3",
|
||||
"icon": "assets/savecoords/icon.png",
|
||||
"environment": "client",
|
||||
"entrypoints": {
|
||||
"client": [
|
||||
"me.bionicbeanie.mods.savecoords.SaveCoordinatesClient"
|
||||
],
|
||||
"modmenu": [
|
||||
"me.bionicbeanie.mods.savecoords.modmenu.SaveCoordinatesModMenu"
|
||||
]
|
||||
},
|
||||
"mixins": [],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.7.4",
|
||||
"fabric": ">=0.34.2",
|
||||
"minecraft": "1.16.5"
|
||||
},
|
||||
"suggests": {
|
||||
"another-mod": "modmenu"
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user