appliedflux下供应器逻辑

This commit is contained in:
GaLicn 2025-09-25 15:01:47 +08:00
parent 4327ccc67a
commit 2a4dd481a0
2 changed files with 78 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package com.extendedae_plus.mixin.ae2.compat; package com.extendedae_plus.mixin.ae2.compat;
import appeng.api.networking.IManagedGridNode; import appeng.api.networking.IManagedGridNode;
import appeng.api.networking.IGridConnection;
import appeng.api.networking.security.IActionSource; import appeng.api.networking.security.IActionSource;
import appeng.api.upgrades.IUpgradeInventory; import appeng.api.upgrades.IUpgradeInventory;
import appeng.api.upgrades.IUpgradeableObject; import appeng.api.upgrades.IUpgradeableObject;
@ -282,6 +283,24 @@ public abstract class PatternProviderLogicCompatMixin implements CompatUpgradePr
eap$compatLastChannel = 0L; eap$compatLastChannel = 0L;
eap$compatHasInitialized = true; eap$compatHasInitialized = true;
try { host.saveChanges(); } catch (Throwable ignored) {} try { host.saveChanges(); } catch (Throwable ignored) {}
// 唤醒节点加速 AE2 感知到连接断开
mainNode.ifPresent((grid, node) -> {
try { grid.getTickManager().wakeDevice(node); } catch (Throwable ignored) {}
// 兜底如仍存在针对无线主端的直连 in-world强制销毁
try {
for (IGridConnection gc : node.getConnections()) {
if (gc != null && !gc.isInWorld()) {
var other = gc.getOtherSide(node);
if (other != null && other.getOwner() instanceof com.extendedae_plus.wireless.IWirelessEndpoint) {
ExtendedAELogger.LOGGER.debug("[样板供应器] 兜底销毁残留无线直连: {} -> {}", node, other);
gc.destroy();
try { grid.getTickManager().wakeDevice(node); } catch (Throwable ignored2) {}
try { if (other.getGrid() != null) { other.getGrid().getTickManager().wakeDevice(other); } } catch (Throwable ignored2) {}
}
}
}
} catch (Throwable ignored2) {}
});
return; return;
} }

View File

@ -1,6 +1,7 @@
package com.extendedae_plus.wireless; package com.extendedae_plus.wireless;
import appeng.api.networking.GridHelper; import appeng.api.networking.GridHelper;
import appeng.api.networking.IGridConnection;
import appeng.api.networking.IGridNode; import appeng.api.networking.IGridNode;
import appeng.me.service.helpers.ConnectionWrapper; import appeng.me.service.helpers.ConnectionWrapper;
import com.extendedae_plus.config.ModConfigs; import com.extendedae_plus.config.ModConfigs;
@ -99,6 +100,13 @@ public class WirelessSlaveLink {
current.destroy(); current.destroy();
connection = new ConnectionWrapper(null); connection = new ConnectionWrapper(null);
} }
// AE2 侧是否已经存在连接例如此前创建但 wrapper 丢失
IGridConnection existing = findExistingConnection(a, b);
if (existing != null) {
ExtendedAELogger.LOGGER.debug("[无线] 复用已存在的连接: {}", existing);
connection = new ConnectionWrapper(existing);
return;
}
ExtendedAELogger.LOGGER.debug("[无线] 创建连接: a={}, b={}", a, b); ExtendedAELogger.LOGGER.debug("[无线] 创建连接: a={}, b={}", a, b);
connection = new ConnectionWrapper(GridHelper.createConnection(a, b)); connection = new ConnectionWrapper(GridHelper.createConnection(a, b));
ExtendedAELogger.LOGGER.debug("[无线] 连接创建完成: {}", connection.getConnection()); ExtendedAELogger.LOGGER.debug("[无线] 连接创建完成: {}", connection.getConnection());
@ -128,9 +136,60 @@ public class WirelessSlaveLink {
private void destroyConnection() { private void destroyConnection() {
var current = connection.getConnection(); var current = connection.getConnection();
if (current != null) { if (current != null) {
ExtendedAELogger.LOGGER.debug("[无线] 销毁连接: {}", current);
var a = current.a();
var b = current.b();
// 先销毁连接再唤醒两端节点使其尽快感知到状态变化
current.destroy(); current.destroy();
try {
if (a != null && a.getGrid() != null) {
a.getGrid().getTickManager().wakeDevice(a);
}
} catch (Throwable ignored) {}
try {
if (b != null && b.getGrid() != null) {
b.getGrid().getTickManager().wakeDevice(b);
}
} catch (Throwable ignored) {}
connection.setConnection(null); connection.setConnection(null);
} else {
// 兜底如果 wrapper 已丢失 AE2 内仍有直连则尝试查找并销毁
try {
IGridNode a = host.getGridNode();
if (a != null) {
for (IGridConnection gc : a.getConnections()) {
// 我们创建的是非 in-world 直连
if (gc != null && !gc.isInWorld()) {
IGridNode other = gc.getOtherSide(a);
Object owner = other != null ? other.getOwner() : null;
if (owner instanceof IWirelessEndpoint) {
ExtendedAELogger.LOGGER.debug("[无线] 兜底销毁直连: {} -> {}", a, other);
gc.destroy();
try { if (a.getGrid() != null) { a.getGrid().getTickManager().wakeDevice(a); } } catch (Throwable ignored) {}
try { if (other != null && other.getGrid() != null) { other.getGrid().getTickManager().wakeDevice(other); } } catch (Throwable ignored) {}
}
}
}
}
} catch (Throwable ignored) {}
} }
connection = new ConnectionWrapper(null); connection = new ConnectionWrapper(null);
} }
/**
* AE2 中查找 a b 之间是否已经有连接存在用于复用避免重复创建异常
*/
private IGridConnection findExistingConnection(IGridNode a, IGridNode b) {
try {
for (IGridConnection gc : a.getConnections()) {
var ga = gc.a();
var gb = gc.b();
if ((ga == a || gb == a) && (ga == b || gb == b)) {
return gc;
}
}
} catch (Throwable ignored) {}
return null;
}
} }