Fix modularity
@ -15,15 +15,21 @@ repositories {
|
||||
name = "CottonMC"
|
||||
url = "https://server.bbkr.space/artifactory/libs-release"
|
||||
}
|
||||
maven {
|
||||
name = "ClothConfig"
|
||||
url = "https://maven.shedaniel.me/"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
||||
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
|
||||
|
||||
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||
modImplementation include("io.github.cottonmc:LibGui:${project.libgui_version}")
|
||||
modImplementation include("me.shedaniel.cloth:cloth-config-fabric:${project.clothconfig_version}")
|
||||
}
|
||||
|
||||
processResources {
|
||||
|
||||
@ -9,7 +9,7 @@ org.gradle.jvmargs=-Xmx1G
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 1.16.5-0.0.3
|
||||
maven_group = me.bionicbeanie.mods
|
||||
maven_group = me.bionicbeanie.mods.savecoords
|
||||
archives_base_name = save-coordinates
|
||||
|
||||
# Dependencies
|
||||
@ -18,3 +18,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
|
||||
|
||||
@ -1,62 +0,0 @@
|
||||
package me.bionicbeanie.mods;
|
||||
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import me.bionicbeanie.mods.api.IFileStore;
|
||||
import me.bionicbeanie.mods.api.IGui;
|
||||
import me.bionicbeanie.mods.api.IViewHandler;
|
||||
import me.bionicbeanie.mods.api.IPlayerLocator;
|
||||
import me.bionicbeanie.mods.api.IScreenController;
|
||||
import me.bionicbeanie.mods.gui.SaveCoordinatesGui;
|
||||
import me.bionicbeanie.mods.gui.ScreenController;
|
||||
import me.bionicbeanie.mods.gui.view.DefaultViewHandler;
|
||||
import me.bionicbeanie.mods.gui.view.ListViewHandler;
|
||||
import me.bionicbeanie.mods.impl.FileStore;
|
||||
import me.bionicbeanie.mods.impl.PlayerLocator;
|
||||
import me.bionicbeanie.mods.model.PlayerPosition;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.options.KeyBinding;
|
||||
import net.minecraft.client.util.InputUtil;
|
||||
|
||||
public class SaveCoordinatesClient implements ClientModInitializer {
|
||||
|
||||
private static IPlayerLocator locator = new PlayerLocator();
|
||||
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
|
||||
KeyBinding keyBinding = registerKeyBinding();
|
||||
|
||||
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
||||
while (keyBinding.wasPressed()) {
|
||||
IGui gui = CreateModGui(client);
|
||||
gui.showDefaultView();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private KeyBinding registerKeyBinding() {
|
||||
String translationKey = "key.savecoords.coords";
|
||||
String category = "category.savecoords.generic";
|
||||
int keyBind = GLFW.GLFW_KEY_H;
|
||||
|
||||
KeyBinding keyBinding = new KeyBinding(translationKey, InputUtil.Type.KEYSYM, keyBind, category);
|
||||
|
||||
return KeyBindingHelper.registerKeyBinding(keyBinding);
|
||||
}
|
||||
|
||||
private IGui CreateModGui(MinecraftClient client) {
|
||||
IGui gui = new SaveCoordinatesGui();
|
||||
IFileStore fileStore = new FileStore(client.runDirectory.getAbsolutePath());
|
||||
IViewHandler<PlayerPosition> defaultHandler = new DefaultViewHandler(fileStore, locator, client, gui);
|
||||
IViewHandler<Void> listHandler = new ListViewHandler(fileStore, gui, client);
|
||||
IScreenController screenController = new ScreenController(client);
|
||||
|
||||
gui.init(defaultHandler, listHandler, screenController);
|
||||
|
||||
return gui;
|
||||
}
|
||||
}
|
||||
@ -1,19 +0,0 @@
|
||||
package me.bionicbeanie.mods.api;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import me.bionicbeanie.mods.model.PlayerPosition;
|
||||
|
||||
public interface IFileStore {
|
||||
|
||||
public String getDefaultWorld() throws IOException;
|
||||
|
||||
public void setDefaultWorld(String defaultWorldName) throws IOException;
|
||||
|
||||
public void save(PlayerPosition position) throws IOException;
|
||||
|
||||
public void delete(String id) throws IOException;
|
||||
|
||||
public List<PlayerPosition> list() throws IOException;
|
||||
}
|
||||
@ -1,18 +0,0 @@
|
||||
package me.bionicbeanie.mods.api;
|
||||
|
||||
import me.bionicbeanie.mods.model.PlayerPosition;
|
||||
|
||||
public interface IGui {
|
||||
|
||||
public void init(IViewHandler<PlayerPosition> saveHandler, IViewHandler<Void> listHandler,
|
||||
IScreenController screenController);
|
||||
|
||||
public void showDefaultView();
|
||||
|
||||
public void setDefaultViewState(PlayerPosition position);
|
||||
|
||||
public void showListView();
|
||||
|
||||
public void close();
|
||||
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
package me.bionicbeanie.mods.api;
|
||||
|
||||
import me.bionicbeanie.mods.model.PlayerRawPosition;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
|
||||
public interface IPlayerLocator {
|
||||
|
||||
public PlayerRawPosition locate(MinecraftClient client);
|
||||
}
|
||||
@ -1,13 +0,0 @@
|
||||
package me.bionicbeanie.mods.api;
|
||||
|
||||
import io.github.cottonmc.cotton.gui.GuiDescription;
|
||||
import io.github.cottonmc.cotton.gui.widget.WWidget;
|
||||
|
||||
public interface IRootGridPanel {
|
||||
|
||||
public void add(WWidget widget, int x, int y, int w, int h);
|
||||
|
||||
public void validate(GuiDescription gui);
|
||||
|
||||
public void reset();
|
||||
}
|
||||
@ -1,10 +0,0 @@
|
||||
package me.bionicbeanie.mods.api;
|
||||
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
|
||||
public interface IScreenController {
|
||||
|
||||
public void openScreen(Screen screen);
|
||||
|
||||
public void closeScreen();
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
package me.bionicbeanie.mods.api;
|
||||
|
||||
public interface IViewHandler<T> {
|
||||
|
||||
void setState(T state);
|
||||
void clearState();
|
||||
void placeWidgets(IRootGridPanel rootPanel);
|
||||
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
package me.bionicbeanie.mods.api;
|
||||
|
||||
public interface IViewOperation extends Runnable {
|
||||
|
||||
}
|
||||
@ -1,66 +0,0 @@
|
||||
package me.bionicbeanie.mods.gui;
|
||||
|
||||
import io.github.cottonmc.cotton.gui.client.LightweightGuiDescription;
|
||||
import me.bionicbeanie.mods.api.IGui;
|
||||
import me.bionicbeanie.mods.api.IViewHandler;
|
||||
import me.bionicbeanie.mods.model.PlayerPosition;
|
||||
import me.bionicbeanie.mods.api.IRootGridPanel;
|
||||
import me.bionicbeanie.mods.api.IScreenController;
|
||||
|
||||
public class SaveCoordinatesGui extends LightweightGuiDescription implements IGui {
|
||||
|
||||
private IRootGridPanel rootGridPanel;
|
||||
private IViewHandler<PlayerPosition> defaultHandler;
|
||||
private IViewHandler<Void> listHandler;
|
||||
private IScreenController screenController;
|
||||
|
||||
@Override
|
||||
public void init(IViewHandler<PlayerPosition> saveHandler, IViewHandler<Void> listHandler,
|
||||
IScreenController screenController) {
|
||||
this.rootGridPanel = createRootPanel();
|
||||
this.defaultHandler = saveHandler;
|
||||
this.listHandler = listHandler;
|
||||
this.screenController = screenController;
|
||||
|
||||
openScreen();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showDefaultView() {
|
||||
showView(defaultHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDefaultViewState(PlayerPosition position) {
|
||||
defaultHandler.setState(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showListView() {
|
||||
showView(listHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
screenController.closeScreen();
|
||||
}
|
||||
|
||||
private void openScreen() {
|
||||
screenController.openScreen(new SaveCoordinatesScreen(this));
|
||||
}
|
||||
|
||||
private IRootGridPanel createRootPanel() {
|
||||
RootGridPanel panel = new RootGridPanel(18);
|
||||
panel.setSize(15 * 18, 10 * 18);
|
||||
|
||||
setRootPanel(panel);
|
||||
return panel;
|
||||
}
|
||||
|
||||
private void showView(IViewHandler<?> handler) {
|
||||
rootGridPanel.reset();
|
||||
handler.placeWidgets(rootGridPanel);
|
||||
rootGridPanel.validate(this);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,149 +0,0 @@
|
||||
package me.bionicbeanie.mods.gui.view;
|
||||
|
||||
import io.github.cottonmc.cotton.gui.widget.WButton;
|
||||
import io.github.cottonmc.cotton.gui.widget.WLabel;
|
||||
import io.github.cottonmc.cotton.gui.widget.WText;
|
||||
import io.github.cottonmc.cotton.gui.widget.WTextField;
|
||||
import io.github.cottonmc.cotton.gui.widget.WWidget;
|
||||
import me.bionicbeanie.mods.api.IFileStore;
|
||||
import me.bionicbeanie.mods.api.IGui;
|
||||
import me.bionicbeanie.mods.api.IPlayerLocator;
|
||||
import me.bionicbeanie.mods.api.IRootGridPanel;
|
||||
import me.bionicbeanie.mods.model.PlayerPosition;
|
||||
import me.bionicbeanie.mods.model.PlayerRawPosition;
|
||||
import me.bionicbeanie.mods.util.DimensionSpriteUtil;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.text.LiteralText;
|
||||
|
||||
public class DefaultViewHandler extends ViewHandlerBase<PlayerPosition> {
|
||||
|
||||
private IPlayerLocator locator;
|
||||
|
||||
public DefaultViewHandler(IFileStore fileStore, IPlayerLocator locator, MinecraftClient client, IGui gui) {
|
||||
super(fileStore, gui, client);
|
||||
this.locator = locator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void placeWidgets(IRootGridPanel root, PlayerPosition existingPosition) {
|
||||
|
||||
PlayerRawPosition rawPosition = existingPosition == null ? locator.locate(client) : existingPosition;
|
||||
|
||||
WWidget xLabel = CreateLabelForCoorindate("X");
|
||||
WWidget yLabel = CreateLabelForCoorindate("Y");
|
||||
WWidget zLabel = CreateLabelForCoorindate("Z");
|
||||
|
||||
WWidget xText = CreateWidgetForCoordinate(rawPosition.getX());
|
||||
WWidget yText = CreateWidgetForCoordinate(rawPosition.getY());
|
||||
WWidget zText = CreateWidgetForCoordinate(rawPosition.getZ());
|
||||
|
||||
root.add(xLabel, 2, 1, 2, 1);
|
||||
root.add(yLabel, 2, 2, 2, 1);
|
||||
root.add(zLabel, 2, 3, 2, 1);
|
||||
|
||||
root.add(xText, 3, 1, 2, 1);
|
||||
root.add(yText, 3, 2, 2, 1);
|
||||
root.add(zText, 3, 3, 2, 1);
|
||||
|
||||
WWidget icon = DimensionSpriteUtil.CreateWorldIcon(rawPosition.getWorldDimension());
|
||||
root.add(icon, 8, 1, 2, 2);
|
||||
|
||||
String defaultWorld = getDefaultWorld(existingPosition);
|
||||
WTextField world = CreateWorldField(defaultWorld);
|
||||
root.add(world, 0, 4, 4, 1);
|
||||
|
||||
WTextField location = CreateLocationField(existingPosition);
|
||||
root.add(location, 5, 4, 7, 1);
|
||||
|
||||
WTextField notes = CreateNotesField(existingPosition);
|
||||
root.add(notes, 0, 6, 12, 1);
|
||||
|
||||
WWidget save = CreateSaveButton(rawPosition, location, notes, world, existingPosition);
|
||||
root.add(save, 13, 6, 2, 1);
|
||||
|
||||
WWidget list = CreateListButton();
|
||||
root.add(list, 13, 9, 2, 1);
|
||||
|
||||
WWidget ping = CreatePingButton(rawPosition);
|
||||
root.add(ping, 13, 1, 2, 1);
|
||||
|
||||
WWidget close = CreateCloseButton();
|
||||
root.add(close, 0, 9, 2, 1);
|
||||
}
|
||||
|
||||
private String getDefaultWorld(PlayerPosition existingPosition) {
|
||||
if (existingPosition != null && existingPosition.getPositionMetadata().getWorldName() != null) {
|
||||
return existingPosition.getPositionMetadata().getWorldName();
|
||||
}
|
||||
|
||||
try {
|
||||
return fileStore.getDefaultWorld();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
private WWidget CreateLabelForCoorindate(String label) {
|
||||
return new WLabel(label, 0xb80000);
|
||||
}
|
||||
|
||||
private WWidget CreateWidgetForCoordinate(long l) {
|
||||
return new WText(new LiteralText(String.valueOf(l)), 0x3939ac);
|
||||
}
|
||||
|
||||
private WTextField CreateLocationField(PlayerPosition existingPosition) {
|
||||
WTextField location = new WTextField(new LiteralText("location name"));
|
||||
|
||||
if (existingPosition != null) {
|
||||
location.setText(existingPosition.getLocationName());
|
||||
}
|
||||
|
||||
location.setMaxLength(20);
|
||||
|
||||
return location;
|
||||
}
|
||||
|
||||
private WTextField CreateNotesField(PlayerPosition existingPosition) {
|
||||
WTextField notes = new WTextField(new LiteralText("additional notes"));
|
||||
|
||||
if (existingPosition != null && existingPosition.getPositionMetadata() != null) {
|
||||
notes.setText(existingPosition.getPositionMetadata().getNotes());
|
||||
}
|
||||
|
||||
return notes;
|
||||
}
|
||||
|
||||
private WTextField CreateWorldField(String defaultWorld) {
|
||||
WTextField world = new WTextField(new LiteralText("world name"));
|
||||
world.setMaxLength(7);
|
||||
world.setText(defaultWorld);
|
||||
return world;
|
||||
}
|
||||
|
||||
private WWidget CreateSaveButton(PlayerRawPosition rawPosition, WTextField location, WTextField notes,
|
||||
WTextField world, PlayerPosition existingPosition) {
|
||||
WButton button = new WButton(new LiteralText("SAVE"));
|
||||
button.setOnClick(new SaveOperation(fileStore, gui, rawPosition, world, location, notes, existingPosition));
|
||||
return button;
|
||||
}
|
||||
|
||||
private WWidget CreateListButton() {
|
||||
WButton button = new WButton(new LiteralText("LIST"));
|
||||
button.setOnClick(gui::showListView);
|
||||
return button;
|
||||
}
|
||||
|
||||
private WWidget CreatePingButton(PlayerRawPosition rawPosition) {
|
||||
WButton button = new WButton(new LiteralText("PING"));
|
||||
button.setOnClick(new PingOperation(fileStore, gui, rawPosition));
|
||||
return button;
|
||||
}
|
||||
|
||||
private WWidget CreateCloseButton() {
|
||||
WButton button = new WButton(new LiteralText("CLOSE"));
|
||||
button.setOnClick(gui::close);
|
||||
return button;
|
||||
}
|
||||
}
|
||||
@ -1,18 +0,0 @@
|
||||
package me.bionicbeanie.mods.gui.view;
|
||||
|
||||
import me.bionicbeanie.mods.api.IFileStore;
|
||||
import me.bionicbeanie.mods.api.IGui;
|
||||
import me.bionicbeanie.mods.model.PlayerPosition;
|
||||
|
||||
public class DeleteOperation extends ViewPositionOperationBase {
|
||||
|
||||
public DeleteOperation(IFileStore fileStore, IGui gui, PlayerPosition position) {
|
||||
super(fileStore, gui, position);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executeOperation(IFileStore fileStore, IGui gui, PlayerPosition position) throws Exception {
|
||||
fileStore.delete(position.getId());
|
||||
gui.showListView();
|
||||
}
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
package me.bionicbeanie.mods.gui.view;
|
||||
|
||||
import me.bionicbeanie.mods.api.IFileStore;
|
||||
import me.bionicbeanie.mods.api.IGui;
|
||||
import me.bionicbeanie.mods.model.PlayerRawPosition;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
|
||||
public class PingOperation extends ViewOperationBase{
|
||||
|
||||
private PlayerRawPosition position;
|
||||
|
||||
public PingOperation(IFileStore fileStore, IGui gui, PlayerRawPosition position) {
|
||||
super(fileStore, gui);
|
||||
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
@Override
|
||||
protected void executeOperation(IFileStore fileStore, IGui gui) throws Exception {
|
||||
MinecraftClient.getInstance().player.sendChatMessage(position.toString());
|
||||
}
|
||||
}
|
||||
@ -1,54 +0,0 @@
|
||||
package me.bionicbeanie.mods.gui.view;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import io.github.cottonmc.cotton.gui.widget.WTextField;
|
||||
import me.bionicbeanie.mods.api.IFileStore;
|
||||
import me.bionicbeanie.mods.api.IGui;
|
||||
import me.bionicbeanie.mods.model.PlayerPosition;
|
||||
import me.bionicbeanie.mods.model.PlayerRawPosition;
|
||||
import me.bionicbeanie.mods.model.PositionMetadata;
|
||||
|
||||
public class SaveOperation extends ViewOperationBase {
|
||||
|
||||
private PlayerRawPosition rawPosition;
|
||||
private WTextField location, notes;
|
||||
private WTextField world;
|
||||
private PlayerPosition existingPosition;
|
||||
|
||||
public SaveOperation(IFileStore fileStore, IGui gui, PlayerRawPosition rawPosition, WTextField world,
|
||||
WTextField location, WTextField notes, PlayerPosition existingPosition) {
|
||||
super(fileStore, gui);
|
||||
this.rawPosition = rawPosition;
|
||||
this.existingPosition = existingPosition;
|
||||
this.world = world;
|
||||
this.location = location;
|
||||
this.notes = notes;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executeOperation(IFileStore fileStore, IGui gui) throws Exception {
|
||||
|
||||
String id = existingPosition == null ? UUID.randomUUID().toString() : existingPosition.getId();
|
||||
PositionMetadata metadata = CreateMetadata(existingPosition);
|
||||
|
||||
PlayerPosition position = new PlayerPosition(id, rawPosition, this.location.getText(), metadata);
|
||||
|
||||
fileStore.save(position);
|
||||
fileStore.setDefaultWorld(position.getPositionMetadata().getWorldName());
|
||||
gui.showListView();
|
||||
gui.setDefaultViewState(null);
|
||||
}
|
||||
|
||||
private PositionMetadata CreateMetadata(PlayerPosition existingPosition) {
|
||||
if(existingPosition == null) {
|
||||
return new PositionMetadata(this.world.getText(), this.notes.getText());
|
||||
}
|
||||
|
||||
existingPosition.getPositionMetadata().setWorldName(this.world.getText());
|
||||
existingPosition.getPositionMetadata().setNotes(this.notes.getText());
|
||||
existingPosition.getPositionMetadata().updateLastModified();
|
||||
|
||||
return existingPosition.getPositionMetadata();
|
||||
}
|
||||
}
|
||||
@ -1,19 +0,0 @@
|
||||
package me.bionicbeanie.mods.gui.view;
|
||||
|
||||
import me.bionicbeanie.mods.api.IFileStore;
|
||||
import me.bionicbeanie.mods.api.IGui;
|
||||
import me.bionicbeanie.mods.model.PlayerPosition;
|
||||
|
||||
public class ShowDetailOperation extends ViewPositionOperationBase {
|
||||
|
||||
public ShowDetailOperation(IFileStore fileStore, IGui gui, PlayerPosition position) {
|
||||
super(fileStore, gui, position);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executeOperation(IFileStore fileStore, IGui gui, PlayerPosition position) throws Exception {
|
||||
gui.setDefaultViewState(position);
|
||||
gui.showDefaultView();
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,41 +0,0 @@
|
||||
package me.bionicbeanie.mods.gui.view;
|
||||
|
||||
import io.github.cottonmc.cotton.gui.widget.WWidget;
|
||||
import me.bionicbeanie.mods.api.IFileStore;
|
||||
import me.bionicbeanie.mods.api.IGui;
|
||||
import me.bionicbeanie.mods.api.IRootGridPanel;
|
||||
import me.bionicbeanie.mods.api.IViewHandler;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
|
||||
public abstract class ViewHandlerBase<T> implements IViewHandler<T> {
|
||||
|
||||
protected IFileStore fileStore;
|
||||
protected IGui gui;
|
||||
protected MinecraftClient client;
|
||||
protected WWidget panel;
|
||||
private T state;
|
||||
|
||||
protected ViewHandlerBase(IFileStore fileStore, IGui gui, MinecraftClient client) {
|
||||
this.fileStore = fileStore;
|
||||
this.gui = gui;
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
protected abstract void placeWidgets(IRootGridPanel rootPanel, T state);
|
||||
|
||||
@Override
|
||||
public void clearState() {
|
||||
state = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setState(T state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void placeWidgets(IRootGridPanel rootPanel) {
|
||||
placeWidgets(rootPanel, state);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,26 +0,0 @@
|
||||
package me.bionicbeanie.mods.gui.view;
|
||||
|
||||
import me.bionicbeanie.mods.api.IFileStore;
|
||||
import me.bionicbeanie.mods.api.IGui;
|
||||
|
||||
public abstract class ViewOperationBase implements Runnable {
|
||||
|
||||
private IFileStore fileStore;
|
||||
private IGui gui;
|
||||
|
||||
public ViewOperationBase(IFileStore fileStore, IGui gui) {
|
||||
this.fileStore = fileStore;
|
||||
this.gui = gui;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
executeOperation(fileStore, gui);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void executeOperation(IFileStore fileStore, IGui gui) throws Exception;
|
||||
}
|
||||
@ -1,22 +0,0 @@
|
||||
package me.bionicbeanie.mods.gui.view;
|
||||
|
||||
import me.bionicbeanie.mods.api.IFileStore;
|
||||
import me.bionicbeanie.mods.api.IGui;
|
||||
import me.bionicbeanie.mods.model.PlayerPosition;
|
||||
|
||||
public abstract class ViewPositionOperationBase extends ViewOperationBase{
|
||||
|
||||
private PlayerPosition position;
|
||||
|
||||
public ViewPositionOperationBase(IFileStore fileStore, IGui gui, PlayerPosition position) {
|
||||
super(fileStore, gui);
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executeOperation(IFileStore fileStore, IGui gui) throws Exception {
|
||||
executeOperation(fileStore, gui, position);
|
||||
}
|
||||
|
||||
protected abstract void executeOperation(IFileStore fileStore, IGui gui, PlayerPosition position) throws Exception;
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package me.bionicbeanie.mods.savecoords;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import me.bionicbeanie.mods.savecoords.model.PlayerPosition;
|
||||
|
||||
public interface IFileStore {
|
||||
String getDefaultWorld() throws IOException;
|
||||
|
||||
void setDefaultWorld(String defaultWorldName) throws IOException;
|
||||
|
||||
void save(PlayerPosition position) throws IOException;
|
||||
|
||||
void delete(String id) throws IOException;
|
||||
|
||||
List<PlayerPosition> list() throws IOException;
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
package me.bionicbeanie.mods.savecoords;
|
||||
|
||||
import me.bionicbeanie.mods.savecoords.model.PlayerRawPosition;
|
||||
|
||||
public interface IPlayerLocator {
|
||||
PlayerRawPosition locate();
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
package me.bionicbeanie.mods.savecoords;
|
||||
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import me.bionicbeanie.mods.savecoords.gui.impl.ModGui;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
||||
import net.minecraft.client.options.KeyBinding;
|
||||
import net.minecraft.client.util.InputUtil;
|
||||
|
||||
public class SaveCoordinatesClient implements ClientModInitializer {
|
||||
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
|
||||
KeyBinding keyBinding = registerKeyBinding();
|
||||
|
||||
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
||||
while (keyBinding.wasPressed()) {
|
||||
ModGui.start(client);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private KeyBinding registerKeyBinding() {
|
||||
String translationKey = "key.savecoords.coords";
|
||||
String category = "category.savecoords.generic";
|
||||
int keyBind = GLFW.GLFW_KEY_H;
|
||||
|
||||
KeyBinding keyBinding = new KeyBinding(translationKey, InputUtil.Type.KEYSYM, keyBind, category);
|
||||
|
||||
return KeyBindingHelper.registerKeyBinding(keyBinding);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
package me.bionicbeanie.mods.savecoords.gui;
|
||||
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
|
||||
public interface IGuiController {
|
||||
void openScreen(Screen screen);
|
||||
|
||||
void closeScreen();
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
package me.bionicbeanie.mods.savecoords.gui;
|
||||
|
||||
import io.github.cottonmc.cotton.gui.widget.WWidget;
|
||||
|
||||
public interface IRootPanel {
|
||||
void add(WWidget widget, int x, int y, int w, int h);
|
||||
|
||||
void validate();
|
||||
|
||||
void reset();
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
package me.bionicbeanie.mods.savecoords.gui;
|
||||
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
|
||||
public interface IViewHandler<T> {
|
||||
Screen createView(T state);
|
||||
|
||||
T getState();
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package me.bionicbeanie.mods.gui;
|
||||
package me.bionicbeanie.mods.savecoords.gui;
|
||||
|
||||
import io.github.cottonmc.cotton.gui.GuiDescription;
|
||||
import io.github.cottonmc.cotton.gui.client.CottonClientScreen;
|
||||
@ -8,5 +8,4 @@ public class SaveCoordinatesScreen extends CottonClientScreen {
|
||||
public SaveCoordinatesScreen(GuiDescription description) {
|
||||
super(description);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,193 @@
|
||||
package me.bionicbeanie.mods.savecoords.gui.impl;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import io.github.cottonmc.cotton.gui.widget.WButton;
|
||||
import io.github.cottonmc.cotton.gui.widget.WLabel;
|
||||
import io.github.cottonmc.cotton.gui.widget.WText;
|
||||
import io.github.cottonmc.cotton.gui.widget.WTextField;
|
||||
import io.github.cottonmc.cotton.gui.widget.WWidget;
|
||||
import me.bionicbeanie.mods.savecoords.IFileStore;
|
||||
import me.bionicbeanie.mods.savecoords.IPlayerLocator;
|
||||
import me.bionicbeanie.mods.savecoords.gui.IRootPanel;
|
||||
import me.bionicbeanie.mods.savecoords.model.PlayerPosition;
|
||||
import me.bionicbeanie.mods.savecoords.model.PlayerRawPosition;
|
||||
import me.bionicbeanie.mods.savecoords.model.PositionMetadata;
|
||||
import me.bionicbeanie.mods.savecoords.util.ResourceUtils;
|
||||
import net.minecraft.text.LiteralText;
|
||||
|
||||
class DefaultViewHandler extends ViewHandlerBase<PlayerPosition> {
|
||||
|
||||
private IPlayerLocator locator;
|
||||
private IFileStore fileStore;
|
||||
private WButton saveButton;
|
||||
private WButton listButton;
|
||||
private WButton pingButton;
|
||||
private WButton closeButton;
|
||||
private WButton configButton;
|
||||
|
||||
public DefaultViewHandler(IFileStore fileStore, IPlayerLocator locator) {
|
||||
this.fileStore = fileStore;
|
||||
this.locator = locator;
|
||||
|
||||
this.listButton = CreateButton("LIST");
|
||||
this.saveButton = CreateButton("SAVE");
|
||||
this.pingButton = CreatePingButton();
|
||||
this.closeButton = CreateButton("CLOSE");
|
||||
this.configButton = CreateButton("CONF");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Supplier<PlayerPosition> placeWidgets(IRootPanel root, PlayerPosition existingPosition) {
|
||||
|
||||
PlayerRawPosition rawPosition = existingPosition == null ? locator.locate() : existingPosition;
|
||||
|
||||
WWidget xLabel = CreateLabelForCoorindate("X");
|
||||
WWidget yLabel = CreateLabelForCoorindate("Y");
|
||||
WWidget zLabel = CreateLabelForCoorindate("Z");
|
||||
|
||||
WWidget xText = CreateWidgetForCoordinate(rawPosition.getX());
|
||||
WWidget yText = CreateWidgetForCoordinate(rawPosition.getY());
|
||||
WWidget zText = CreateWidgetForCoordinate(rawPosition.getZ());
|
||||
|
||||
root.add(xLabel, 2, 1, 2, 1);
|
||||
root.add(yLabel, 2, 2, 2, 1);
|
||||
root.add(zLabel, 2, 3, 2, 1);
|
||||
|
||||
root.add(xText, 3, 1, 2, 1);
|
||||
root.add(yText, 3, 2, 2, 1);
|
||||
root.add(zText, 3, 3, 2, 1);
|
||||
|
||||
WWidget icon = ResourceUtils.CreateWorldIcon(rawPosition.getWorldDimension());
|
||||
root.add(icon, 8, 1, 2, 2);
|
||||
|
||||
String defaultWorldName = getDefaultWorldName(existingPosition);
|
||||
WTextField world = CreateWorldField(defaultWorldName);
|
||||
root.add(world, 0, 4, 4, 1);
|
||||
|
||||
WTextField location = CreateLocationField(existingPosition);
|
||||
root.add(location, 5, 4, 7, 1);
|
||||
|
||||
WTextField notes = CreateNotesField(existingPosition);
|
||||
root.add(notes, 0, 6, 12, 1);
|
||||
|
||||
root.add(saveButton, 13, 6, 2, 1);
|
||||
root.add(listButton, 13, 9, 2, 1);
|
||||
root.add(pingButton, 13, 1, 1, 1);
|
||||
root.add(closeButton, 0, 9, 2, 1);
|
||||
root.add(configButton, 10, 9, 2, 1);
|
||||
|
||||
return createPlayerPositionSupplier(existingPosition, rawPosition, world, location, notes);
|
||||
}
|
||||
|
||||
public void onSave(Runnable runnable) {
|
||||
this.saveButton.setOnClick(runnable);
|
||||
}
|
||||
|
||||
public void onClose(Runnable runnable) {
|
||||
this.closeButton.setOnClick(runnable);
|
||||
}
|
||||
|
||||
public void onList(Runnable runnable) {
|
||||
this.listButton.setOnClick(runnable);
|
||||
}
|
||||
|
||||
public void onPing(Runnable runnable) {
|
||||
this.pingButton.setOnClick(runnable);
|
||||
}
|
||||
|
||||
public void onConfig(Runnable runnable) {
|
||||
this.configButton.setOnClick(runnable);
|
||||
}
|
||||
|
||||
private Supplier<PlayerPosition> createPlayerPositionSupplier(PlayerPosition existingPosition,
|
||||
PlayerRawPosition rawPosition, WTextField world, WTextField location, WTextField notes) {
|
||||
|
||||
return () -> {
|
||||
String id = CreateId(existingPosition);
|
||||
PositionMetadata metadata = CreateMetadata(existingPosition, world, notes);
|
||||
|
||||
return new PlayerPosition(id, rawPosition, location.getText(), metadata);
|
||||
};
|
||||
}
|
||||
|
||||
private String CreateId(PlayerPosition existingPosition) {
|
||||
return existingPosition == null ? UUID.randomUUID().toString() : existingPosition.getId();
|
||||
}
|
||||
|
||||
private PositionMetadata CreateMetadata(PlayerPosition existingPosition, WTextField world, WTextField notes) {
|
||||
if (existingPosition == null) {
|
||||
return new PositionMetadata(world.getText(), notes.getText());
|
||||
}
|
||||
|
||||
existingPosition.getPositionMetadata().setWorldName(world.getText());
|
||||
existingPosition.getPositionMetadata().setNotes(notes.getText());
|
||||
existingPosition.getPositionMetadata().updateLastModified();
|
||||
|
||||
return existingPosition.getPositionMetadata();
|
||||
}
|
||||
|
||||
private String getDefaultWorldName(PlayerPosition existingPosition) {
|
||||
if (existingPosition != null && existingPosition.getPositionMetadata().getWorldName() != null) {
|
||||
return existingPosition.getPositionMetadata().getWorldName();
|
||||
}
|
||||
|
||||
try {
|
||||
return fileStore.getDefaultWorld();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
private WWidget CreateLabelForCoorindate(String label) {
|
||||
return new WLabel(label, 0xb80000);
|
||||
}
|
||||
|
||||
private WWidget CreateWidgetForCoordinate(long l) {
|
||||
return new WText(new LiteralText(String.valueOf(l)), 0x3939ac);
|
||||
}
|
||||
|
||||
private WTextField CreateLocationField(PlayerPosition existingPosition) {
|
||||
WTextField location = new WTextField(new LiteralText("location name"));
|
||||
|
||||
if (existingPosition != null) {
|
||||
location.setText(existingPosition.getLocationName());
|
||||
}
|
||||
|
||||
location.setMaxLength(20);
|
||||
|
||||
return location;
|
||||
}
|
||||
|
||||
private WTextField CreateNotesField(PlayerPosition existingPosition) {
|
||||
WTextField notes = new WTextField(new LiteralText("additional notes"));
|
||||
|
||||
if (existingPosition != null && existingPosition.getPositionMetadata() != null) {
|
||||
notes.setText(existingPosition.getPositionMetadata().getNotes());
|
||||
}
|
||||
|
||||
return notes;
|
||||
}
|
||||
|
||||
private WTextField CreateWorldField(String defaultWorld) {
|
||||
WTextField world = new WTextField(new LiteralText("world name"));
|
||||
world.setMaxLength(7);
|
||||
world.setText(defaultWorld);
|
||||
return world;
|
||||
}
|
||||
|
||||
private WButton CreatePingButton() {
|
||||
WButton button = CreateButton("");
|
||||
button.setIcon(ResourceUtils.CreatePingIcon());
|
||||
return button;
|
||||
}
|
||||
|
||||
private WButton CreateButton(String name) {
|
||||
WButton button = new WButton(new LiteralText(name));
|
||||
|
||||
return button;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
package me.bionicbeanie.mods.savecoords.gui.impl;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import me.bionicbeanie.mods.savecoords.IFileStore;
|
||||
|
||||
class DeleteOperation extends ViewOperationBase<String> {
|
||||
|
||||
public DeleteOperation(IFileStore fileStore, Supplier<String> stateSupplier) {
|
||||
super(fileStore, stateSupplier);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executeOperation(IFileStore fileStore, String positionId) throws Exception {
|
||||
fileStore.delete(positionId);
|
||||
}
|
||||
}
|
||||
@ -1,14 +1,14 @@
|
||||
package me.bionicbeanie.mods.gui;
|
||||
package me.bionicbeanie.mods.savecoords.gui.impl;
|
||||
|
||||
import me.bionicbeanie.mods.api.IScreenController;
|
||||
import me.bionicbeanie.mods.savecoords.gui.IGuiController;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
|
||||
public class ScreenController implements IScreenController {
|
||||
class GuiController implements IGuiController {
|
||||
|
||||
private MinecraftClient client;
|
||||
|
||||
public ScreenController(MinecraftClient client) {
|
||||
public GuiController(MinecraftClient client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
@ -1,61 +1,80 @@
|
||||
package me.bionicbeanie.mods.gui.view;
|
||||
package me.bionicbeanie.mods.savecoords.gui.impl;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import io.github.cottonmc.cotton.gui.widget.WButton;
|
||||
import io.github.cottonmc.cotton.gui.widget.WLabel;
|
||||
import io.github.cottonmc.cotton.gui.widget.WListPanel;
|
||||
import io.github.cottonmc.cotton.gui.widget.WPlainPanel;
|
||||
import io.github.cottonmc.cotton.gui.widget.WSprite;
|
||||
import me.bionicbeanie.mods.api.IFileStore;
|
||||
import me.bionicbeanie.mods.api.IGui;
|
||||
import me.bionicbeanie.mods.api.IRootGridPanel;
|
||||
import me.bionicbeanie.mods.model.PlayerPosition;
|
||||
import me.bionicbeanie.mods.util.DimensionSpriteUtil;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import me.bionicbeanie.mods.savecoords.IFileStore;
|
||||
import me.bionicbeanie.mods.savecoords.gui.IRootPanel;
|
||||
import me.bionicbeanie.mods.savecoords.model.PlayerPosition;
|
||||
import me.bionicbeanie.mods.savecoords.model.PlayerRawPosition;
|
||||
import me.bionicbeanie.mods.savecoords.util.ResourceUtils;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class ListViewHandler extends ViewHandlerBase<Void> {
|
||||
class ListViewHandler extends ViewHandlerBase<Void> {
|
||||
|
||||
public ListViewHandler(IFileStore fileStore, IGui gui, MinecraftClient client) {
|
||||
super(fileStore, gui, client);
|
||||
private IFileStore fileStore;
|
||||
private WButton backButton;
|
||||
private Consumer<PlayerPosition> onDelete;
|
||||
private Consumer<PlayerPosition> onEdit;
|
||||
private Consumer<PlayerRawPosition> onPing;
|
||||
|
||||
public ListViewHandler(IFileStore fileStore, Consumer<PlayerPosition> onDelete, Consumer<PlayerPosition> onEdit,
|
||||
Consumer<PlayerRawPosition> onPing) {
|
||||
this.fileStore = fileStore;
|
||||
this.backButton = createBackButton();
|
||||
this.onDelete = onDelete;
|
||||
this.onEdit = onEdit;
|
||||
this.onPing = onPing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void placeWidgets(IRootGridPanel root, Void nullState) {
|
||||
public Supplier<Void> placeWidgets(IRootPanel root, Void nullState) {
|
||||
|
||||
List<PlayerPosition> positions = getPositions(fileStore);
|
||||
WListPanel<PlayerPosition, CoordinatesListItemPanel> listPanel = createListPane(positions);
|
||||
|
||||
WButton backButton = createBackButton();
|
||||
|
||||
root.add(listPanel, 0, 0, 15, 9);
|
||||
root.add(backButton, 0, 9, 2, 1);
|
||||
|
||||
return () -> (Void) null;
|
||||
}
|
||||
|
||||
public void onBack(Runnable runnable) {
|
||||
this.backButton.setOnClick(runnable);
|
||||
}
|
||||
|
||||
private WButton createBackButton() {
|
||||
WButton backButton = new WButton(new LiteralText("BACK"));
|
||||
backButton.setOnClick(gui::showDefaultView);
|
||||
return backButton;
|
||||
return new WButton(new LiteralText("BACK"));
|
||||
}
|
||||
|
||||
private WListPanel<PlayerPosition, CoordinatesListItemPanel> createListPane(List<PlayerPosition> positions) {
|
||||
BiConsumer<PlayerPosition, CoordinatesListItemPanel> configurator = (position, panel) -> {
|
||||
panel.setPosition(position, fileStore, gui);
|
||||
};
|
||||
|
||||
WListPanel<PlayerPosition, CoordinatesListItemPanel> panel = new WListPanel<>(positions,
|
||||
CoordinatesListItemPanel::new, configurator);
|
||||
BiConsumer<PlayerPosition, CoordinatesListItemPanel> configurator = (pos, p) -> p.setPosition(pos, fileStore);
|
||||
WListPanel<PlayerPosition, CoordinatesListItemPanel> panel = CreateListPanel(positions, configurator);
|
||||
|
||||
panel.setListItemHeight(2 * 18);
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
private WListPanel<PlayerPosition, CoordinatesListItemPanel> CreateListPanel(List<PlayerPosition> positions,
|
||||
BiConsumer<PlayerPosition, CoordinatesListItemPanel> config) {
|
||||
return new WListPanel<>(positions, this::createListPanel, config);
|
||||
}
|
||||
|
||||
private CoordinatesListItemPanel createListPanel() {
|
||||
return new CoordinatesListItemPanel(onDelete, onEdit, onPing);
|
||||
}
|
||||
|
||||
private List<PlayerPosition> getPositions(IFileStore fileStore) {
|
||||
try {
|
||||
List<PlayerPosition> positions = fileStore.list();
|
||||
@ -68,7 +87,7 @@ public class ListViewHandler extends ViewHandlerBase<Void> {
|
||||
}
|
||||
}
|
||||
|
||||
public static class CoordinatesListItemPanel extends WPlainPanel {
|
||||
private static class CoordinatesListItemPanel extends WPlainPanel {
|
||||
|
||||
private WLabel coordinates;
|
||||
private WLabel location;
|
||||
@ -77,22 +96,35 @@ public class ListViewHandler extends ViewHandlerBase<Void> {
|
||||
private WButton pingButton;
|
||||
private WButton detailButton;
|
||||
private WLabel world;
|
||||
private Consumer<PlayerRawPosition> onPing;
|
||||
private Consumer<PlayerPosition> onEdit;
|
||||
private Consumer<PlayerPosition> onDelete;
|
||||
|
||||
CoordinatesListItemPanel(Consumer<PlayerPosition> onDelete, Consumer<PlayerPosition> onEdit,
|
||||
Consumer<PlayerRawPosition> onPing) {
|
||||
|
||||
this.onDelete = onDelete;
|
||||
this.onEdit = onEdit;
|
||||
this.onPing = onPing;
|
||||
|
||||
public CoordinatesListItemPanel() {
|
||||
this.coordinates = new WLabel("Foo");
|
||||
this.location = new WLabel("Foo");
|
||||
this.world = new WLabel("Foo");
|
||||
this.icon = new WSprite(new Identifier("minecraft:textures/item/ender_eye.png"));
|
||||
this.deleteButton = new WButton(new LiteralText("x"));
|
||||
this.pingButton = new WButton(new LiteralText("!"));
|
||||
this.detailButton = new WButton(new LiteralText("+"));
|
||||
this.pingButton = new WButton(new LiteralText(""));
|
||||
this.detailButton = new WButton(new LiteralText(""));
|
||||
|
||||
this.deleteButton.setIcon(ResourceUtils.CreateCloseIcon());
|
||||
this.pingButton.setIcon(ResourceUtils.CreatePingIcon());
|
||||
this.detailButton.setIcon(ResourceUtils.CreateDetailsIcon());
|
||||
|
||||
this.add(icon, 0, 0, 1 * 9, 1 * 9);
|
||||
this.add(world, 1 * 18, 0, 3 * 18, 1 * 18);
|
||||
this.add(location, 4 * 18, 0, 4 * 18, 1 * 18);
|
||||
this.add(coordinates, 1 * 18, 1 * 18, 9 * 18, 1 * 18);
|
||||
this.add(coordinates, 3 * 18, 1 * 18, 9 * 18, 1 * 18);
|
||||
this.add(deleteButton, 13 * 18, 0, 1 * 18, 1 * 18);
|
||||
this.add(pingButton, 12 * 18, 0, 1 * 18, 1 * 18);
|
||||
this.add(pingButton, 1 * 18, 1 * 18, 1 * 18, 1 * 18);
|
||||
this.add(detailButton, 11 * 18, 0, 1 * 18, 1 * 18);
|
||||
|
||||
this.icon.setSize(1 * 15, 1 * 15);
|
||||
@ -106,17 +138,17 @@ public class ListViewHandler extends ViewHandlerBase<Void> {
|
||||
this.setSize(15 * 18, 2 * 18);
|
||||
}
|
||||
|
||||
public void setPosition(PlayerPosition position, IFileStore fileStore, IGui gui) {
|
||||
this.icon.setImage(DimensionSpriteUtil.CreateWorldIconIdentifier(position.getWorldDimension()));
|
||||
void setPosition(PlayerPosition position, IFileStore fileStore) {
|
||||
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);
|
||||
this.coordinates
|
||||
.setText(new LiteralText(position.getX() + ", " + position.getY() + ", " + position.getZ()));
|
||||
this.deleteButton.setOnClick(new DeleteOperation(fileStore, gui, position));
|
||||
this.pingButton.setOnClick(new PingOperation(fileStore, gui, position));
|
||||
this.detailButton.setOnClick(new ShowDetailOperation(fileStore, gui, position));
|
||||
this.deleteButton.setOnClick(() -> onDelete.accept(position));
|
||||
this.pingButton.setOnClick(() -> onPing.accept(position));
|
||||
this.detailButton.setOnClick(() -> onEdit.accept(position));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
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.impl.Factory;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
|
||||
public class ModGui {
|
||||
|
||||
public static void start(MinecraftClient client) {
|
||||
IGuiController controller = new GuiController(client);
|
||||
IPlayerLocator locator = Factory.CreatePlayerLocator(client);
|
||||
IFileStore fileStore = Factory.createFileStore(client.runDirectory.getAbsolutePath());
|
||||
|
||||
new SaveCoordinatesGui(fileStore, locator, controller);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
package me.bionicbeanie.mods.savecoords.gui.impl;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import me.bionicbeanie.mods.savecoords.IFileStore;
|
||||
import me.bionicbeanie.mods.savecoords.model.PlayerRawPosition;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
|
||||
class PingOperation extends ViewOperationBase<PlayerRawPosition>{
|
||||
|
||||
public PingOperation(IFileStore fileStore, Supplier<PlayerRawPosition> stateSupplier) {
|
||||
super(fileStore, stateSupplier);
|
||||
}
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
@Override
|
||||
protected void executeOperation(IFileStore fileStore, PlayerRawPosition position) throws Exception {
|
||||
MinecraftClient.getInstance().player.sendChatMessage(position.toString());
|
||||
}
|
||||
}
|
||||
@ -1,18 +1,22 @@
|
||||
package me.bionicbeanie.mods.gui;
|
||||
package me.bionicbeanie.mods.savecoords.gui.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.github.cottonmc.cotton.gui.GuiDescription;
|
||||
import io.github.cottonmc.cotton.gui.widget.WGridPanel;
|
||||
import io.github.cottonmc.cotton.gui.widget.WWidget;
|
||||
import me.bionicbeanie.mods.api.IRootGridPanel;
|
||||
import me.bionicbeanie.mods.savecoords.gui.IRootPanel;
|
||||
|
||||
public class RootGridPanel extends WGridPanel implements IRootGridPanel{
|
||||
class RootGridPanel extends WGridPanel implements IRootPanel{
|
||||
|
||||
private List<WWidget> children;
|
||||
private GuiDescription guiDescription;
|
||||
|
||||
public RootGridPanel() {
|
||||
public RootGridPanel(GuiDescription guiDescription) {
|
||||
this(18);
|
||||
|
||||
this.guiDescription = guiDescription;
|
||||
}
|
||||
|
||||
public RootGridPanel(int gridSize){
|
||||
@ -32,4 +36,8 @@ public class RootGridPanel extends WGridPanel implements IRootGridPanel{
|
||||
children.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() {
|
||||
validate(guiDescription);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,94 @@
|
||||
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.IViewHandler;
|
||||
import me.bionicbeanie.mods.savecoords.model.PlayerPosition;
|
||||
import me.bionicbeanie.mods.savecoords.model.PlayerRawPosition;
|
||||
|
||||
public class SaveCoordinatesGui {
|
||||
|
||||
private IGuiController screenController;
|
||||
private IFileStore fileStore;
|
||||
private IViewHandler<PlayerPosition> defaultHandler;
|
||||
private IViewHandler<Void> listHandler;
|
||||
private IPlayerLocator locator;
|
||||
|
||||
SaveCoordinatesGui(IFileStore fileStore, IPlayerLocator locator, IGuiController screenController) {
|
||||
this.screenController = screenController;
|
||||
this.fileStore = fileStore;
|
||||
this.locator = locator;
|
||||
|
||||
this.defaultHandler = CreateDefaultViewHandler();
|
||||
this.listHandler = CreateListViewHandler();
|
||||
|
||||
showDefaultView(null);
|
||||
}
|
||||
|
||||
private IViewHandler<PlayerPosition> CreateDefaultViewHandler() {
|
||||
DefaultViewHandler handler = new DefaultViewHandler(fileStore, locator);
|
||||
|
||||
handler.onClose(screenController::closeScreen);
|
||||
handler.onSave(this::onSavePosition);
|
||||
handler.onList(this::showListView);
|
||||
handler.onPing(new PingOperation(fileStore, locator::locate));
|
||||
|
||||
return handler;
|
||||
}
|
||||
|
||||
private IViewHandler<Void> CreateListViewHandler() {
|
||||
ListViewHandler handler = new ListViewHandler(fileStore, this::onDeletePosition, this::onEditPosition,
|
||||
this::onPingPosition);
|
||||
|
||||
handler.onBack(() -> showDefaultView(null));
|
||||
|
||||
return handler;
|
||||
}
|
||||
|
||||
private void onSavePosition() {
|
||||
new SaveOperation(fileStore, defaultHandler::getState).run();
|
||||
showListView();
|
||||
}
|
||||
|
||||
private void onDeletePosition(PlayerPosition position) {
|
||||
new DeleteOperation(fileStore, () -> position.getId()).run();
|
||||
showListView();
|
||||
}
|
||||
|
||||
private void onEditPosition(PlayerPosition position) {
|
||||
showDefaultView(position);
|
||||
}
|
||||
|
||||
private void onPingPosition(PlayerRawPosition position) {
|
||||
new PingOperation(fileStore, () -> position).run();
|
||||
}
|
||||
|
||||
private void showDefaultView(PlayerPosition position) {
|
||||
screenController.openScreen(this.defaultHandler.createView(position));
|
||||
}
|
||||
|
||||
private void showListView() {
|
||||
screenController.openScreen(this.listHandler.createView(null));
|
||||
}
|
||||
|
||||
// public void showConfigView() {
|
||||
//
|
||||
// ConfigBuilder builder = ConfigBuilder.create()
|
||||
// .setParentScreen(this.screen)
|
||||
// .setTitle(new LiteralText("Save Coordinates config"));
|
||||
//
|
||||
// ConfigCategory general = builder.getOrCreateCategory(new LiteralText("Generic"));
|
||||
// ConfigEntryBuilder entryBuilder = builder.entryBuilder();
|
||||
//
|
||||
// general.addEntry(entryBuilder.startKeyCodeField(new LiteralText("Default Keybind"),
|
||||
// InputUtil.Type.KEYSYM.createFromCode(GLFW.GLFW_KEY_H))
|
||||
// .setDefaultValue(InputUtil.Type.KEYSYM.createFromCode(GLFW.GLFW_KEY_H))
|
||||
// .setTooltip(new LiteralText("Keybind to open Save Coordinates menu"))
|
||||
// .setSaveConsumer(newValue -> newValue = newValue)
|
||||
// .build());
|
||||
//
|
||||
// screenController.openScreen(builder.build());
|
||||
// }
|
||||
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
package me.bionicbeanie.mods.savecoords.gui.impl;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import me.bionicbeanie.mods.savecoords.IFileStore;
|
||||
import me.bionicbeanie.mods.savecoords.model.PlayerPosition;
|
||||
|
||||
class SaveOperation extends ViewOperationBase<PlayerPosition> {
|
||||
|
||||
public SaveOperation(IFileStore fileStore, Supplier<PlayerPosition> stateSupplier) {
|
||||
super(fileStore, stateSupplier);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executeOperation(IFileStore fileStore, PlayerPosition position) throws Exception {
|
||||
fileStore.save(position);
|
||||
fileStore.setDefaultWorld(position.getPositionMetadata().getWorldName());
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
package me.bionicbeanie.mods.savecoords.gui.impl;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import io.github.cottonmc.cotton.gui.client.LightweightGuiDescription;
|
||||
import me.bionicbeanie.mods.savecoords.gui.IRootPanel;
|
||||
import me.bionicbeanie.mods.savecoords.gui.IViewHandler;
|
||||
import me.bionicbeanie.mods.savecoords.gui.SaveCoordinatesScreen;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
|
||||
abstract class ViewHandlerBase<T> extends LightweightGuiDescription implements IViewHandler<T> {
|
||||
|
||||
private IRootPanel rootGridPanel;
|
||||
private Supplier<T> stateSupplier;
|
||||
|
||||
protected ViewHandlerBase() {
|
||||
this.rootGridPanel = createRootPanel();
|
||||
}
|
||||
|
||||
protected abstract Supplier<T> placeWidgets(IRootPanel rootGridPanel, T state);
|
||||
|
||||
@Override
|
||||
public Screen createView(T state) {
|
||||
rootGridPanel.reset();
|
||||
this.stateSupplier = placeWidgets(rootGridPanel, state);
|
||||
rootGridPanel.validate();
|
||||
return new SaveCoordinatesScreen(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getState() {
|
||||
return stateSupplier.get();
|
||||
}
|
||||
|
||||
private IRootPanel createRootPanel() {
|
||||
RootGridPanel panel = new RootGridPanel(this);
|
||||
panel.setSize(15 * 18, 10 * 18);
|
||||
|
||||
setRootPanel(panel);
|
||||
return panel;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
package me.bionicbeanie.mods.savecoords.gui.impl;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import me.bionicbeanie.mods.savecoords.IFileStore;
|
||||
|
||||
abstract class ViewOperationBase<T> implements Runnable {
|
||||
|
||||
private IFileStore fileStore;
|
||||
private Supplier<T> stateSupplier;
|
||||
|
||||
public ViewOperationBase(IFileStore fileStore,Supplier<T> stateSupplier) {
|
||||
this.fileStore = fileStore;
|
||||
this.stateSupplier = stateSupplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
executeOperation(fileStore, stateSupplier.get());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void executeOperation(IFileStore fileStore, T state) throws Exception;
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package me.bionicbeanie.mods.savecoords.impl;
|
||||
|
||||
import me.bionicbeanie.mods.savecoords.IFileStore;
|
||||
import me.bionicbeanie.mods.savecoords.IPlayerLocator;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
|
||||
public class Factory {
|
||||
|
||||
public static IFileStore createFileStore(String baseDirectory) {
|
||||
return new FileStore(baseDirectory);
|
||||
}
|
||||
|
||||
public static IPlayerLocator CreatePlayerLocator(MinecraftClient client) {
|
||||
return new PlayerLocator(client);
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package me.bionicbeanie.mods.impl;
|
||||
package me.bionicbeanie.mods.savecoords.impl;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.FileAlreadyExistsException;
|
||||
@ -14,11 +14,11 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
import me.bionicbeanie.mods.api.IFileStore;
|
||||
import me.bionicbeanie.mods.model.ModData;
|
||||
import me.bionicbeanie.mods.model.PlayerPosition;
|
||||
import me.bionicbeanie.mods.savecoords.IFileStore;
|
||||
import me.bionicbeanie.mods.savecoords.model.ModData;
|
||||
import me.bionicbeanie.mods.savecoords.model.PlayerPosition;
|
||||
|
||||
public class FileStore implements IFileStore {
|
||||
class FileStore implements IFileStore {
|
||||
|
||||
private static String DEFAULT_DIR = "saveCoordinates";
|
||||
private static String DEFAULT_FILE = "coordiates.json";
|
||||
@ -1,13 +1,19 @@
|
||||
package me.bionicbeanie.mods.impl;
|
||||
package me.bionicbeanie.mods.savecoords.impl;
|
||||
|
||||
import me.bionicbeanie.mods.api.IPlayerLocator;
|
||||
import me.bionicbeanie.mods.model.PlayerRawPosition;
|
||||
import me.bionicbeanie.mods.savecoords.IPlayerLocator;
|
||||
import me.bionicbeanie.mods.savecoords.model.PlayerRawPosition;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
public class PlayerLocator implements IPlayerLocator {
|
||||
class PlayerLocator implements IPlayerLocator {
|
||||
|
||||
public PlayerRawPosition locate(MinecraftClient client) {
|
||||
private MinecraftClient client;
|
||||
|
||||
public PlayerLocator(MinecraftClient client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
public PlayerRawPosition locate() {
|
||||
Vec3d pos = client.player.getPos();
|
||||
long x = Math.round(pos.x);
|
||||
long y = Math.round(pos.y);
|
||||
@ -1,4 +1,4 @@
|
||||
package me.bionicbeanie.mods.model;
|
||||
package me.bionicbeanie.mods.savecoords.model;
|
||||
|
||||
public class ModData {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package me.bionicbeanie.mods.model;
|
||||
package me.bionicbeanie.mods.savecoords.model;
|
||||
|
||||
public class PlayerPosition extends PlayerRawPosition {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package me.bionicbeanie.mods.model;
|
||||
package me.bionicbeanie.mods.savecoords.model;
|
||||
|
||||
public class PlayerRawPosition {
|
||||
private long x, y, z;
|
||||
@ -1,4 +1,4 @@
|
||||
package me.bionicbeanie.mods.model;
|
||||
package me.bionicbeanie.mods.savecoords.model;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@ -0,0 +1,45 @@
|
||||
package me.bionicbeanie.mods.savecoords.util;
|
||||
|
||||
import io.github.cottonmc.cotton.gui.widget.WSprite;
|
||||
import io.github.cottonmc.cotton.gui.widget.WWidget;
|
||||
import io.github.cottonmc.cotton.gui.widget.icon.Icon;
|
||||
import io.github.cottonmc.cotton.gui.widget.icon.TextureIcon;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class ResourceUtils {
|
||||
|
||||
public static WWidget CreateWorldIcon(String dimension) {
|
||||
return new WSprite(CreateWorldIconIdentifier(dimension));
|
||||
}
|
||||
|
||||
public static Identifier CreateWorldIconIdentifier(String dimension) {
|
||||
|
||||
if (dimension == null)
|
||||
return CreateIdentifier("nonExistent");
|
||||
if (dimension.contains("overworld"))
|
||||
return CreateIdentifier("overworld");
|
||||
if (dimension.contains("nether"))
|
||||
return CreateIdentifier("nether");
|
||||
if (dimension.contains("end"))
|
||||
return CreateIdentifier("end");
|
||||
|
||||
return CreateIdentifier("nonExistent");
|
||||
|
||||
}
|
||||
|
||||
public static Icon CreatePingIcon() {
|
||||
return new TextureIcon(CreateIdentifier("ping"));
|
||||
}
|
||||
|
||||
public static Icon CreateCloseIcon() {
|
||||
return new TextureIcon(CreateIdentifier("close"));
|
||||
}
|
||||
|
||||
public static Icon CreateDetailsIcon() {
|
||||
return new TextureIcon(CreateIdentifier("more"));
|
||||
}
|
||||
|
||||
private static Identifier CreateIdentifier(String file) {
|
||||
return new Identifier("savecoords", "textures/gui/" + file + ".png");
|
||||
}
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
package me.bionicbeanie.mods.util;
|
||||
|
||||
import io.github.cottonmc.cotton.gui.widget.WSprite;
|
||||
import io.github.cottonmc.cotton.gui.widget.WWidget;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class DimensionSpriteUtil {
|
||||
|
||||
public static WWidget CreateWorldIcon(String dimension) {
|
||||
return new WSprite(CreateWorldIconIdentifier(dimension));
|
||||
}
|
||||
|
||||
public static Identifier CreateWorldIconIdentifier(String dimension) {
|
||||
String dimensionItem = "netherite_ingot";
|
||||
|
||||
if(dimension == null) {
|
||||
dimensionItem = "barrier";
|
||||
}
|
||||
else if (dimension.contains("overworld")) {
|
||||
dimensionItem = "totem_of_undying";
|
||||
} else if (dimension.contains("end")) {
|
||||
dimensionItem = "ender_eye";
|
||||
}
|
||||
|
||||
return new Identifier("minecraft:textures/item/" + dimensionItem + ".png");
|
||||
}
|
||||
}
|
||||
BIN
src/main/resources/assets/savecoords/textures/gui/close.png
Normal file
|
After Width: | Height: | Size: 183 B |
BIN
src/main/resources/assets/savecoords/textures/gui/end.png
Normal file
|
After Width: | Height: | Size: 5.8 KiB |
BIN
src/main/resources/assets/savecoords/textures/gui/more.png
Normal file
|
After Width: | Height: | Size: 195 B |
BIN
src/main/resources/assets/savecoords/textures/gui/nether.png
Normal file
|
After Width: | Height: | Size: 6.4 KiB |
BIN
src/main/resources/assets/savecoords/textures/gui/overworld.png
Normal file
|
After Width: | Height: | Size: 4.7 KiB |
BIN
src/main/resources/assets/savecoords/textures/gui/ping.png
Normal file
|
After Width: | Height: | Size: 221 B |
BIN
src/main/resources/data/savecoords/end.png
Normal file
|
After Width: | Height: | Size: 28 KiB |