Add nether coordinate calculator
This commit is contained in:
parent
523035a463
commit
4d022fcb03
@ -12,8 +12,16 @@ public interface IDimensionAware {
|
|||||||
|
|
||||||
IDimension getDimension(String dimensionKey);
|
IDimension getDimension(String dimensionKey);
|
||||||
|
|
||||||
|
boolean isOverworld(IDimension dimension);
|
||||||
|
|
||||||
|
boolean isNether(IDimension dimension);
|
||||||
|
|
||||||
|
boolean isEnd(IDimension dimension);
|
||||||
|
|
||||||
public interface IDimension {
|
public interface IDimension {
|
||||||
|
|
||||||
|
public int getId();
|
||||||
|
|
||||||
public String getName();
|
public String getName();
|
||||||
|
|
||||||
public Identifier getSpriteIdentifier();
|
public Identifier getSpriteIdentifier();
|
||||||
|
|||||||
@ -0,0 +1,7 @@
|
|||||||
|
package me.bionicbeanie.mods.savecoords;
|
||||||
|
|
||||||
|
import me.bionicbeanie.mods.savecoords.model.PlayerRawPosition;
|
||||||
|
|
||||||
|
public interface INetherCalculator {
|
||||||
|
PlayerRawPosition convert(PlayerRawPosition position);
|
||||||
|
}
|
||||||
@ -5,6 +5,8 @@ import me.bionicbeanie.mods.savecoords.gui.impl.DIContainer;
|
|||||||
import net.fabricmc.api.ClientModInitializer;
|
import net.fabricmc.api.ClientModInitializer;
|
||||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.client.font.Font;
|
||||||
|
import net.minecraft.client.font.TextRenderer;
|
||||||
import net.minecraft.text.TranslatableText;
|
import net.minecraft.text.TranslatableText;
|
||||||
|
|
||||||
public class SaveCoordinatesClient implements ClientModInitializer {
|
public class SaveCoordinatesClient implements ClientModInitializer {
|
||||||
@ -24,6 +26,7 @@ public class SaveCoordinatesClient implements ClientModInitializer {
|
|||||||
|
|
||||||
while(pingLockBinding.wasPressed()) {
|
while(pingLockBinding.wasPressed()) {
|
||||||
boolean enabled = DIContainer.togglePingBehavior();
|
boolean enabled = DIContainer.togglePingBehavior();
|
||||||
|
// TODO : Abstract to a tooltip queue
|
||||||
String translationKey = TranslationKeys.TOOLTIP_PING_DISABLED;
|
String translationKey = TranslationKeys.TOOLTIP_PING_DISABLED;
|
||||||
if(enabled) {
|
if(enabled) {
|
||||||
translationKey = TranslationKeys.TOOLTIP_PING_ENABLED;
|
translationKey = TranslationKeys.TOOLTIP_PING_ENABLED;
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import me.bionicbeanie.mods.savecoords.IDimensionAware;
|
|||||||
import me.bionicbeanie.mods.savecoords.IFileStore;
|
import me.bionicbeanie.mods.savecoords.IFileStore;
|
||||||
import me.bionicbeanie.mods.savecoords.IKeyBinds;
|
import me.bionicbeanie.mods.savecoords.IKeyBinds;
|
||||||
import me.bionicbeanie.mods.savecoords.IModGui;
|
import me.bionicbeanie.mods.savecoords.IModGui;
|
||||||
|
import me.bionicbeanie.mods.savecoords.INetherCalculator;
|
||||||
import me.bionicbeanie.mods.savecoords.IPlayerLocator;
|
import me.bionicbeanie.mods.savecoords.IPlayerLocator;
|
||||||
import me.bionicbeanie.mods.savecoords.impl.Factory;
|
import me.bionicbeanie.mods.savecoords.impl.Factory;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
@ -23,6 +24,7 @@ public class DIContainer {
|
|||||||
private static ConfigScreenFactory<Screen> modMenuScreenFactory;
|
private static ConfigScreenFactory<Screen> modMenuScreenFactory;
|
||||||
private static CurrentPositionPingOperation pingPositionOperation;
|
private static CurrentPositionPingOperation pingPositionOperation;
|
||||||
private static IDimensionAware dimensionAware;
|
private static IDimensionAware dimensionAware;
|
||||||
|
private static INetherCalculator netherCalculator;
|
||||||
|
|
||||||
public static IModGui getModGui() {
|
public static IModGui getModGui() {
|
||||||
initialize();
|
initialize();
|
||||||
@ -59,7 +61,7 @@ public class DIContainer {
|
|||||||
return () -> {
|
return () -> {
|
||||||
try {
|
try {
|
||||||
pingPositionOperation.call();
|
pingPositionOperation.call();
|
||||||
}catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -79,7 +81,9 @@ public class DIContainer {
|
|||||||
playerLocator = Factory.CreatePlayerLocator(minecraftClient);
|
playerLocator = Factory.CreatePlayerLocator(minecraftClient);
|
||||||
keyBinds = Factory.CreateKeyBinds(fileStore);
|
keyBinds = Factory.CreateKeyBinds(fileStore);
|
||||||
dimensionAware = Factory.CreateDimensionAware(minecraftClient);
|
dimensionAware = Factory.CreateDimensionAware(minecraftClient);
|
||||||
modGui = new SaveCoordinatesGui(fileStore, playerLocator, dimensionAware, keyBinds, guiController);
|
netherCalculator = Factory.CreateNetherCalculator(dimensionAware);
|
||||||
|
modGui = new SaveCoordinatesGui(fileStore, playerLocator, dimensionAware, keyBinds, guiController,
|
||||||
|
netherCalculator);
|
||||||
|
|
||||||
pingPositionOperation = new CurrentPositionPingOperation(fileStore, () -> playerLocator.locate());
|
pingPositionOperation = new CurrentPositionPingOperation(fileStore, () -> playerLocator.locate());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,6 +13,7 @@ import io.github.cottonmc.cotton.gui.widget.WListPanel;
|
|||||||
import io.github.cottonmc.cotton.gui.widget.WPlainPanel;
|
import io.github.cottonmc.cotton.gui.widget.WPlainPanel;
|
||||||
import io.github.cottonmc.cotton.gui.widget.WSprite;
|
import io.github.cottonmc.cotton.gui.widget.WSprite;
|
||||||
import me.bionicbeanie.mods.savecoords.IFileStore;
|
import me.bionicbeanie.mods.savecoords.IFileStore;
|
||||||
|
import me.bionicbeanie.mods.savecoords.INetherCalculator;
|
||||||
import me.bionicbeanie.mods.savecoords.TranslationKeys;
|
import me.bionicbeanie.mods.savecoords.TranslationKeys;
|
||||||
import me.bionicbeanie.mods.savecoords.gui.IRootPanel;
|
import me.bionicbeanie.mods.savecoords.gui.IRootPanel;
|
||||||
import me.bionicbeanie.mods.savecoords.model.PlayerPosition;
|
import me.bionicbeanie.mods.savecoords.model.PlayerPosition;
|
||||||
@ -29,14 +30,16 @@ class ListViewHandler extends ViewHandlerBase<Void> {
|
|||||||
private Consumer<PlayerPosition> onDelete;
|
private Consumer<PlayerPosition> onDelete;
|
||||||
private Consumer<PlayerPosition> onEdit;
|
private Consumer<PlayerPosition> onEdit;
|
||||||
private Consumer<PlayerRawPosition> onPing;
|
private Consumer<PlayerRawPosition> onPing;
|
||||||
|
private INetherCalculator netherCalculator;
|
||||||
|
|
||||||
public ListViewHandler(IFileStore fileStore, Consumer<PlayerPosition> onDelete, Consumer<PlayerPosition> onEdit,
|
public ListViewHandler(IFileStore fileStore, Consumer<PlayerPosition> onDelete, Consumer<PlayerPosition> onEdit,
|
||||||
Consumer<PlayerRawPosition> onPing) {
|
Consumer<PlayerRawPosition> onPing, INetherCalculator netherCalculator) {
|
||||||
this.fileStore = fileStore;
|
this.fileStore = fileStore;
|
||||||
this.backButton = createBackButton();
|
this.backButton = createBackButton();
|
||||||
this.onDelete = onDelete;
|
this.onDelete = onDelete;
|
||||||
this.onEdit = onEdit;
|
this.onEdit = onEdit;
|
||||||
this.onPing = onPing;
|
this.onPing = onPing;
|
||||||
|
this.netherCalculator = netherCalculator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -60,7 +63,7 @@ class ListViewHandler extends ViewHandlerBase<Void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private WListPanel<PlayerPosition, CoordinatesListItemPanel> createListPanel(List<PlayerPosition> positions) {
|
private WListPanel<PlayerPosition, CoordinatesListItemPanel> createListPanel(List<PlayerPosition> positions) {
|
||||||
BiConsumer<PlayerPosition, CoordinatesListItemPanel> configurator = (pos, p) -> p.setPosition(pos, fileStore);
|
BiConsumer<PlayerPosition, CoordinatesListItemPanel> configurator = (pos, p) -> p.setPosition(pos);
|
||||||
WListPanel<PlayerPosition, CoordinatesListItemPanel> panel = createListPanel(positions, configurator);
|
WListPanel<PlayerPosition, CoordinatesListItemPanel> panel = createListPanel(positions, configurator);
|
||||||
|
|
||||||
panel.setListItemHeight(2 * 18);
|
panel.setListItemHeight(2 * 18);
|
||||||
@ -74,7 +77,7 @@ class ListViewHandler extends ViewHandlerBase<Void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private CoordinatesListItemPanel createListPanel() {
|
private CoordinatesListItemPanel createListPanel() {
|
||||||
return new CoordinatesListItemPanel(onDelete, onEdit, onPing);
|
return new CoordinatesListItemPanel(onDelete, onEdit, onPing, netherCalculator);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<PlayerPosition> getPositions(IFileStore fileStore) {
|
private List<PlayerPosition> getPositions(IFileStore fileStore) {
|
||||||
@ -101,27 +104,31 @@ class ListViewHandler extends ViewHandlerBase<Void> {
|
|||||||
private WLabel location;
|
private WLabel location;
|
||||||
private WSprite icon;
|
private WSprite icon;
|
||||||
private WButton deleteButton;
|
private WButton deleteButton;
|
||||||
private WButton pingButton;
|
|
||||||
private WButton detailButton;
|
private WButton detailButton;
|
||||||
|
private WButton pingButton;
|
||||||
|
private WButton convertButton;
|
||||||
private WLabel world;
|
private WLabel world;
|
||||||
private Consumer<PlayerRawPosition> onPing;
|
private Consumer<PlayerRawPosition> onPing;
|
||||||
private Consumer<PlayerPosition> onEdit;
|
private Consumer<PlayerPosition> onEdit;
|
||||||
private Consumer<PlayerPosition> onDelete;
|
private Consumer<PlayerPosition> onDelete;
|
||||||
|
private INetherCalculator netherCalculator;
|
||||||
|
|
||||||
CoordinatesListItemPanel(Consumer<PlayerPosition> onDelete, Consumer<PlayerPosition> onEdit,
|
CoordinatesListItemPanel(Consumer<PlayerPosition> onDelete, Consumer<PlayerPosition> onEdit,
|
||||||
Consumer<PlayerRawPosition> onPing) {
|
Consumer<PlayerRawPosition> onPing, INetherCalculator netherCalculator) {
|
||||||
|
|
||||||
this.onDelete = onDelete;
|
this.onDelete = onDelete;
|
||||||
this.onEdit = onEdit;
|
this.onEdit = onEdit;
|
||||||
this.onPing = onPing;
|
this.onPing = onPing;
|
||||||
|
this.netherCalculator = netherCalculator;
|
||||||
|
|
||||||
this.coordinates = new WLabel("Foo");
|
this.coordinates = new WLabel("Foo");
|
||||||
this.location = new WLabel("Foo");
|
this.location = new WLabel("Foo");
|
||||||
this.world = new WLabel("Foo");
|
this.world = new WLabel("Foo");
|
||||||
this.icon = new WSprite(new Identifier("minecraft:textures/item/ender_eye.png"));
|
this.icon = new WSprite(new Identifier("minecraft:textures/item/ender_eye.png"));
|
||||||
this.deleteButton = createDeleteButton();
|
this.deleteButton = createDeleteButton();
|
||||||
this.pingButton = new WButton(new LiteralText(""));
|
|
||||||
this.detailButton = new WButton(new LiteralText(""));
|
this.detailButton = new WButton(new LiteralText(""));
|
||||||
|
this.pingButton = new WButton(new LiteralText(""));
|
||||||
|
this.convertButton = new WButton(new LiteralText(""));
|
||||||
|
|
||||||
this.pingButton.setIcon(ResourceUtils.createPingIcon());
|
this.pingButton.setIcon(ResourceUtils.createPingIcon());
|
||||||
this.detailButton.setIcon(ResourceUtils.createDetailsIcon());
|
this.detailButton.setIcon(ResourceUtils.createDetailsIcon());
|
||||||
@ -131,8 +138,9 @@ class ListViewHandler extends ViewHandlerBase<Void> {
|
|||||||
this.add(location, 4 * 18, 0, 4 * 18, 1 * 18);
|
this.add(location, 4 * 18, 0, 4 * 18, 1 * 18);
|
||||||
this.add(coordinates, 3 * 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(deleteButton, 13 * 18, 0, 1 * 18, 1 * 18);
|
||||||
this.add(pingButton, 11 * 18 - 2, 0, 1 * 18, 1 * 18);
|
|
||||||
this.add(detailButton, 12 * 18 - 1, 0, 1 * 18, 1 * 18);
|
this.add(detailButton, 12 * 18 - 1, 0, 1 * 18, 1 * 18);
|
||||||
|
this.add(pingButton, 11 * 18 - 2, 0, 1 * 18, 1 * 18);
|
||||||
|
this.add(convertButton, 10 * 18 - 3, 0, 1 * 18, 1 * 18);
|
||||||
|
|
||||||
this.icon.setSize(1 * 15, 1 * 15);
|
this.icon.setSize(1 * 15, 1 * 15);
|
||||||
this.world.setSize(3 * 18, 1 * 18);
|
this.world.setSize(3 * 18, 1 * 18);
|
||||||
@ -152,8 +160,7 @@ class ListViewHandler extends ViewHandlerBase<Void> {
|
|||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPosition(PlayerPosition position, IFileStore fileStore) {
|
void setPosition(PlayerPosition position) {
|
||||||
this.icon.setImage(ResourceUtils.getIdentifier(position.getWorldDimension()));
|
|
||||||
this.location.setText(new LiteralText(position.getLocationName()));
|
this.location.setText(new LiteralText(position.getLocationName()));
|
||||||
this.location.setColor(0x3939ac);
|
this.location.setColor(0x3939ac);
|
||||||
if (position.getPositionMetadata() != null) {
|
if (position.getPositionMetadata() != null) {
|
||||||
@ -161,11 +168,19 @@ class ListViewHandler extends ViewHandlerBase<Void> {
|
|||||||
this.world.setColor(0xb80000);
|
this.world.setColor(0xb80000);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.coordinates
|
setRawPosition(position);
|
||||||
.setText(new LiteralText(position.getX() + ", " + position.getY() + ", " + position.getZ()));
|
|
||||||
this.deleteButton.setOnClick(() -> onDelete.accept(position));
|
this.deleteButton.setOnClick(() -> onDelete.accept(position));
|
||||||
this.pingButton.setOnClick(() -> onPing.accept(position));
|
this.pingButton.setOnClick(() -> onPing.accept(position));
|
||||||
this.detailButton.setOnClick(() -> onEdit.accept(position));
|
this.detailButton.setOnClick(() -> onEdit.accept(position));
|
||||||
|
this.convertButton.setOnClick(() -> setRawPosition(netherCalculator.convert(position)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setRawPosition(PlayerRawPosition position) {
|
||||||
|
this.icon.setImage(ResourceUtils.getIdentifier(position.getWorldDimension()));
|
||||||
|
this.coordinates
|
||||||
|
.setText(new LiteralText(position.getX() + ", " + position.getY() + ", " + position.getZ()));
|
||||||
|
this.convertButton.setOnClick(() -> setRawPosition(netherCalculator.convert(position)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import me.bionicbeanie.mods.savecoords.IFileStore;
|
|||||||
import me.bionicbeanie.mods.savecoords.IKeyBinds;
|
import me.bionicbeanie.mods.savecoords.IKeyBinds;
|
||||||
import me.bionicbeanie.mods.savecoords.IKeyBinds.IKeyBinding;
|
import me.bionicbeanie.mods.savecoords.IKeyBinds.IKeyBinding;
|
||||||
import me.bionicbeanie.mods.savecoords.IModGui;
|
import me.bionicbeanie.mods.savecoords.IModGui;
|
||||||
|
import me.bionicbeanie.mods.savecoords.INetherCalculator;
|
||||||
import me.bionicbeanie.mods.savecoords.IPlayerLocator;
|
import me.bionicbeanie.mods.savecoords.IPlayerLocator;
|
||||||
import me.bionicbeanie.mods.savecoords.gui.IGuiController;
|
import me.bionicbeanie.mods.savecoords.gui.IGuiController;
|
||||||
import me.bionicbeanie.mods.savecoords.gui.IViewHandler;
|
import me.bionicbeanie.mods.savecoords.gui.IViewHandler;
|
||||||
@ -24,14 +25,16 @@ public class SaveCoordinatesGui implements IModGui {
|
|||||||
private IPlayerLocator locator;
|
private IPlayerLocator locator;
|
||||||
private IDimensionAware dimensionAware;
|
private IDimensionAware dimensionAware;
|
||||||
private IKeyBinds keyBinds;
|
private IKeyBinds keyBinds;
|
||||||
|
private INetherCalculator netherCalculator;
|
||||||
|
|
||||||
SaveCoordinatesGui(IFileStore fileStore, IPlayerLocator locator, IDimensionAware dimensionAware, IKeyBinds binds,
|
SaveCoordinatesGui(IFileStore fileStore, IPlayerLocator locator, IDimensionAware dimensionAware, IKeyBinds binds,
|
||||||
IGuiController screenController) {
|
IGuiController screenController, INetherCalculator netherCalculator) {
|
||||||
this.screenController = screenController;
|
this.screenController = screenController;
|
||||||
this.fileStore = fileStore;
|
this.fileStore = fileStore;
|
||||||
this.keyBinds = binds;
|
this.keyBinds = binds;
|
||||||
this.locator = locator;
|
this.locator = locator;
|
||||||
this.dimensionAware = dimensionAware;
|
this.dimensionAware = dimensionAware;
|
||||||
|
this.netherCalculator = netherCalculator;
|
||||||
|
|
||||||
this.defaultHandler = CreateDefaultViewHandler();
|
this.defaultHandler = CreateDefaultViewHandler();
|
||||||
this.listHandler = CreateListViewHandler();
|
this.listHandler = CreateListViewHandler();
|
||||||
@ -57,7 +60,7 @@ public class SaveCoordinatesGui implements IModGui {
|
|||||||
|
|
||||||
private IViewHandler<Void> CreateListViewHandler() {
|
private IViewHandler<Void> CreateListViewHandler() {
|
||||||
ListViewHandler handler = new ListViewHandler(fileStore, this::onDeletePosition, this::onEditPosition,
|
ListViewHandler handler = new ListViewHandler(fileStore, this::onDeletePosition, this::onEditPosition,
|
||||||
this::pingPosition);
|
this::pingPosition, netherCalculator);
|
||||||
|
|
||||||
handler.onBackButtonClick(() -> showDefaultView(null));
|
handler.onBackButtonClick(() -> showDefaultView(null));
|
||||||
|
|
||||||
|
|||||||
@ -9,12 +9,15 @@ import me.bionicbeanie.mods.savecoords.util.ResourceUtils;
|
|||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
public class DimensionAware implements IDimensionAware {
|
class DimensionAware implements IDimensionAware {
|
||||||
|
|
||||||
private List<Dimension> allDimensions;
|
private List<Dimension> allDimensions;
|
||||||
private List<IDimension> allDimensionsReadOnly;
|
private List<IDimension> allDimensionsReadOnly;
|
||||||
private IDimension UNKNOWN = new Dimension("Unknown", ResourceUtils.getIdentifier("unknown"));
|
private IDimension UNKNOWN = new Dimension("Unknown", ResourceUtils.getIdentifier("unknown"), 0);
|
||||||
private MinecraftClient minecraftClient;
|
private MinecraftClient minecraftClient;
|
||||||
|
private int DIM_OVERWORLD = 1;
|
||||||
|
private int DIM_NETHER = 2;
|
||||||
|
private int DIM_END = 4;
|
||||||
|
|
||||||
public DimensionAware(MinecraftClient minecraftClient) {
|
public DimensionAware(MinecraftClient minecraftClient) {
|
||||||
this.minecraftClient = minecraftClient;
|
this.minecraftClient = minecraftClient;
|
||||||
@ -27,9 +30,9 @@ public class DimensionAware implements IDimensionAware {
|
|||||||
|
|
||||||
// TODO: Provide a hook for other mods to add in their dimension info
|
// TODO: Provide a hook for other mods to add in their dimension info
|
||||||
private void initialize(List<Dimension> dimensions) {
|
private void initialize(List<Dimension> dimensions) {
|
||||||
dimensions.add(new Dimension("Overworld", ResourceUtils.getIdentifier("overworld")));
|
dimensions.add(new Dimension("Overworld", ResourceUtils.getIdentifier("overworld"), DIM_OVERWORLD));
|
||||||
dimensions.add(new Dimension("Nether", ResourceUtils.getIdentifier("nether")));
|
dimensions.add(new Dimension("Nether", ResourceUtils.getIdentifier("nether"), DIM_NETHER));
|
||||||
dimensions.add(new Dimension("End", ResourceUtils.getIdentifier("end")));
|
dimensions.add(new Dimension("End", ResourceUtils.getIdentifier("end"), DIM_END));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -54,14 +57,31 @@ public class DimensionAware implements IDimensionAware {
|
|||||||
return UNKNOWN;
|
return UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isOverworld(IDimension dimension) {
|
||||||
|
return dimension.getId() == DIM_OVERWORLD;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isNether(IDimension dimension) {
|
||||||
|
return dimension.getId() == DIM_NETHER;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEnd(IDimension dimension) {
|
||||||
|
return dimension.getId() == DIM_END;
|
||||||
|
}
|
||||||
|
|
||||||
static class Dimension implements IDimension {
|
static class Dimension implements IDimension {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private Identifier spriteIdentifier;
|
private Identifier spriteIdentifier;
|
||||||
|
private int dimensionId;
|
||||||
|
|
||||||
Dimension(String name, Identifier spriteIdentifier) {
|
Dimension(String name, Identifier spriteIdentifier, int dimensionId) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.spriteIdentifier = spriteIdentifier;
|
this.spriteIdentifier = spriteIdentifier;
|
||||||
|
this.dimensionId = dimensionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -77,7 +97,15 @@ public class DimensionAware implements IDimensionAware {
|
|||||||
boolean isDimension(String registryKey) {
|
boolean isDimension(String registryKey) {
|
||||||
return (registryKey != null && registryKey.toLowerCase().contains(this.name.toLowerCase()));
|
return (registryKey != null && registryKey.toLowerCase().contains(this.name.toLowerCase()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int getDimensionId() {
|
||||||
|
return this.dimensionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getId() {
|
||||||
|
return this.dimensionId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package me.bionicbeanie.mods.savecoords.impl;
|
|||||||
import me.bionicbeanie.mods.savecoords.IDimensionAware;
|
import me.bionicbeanie.mods.savecoords.IDimensionAware;
|
||||||
import me.bionicbeanie.mods.savecoords.IFileStore;
|
import me.bionicbeanie.mods.savecoords.IFileStore;
|
||||||
import me.bionicbeanie.mods.savecoords.IKeyBinds;
|
import me.bionicbeanie.mods.savecoords.IKeyBinds;
|
||||||
|
import me.bionicbeanie.mods.savecoords.INetherCalculator;
|
||||||
import me.bionicbeanie.mods.savecoords.IPlayerLocator;
|
import me.bionicbeanie.mods.savecoords.IPlayerLocator;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
|
||||||
@ -23,4 +24,8 @@ public class Factory {
|
|||||||
public static IDimensionAware CreateDimensionAware(MinecraftClient client) {
|
public static IDimensionAware CreateDimensionAware(MinecraftClient client) {
|
||||||
return new DimensionAware(client);
|
return new DimensionAware(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static INetherCalculator CreateNetherCalculator(IDimensionAware dimensionAware) {
|
||||||
|
return new NetherCalculator(dimensionAware);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,47 @@
|
|||||||
|
package me.bionicbeanie.mods.savecoords.impl;
|
||||||
|
|
||||||
|
import me.bionicbeanie.mods.savecoords.IDimensionAware;
|
||||||
|
import me.bionicbeanie.mods.savecoords.IDimensionAware.IDimension;
|
||||||
|
import me.bionicbeanie.mods.savecoords.INetherCalculator;
|
||||||
|
import me.bionicbeanie.mods.savecoords.model.PlayerRawPosition;
|
||||||
|
|
||||||
|
class NetherCalculator implements INetherCalculator {
|
||||||
|
|
||||||
|
private int MULTIPLIER = 8;
|
||||||
|
private IDimensionAware dimensionAware;
|
||||||
|
private IDimension overworld;
|
||||||
|
private IDimension nether;
|
||||||
|
|
||||||
|
public NetherCalculator(IDimensionAware dimensionAware) {
|
||||||
|
this.dimensionAware = dimensionAware;
|
||||||
|
|
||||||
|
for (IDimension dimension : dimensionAware.getDimensions()) {
|
||||||
|
if (dimensionAware.isOverworld(dimension)) {
|
||||||
|
overworld = dimension;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dimensionAware.isNether(dimension)) {
|
||||||
|
nether = dimension;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PlayerRawPosition convert(PlayerRawPosition position) {
|
||||||
|
IDimension dimension = dimensionAware.getDimension(position.getWorldDimension());
|
||||||
|
|
||||||
|
if (dimensionAware.isOverworld(dimension)) {
|
||||||
|
return new PlayerRawPosition(position.getX() / MULTIPLIER, position.getY(), position.getZ() / MULTIPLIER,
|
||||||
|
nether.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dimensionAware.isNether(dimension)) {
|
||||||
|
return new PlayerRawPosition(position.getX() * MULTIPLIER, position.getY(), position.getZ() * MULTIPLIER,
|
||||||
|
overworld.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user