diff --git a/CHANGELOG.md b/CHANGELOG.md index 8764f14e..e562d1e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ - remove reverse charging, it seemed caused more issues than it fixed (fix #230) - change energy usage when quantum linked to be more like an ae2 quantum bridges energy usage (22.5 ae / tick) (fix #222) -- update russian translations \ No newline at end of file +- update russian translations +- fix "Linked Network cannot be found" message appearing even if the terminal clearly works (#221) \ No newline at end of file diff --git a/src/main/java/de/mari_023/ae2wtlib/TextConstants.java b/src/main/java/de/mari_023/ae2wtlib/TextConstants.java index d652943c..98e919ff 100644 --- a/src/main/java/de/mari_023/ae2wtlib/TextConstants.java +++ b/src/main/java/de/mari_023/ae2wtlib/TextConstants.java @@ -21,33 +21,31 @@ private TextConstants() { public static final MutableComponent RESTOCK_OFF = Component.translatable("gui.ae2wtlib.restock") .append(Component.translatable("gui.ae2wtlib.off").setStyle(STYLE_RED)); - public static final MutableComponent HOTKEY_MAGNETCARD_INVENTORY = Component.translatable( - "gui.ae2wtlib.magnetcard.hotkey") + public static final MutableComponent HOTKEY_MAGNETCARD_INVENTORY = Component + .translatable("gui.ae2wtlib.magnetcard.hotkey") .append(Component.translatable("gui.ae2wtlib.magnetcard.desc.inv").setStyle(STYLE_GREEN)); - public static final MutableComponent HOTKEY_MAGNETCARD_ME = Component.translatable( - "gui.ae2wtlib.magnetcard.hotkey") + public static final MutableComponent HOTKEY_MAGNETCARD_ME = Component.translatable("gui.ae2wtlib.magnetcard.hotkey") .append(Component.translatable("gui.ae2wtlib.magnetcard.desc.me").setStyle(STYLE_GREEN)); - public static final MutableComponent HOTKEY_MAGNETCARD_OFF = Component.translatable( - "gui.ae2wtlib.magnetcard.hotkey") + public static final MutableComponent HOTKEY_MAGNETCARD_OFF = Component + .translatable("gui.ae2wtlib.magnetcard.hotkey") .append(Component.translatable("gui.ae2wtlib.magnetcard.desc.off").setStyle(STYLE_RED)); - public static final MutableComponent MAGNETCARD_OFF = Component.translatable("gui.ae2wtlib.magnetcard") - .append("\n").append(Component.translatable("gui.ae2wtlib.magnetcard.desc.off")); + public static final MutableComponent MAGNETCARD_OFF = Component.translatable("gui.ae2wtlib.magnetcard").append("\n") + .append(Component.translatable("gui.ae2wtlib.magnetcard.desc.off")); public static final MutableComponent MAGNETCARD_INVENTORY = Component.translatable("gui.ae2wtlib.magnetcard") .append("\n").append(Component.translatable("gui.ae2wtlib.magnetcard.desc.inv")); - public static final MutableComponent MAGNETCARD_ME = Component.translatable("gui.ae2wtlib.magnetcard") - .append("\n").append(Component.translatable("gui.ae2wtlib.magnetcard.desc.me")); + public static final MutableComponent MAGNETCARD_ME = Component.translatable("gui.ae2wtlib.magnetcard").append("\n") + .append(Component.translatable("gui.ae2wtlib.magnetcard.desc.me")); - public static final MutableComponent UNIVERSAL = Component.translatable( - "item.ae2wtlib.wireless_universal_terminal.desc").withStyle(STYLE_GRAY); + public static final MutableComponent UNIVERSAL = Component + .translatable("item.ae2wtlib.wireless_universal_terminal.desc").withStyle(STYLE_GRAY); public static MutableComponent formatTerminalName(String terminal) { return Component.translatable(terminal).withStyle(STYLE_GRAY); } - public static final Component TERMINAL_EMPTY = Component.literal( - "This terminal does not contain any other Terminals"); - public static final Component CYCLE_TOOLTIP = Component.translatable( - "gui.ae2wtlib.cycle_terminal.desc"); + public static final Component TERMINAL_EMPTY = Component + .literal("This terminal does not contain any other Terminals"); + public static final Component CYCLE_TOOLTIP = Component.translatable("gui.ae2wtlib.cycle_terminal.desc"); public static final MutableComponent TRASH = Component.translatable("gui.ae2wtlib.trash"); @@ -84,4 +82,6 @@ public static MutableComponent getInsertMode(IncludeExclude includeExclude) { public static final Component SWITCH = Component.translatable("gui.ae2wtlib.switch"); public static final Component CREATIVE_TAB = Component.translatable("gui.ae2wtlib.creativetab"); + + public static final Component NETWORK_NOT_POWERED = Component.translatable("chat.ae2wtlib.NetworkNotPowered"); } diff --git a/src/main/java/de/mari_023/ae2wtlib/terminal/GridResult.java b/src/main/java/de/mari_023/ae2wtlib/terminal/GridResult.java new file mode 100644 index 00000000..1e2690e4 --- /dev/null +++ b/src/main/java/de/mari_023/ae2wtlib/terminal/GridResult.java @@ -0,0 +1,45 @@ +package de.mari_023.ae2wtlib.terminal; + +import javax.annotation.Nullable; + +import net.minecraft.network.chat.Component; + +import de.mari_023.ae2wtlib.TextConstants; + +import appeng.api.networking.IGrid; +import appeng.core.localization.PlayerMessages; + +public record GridResult(@Nullable IGrid grid, GridStatus status) { + + public static GridResult valid(IGrid grid) { + return new GridResult(grid, GridStatus.Valid); + } + + public static GridResult invalid(GridStatus status) { + return new GridResult(null, status); + } + + public enum GridStatus { + Valid(null), + NotServer(null), + NotLinked(PlayerMessages.DeviceNotLinked.text()), + NotPowered(TextConstants.NETWORK_NOT_POWERED), + NotFound(PlayerMessages.LinkedNetworkNotFound.text()); + + @Nullable + private final Component error; + + GridStatus(@Nullable Component error) { + this.error = error; + } + + @Nullable + public Component getError() { + return error; + } + + public boolean isValid() { + return this == Valid; + } + } +} diff --git a/src/main/java/de/mari_023/ae2wtlib/terminal/ItemWT.java b/src/main/java/de/mari_023/ae2wtlib/terminal/ItemWT.java index 789ecfea..f62bef08 100644 --- a/src/main/java/de/mari_023/ae2wtlib/terminal/ItemWT.java +++ b/src/main/java/de/mari_023/ae2wtlib/terminal/ItemWT.java @@ -4,6 +4,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResultHolder; @@ -16,15 +17,16 @@ import de.mari_023.ae2wtlib.wut.WUTHandler; import appeng.api.features.Locatables; +import appeng.api.implementations.blockentities.IWirelessAccessPoint; import appeng.api.implementations.menuobjects.ItemMenuHost; import appeng.api.networking.IGrid; import appeng.api.networking.security.IActionHost; import appeng.api.upgrades.IUpgradeInventory; import appeng.api.upgrades.UpgradeInventories; import appeng.core.AEConfig; -import appeng.core.localization.PlayerMessages; import appeng.items.tools.powered.WirelessTerminalItem; import appeng.menu.locator.MenuLocators; +import appeng.util.Platform; import appeng.util.inv.AppEngInternalInventory; public abstract class ItemWT extends WirelessTerminalItem implements IUniversalWirelessTerminalItem { @@ -92,27 +94,54 @@ public static IActionHost getQuantumBridge(ItemStack itemStack, Level level, return findQuantumBridge(level, frequency); } - @Nullable - private IGrid getLinkedGrid(ItemStack item, Level level) { - IGrid grid = super.getLinkedGrid(item, level, null); - if (grid != null) + private GridResult getLinkedGrid(ItemStack item, Level level) { + if (!(level instanceof ServerLevel serverLevel)) + return GridResult.invalid(GridResult.GridStatus.NotServer); + + GridResult grid = getAccessPointLinkedGrid(item, serverLevel); + if (grid.status().isValid()) return grid; + var quantumBridge = getQuantumBridge(item, level, null, null); if (quantumBridge == null) - return null; + return grid; if (quantumBridge.getActionableNode() == null) - return null; - return quantumBridge.getActionableNode().getGrid(); + return GridResult.invalid(GridResult.GridStatus.NotFound); + if (!quantumBridge.getActionableNode().isPowered()) + return GridResult.invalid(GridResult.GridStatus.NotPowered); + return GridResult.valid(quantumBridge.getActionableNode().getGrid()); + } + + private GridResult getAccessPointLinkedGrid(ItemStack item, ServerLevel level) { + var linkedPos = getLinkedPosition(item); + if (linkedPos == null) + return GridResult.invalid(GridResult.GridStatus.NotLinked); + + var linkedLevel = level.getServer().getLevel(linkedPos.dimension()); + if (linkedLevel == null) + return GridResult.invalid(GridResult.GridStatus.NotFound); + + var be = Platform.getTickingBlockEntity(linkedLevel, linkedPos.pos()); + if (!(be instanceof IWirelessAccessPoint accessPoint)) + return GridResult.invalid(GridResult.GridStatus.NotFound); + + var grid = accessPoint.getGrid(); + if (grid == null) + return GridResult.invalid(GridResult.GridStatus.NotFound); + + if (!grid.getEnergyService().isNetworkPowered()) + return GridResult.invalid(GridResult.GridStatus.NotPowered); + return GridResult.valid(grid); } @Nullable public IGrid getLinkedGrid(ItemStack item, Level level, @Nullable Player sendMessagesTo) { - IGrid grid = getLinkedGrid(item, level); - if (grid == null && sendMessagesTo != null && level.isClientSide()) { - sendMessagesTo.displayClientMessage(PlayerMessages.LinkedNetworkNotFound.text(), true); + GridResult grid = getLinkedGrid(item, level); + if (grid.status().getError() != null && sendMessagesTo != null && !level.isClientSide()) { + sendMessagesTo.displayClientMessage(grid.status().getError(), true); } - return grid; + return grid.grid(); } /** diff --git a/src/main/java/de/mari_023/ae2wtlib/terminal/WTMenuHost.java b/src/main/java/de/mari_023/ae2wtlib/terminal/WTMenuHost.java index b8a68326..0546e78a 100644 --- a/src/main/java/de/mari_023/ae2wtlib/terminal/WTMenuHost.java +++ b/src/main/java/de/mari_023/ae2wtlib/terminal/WTMenuHost.java @@ -86,7 +86,7 @@ public IGridNode getActionableNode() { public MEStorage getInventory() { var node = getActionableNode(); if (node == null) - return null; + return super.getInventory(); return node.getGrid().getStorageService().getInventory(); } @@ -115,7 +115,7 @@ public boolean isQuantumLinked() { } if (quantumBridge.getActionableNode() == null) return false; - return (quantumBridge.getActionableNode().getGrid() == targetGrid || targetGrid == null) + return (quantumBridge.getActionableNode().getGrid() == targetGrid && targetGrid != null) && targetGrid.getEnergyService().isNetworkPowered(); } diff --git a/src/main/resources/assets/ae2wtlib/lang/de_de.json b/src/main/resources/assets/ae2wtlib/lang/de_de.json index fd323964..7eda602b 100644 --- a/src/main/resources/assets/ae2wtlib/lang/de_de.json +++ b/src/main/resources/assets/ae2wtlib/lang/de_de.json @@ -36,6 +36,8 @@ "key.ae2.ae2wtlib_restock": "Nachfüllen umschalten", "key.ae2.ae2wtlib_magnet": "Magnet Karte umschalten", + "chat.ae2wtlib.NetworkNotPowered" : "Netzwerk hat keine Energie", + "text.autoconfig.de/mari_023/ae2wtlib.title": "AE2 Wireless Terminals", "text.autoconfig.de/mari_023/ae2wtlib.option.magnetCardRange": "Reichweite der Magnet Karte" } diff --git a/src/main/resources/assets/ae2wtlib/lang/en_us.json b/src/main/resources/assets/ae2wtlib/lang/en_us.json index ee50a36d..b6bdee05 100644 --- a/src/main/resources/assets/ae2wtlib/lang/en_us.json +++ b/src/main/resources/assets/ae2wtlib/lang/en_us.json @@ -38,6 +38,8 @@ "key.ae2.ae2wtlib_restock": "Toggle Restock", "key.ae2.ae2wtlib_magnet": "Toggle Magnet Card", + "chat.ae2wtlib.NetworkNotPowered" : "Network Not Powered", + "text.autoconfig.de/mari_023/ae2wtlib.title": "AE2 Wireless Terminals", "text.autoconfig.de/mari_023/ae2wtlib.option.magnetCardRange": "Magnet Card Range"