Skip to content

Commit

Permalink
fix (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mari023 committed Dec 7, 2023
1 parent 3facabb commit 0745df1
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 31 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
- update russian translations
- fix "Linked Network cannot be found" message appearing even if the terminal clearly works (#221)
32 changes: 16 additions & 16 deletions src/main/java/de/mari_023/ae2wtlib/TextConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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");
}
45 changes: 45 additions & 0 deletions src/main/java/de/mari_023/ae2wtlib/terminal/GridResult.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
53 changes: 41 additions & 12 deletions src/main/java/de/mari_023/ae2wtlib/terminal/ItemWT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/de/mari_023/ae2wtlib/terminal/WTMenuHost.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/ae2wtlib/lang/de_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
2 changes: 2 additions & 0 deletions src/main/resources/assets/ae2wtlib/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 0745df1

Please sign in to comment.