修复使用标签无线收发器时偶现退出游戏无法保存问题
This commit is contained in:
parent
7a586fc87d
commit
6d530b8f96
|
|
@ -91,7 +91,7 @@ dependencies {
|
|||
modImplementation "curse.maven:mega-cells-622112:${mega_cells_version}"
|
||||
|
||||
//mae2
|
||||
modRuntimeOnly "curse.maven:modern-ae2-additions-1028068:6827727"
|
||||
//modRuntimeOnly "curse.maven:modern-ae2-additions-1028068:6827727"
|
||||
modCompileOnly "curse.maven:modern-ae2-additions-1028068:6827727"
|
||||
|
||||
//aea
|
||||
|
|
@ -115,7 +115,8 @@ dependencies {
|
|||
modRuntimeOnly "curse.maven:cloth-config-348521:5729105"
|
||||
|
||||
//jec
|
||||
modImplementation "curse.maven:just-enough-characters-250702:6680042"
|
||||
modCompileClasspath "curse.maven:just-enough-characters-250702:6680042"
|
||||
modRuntimeOnly "curse.maven:just-enough-characters-250702:6680042"
|
||||
|
||||
//geckolib
|
||||
modRuntimeOnly "curse.maven:geckolib-388172:6920925"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.extendedae_plus.ae.wireless;
|
||||
|
||||
import appeng.api.networking.GridHelper;
|
||||
import appeng.api.networking.IGridConnection;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.me.service.helpers.ConnectionWrapper;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
|
|
@ -88,14 +89,62 @@ public class LabelLink {
|
|||
}
|
||||
|
||||
public void onUnloadOrRemove() {
|
||||
this.target = null;
|
||||
destroyConnection();
|
||||
}
|
||||
|
||||
private void destroyConnection() {
|
||||
var current = connection.getConnection();
|
||||
if (current != null) {
|
||||
var a = current.a();
|
||||
var b = current.b();
|
||||
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);
|
||||
} else {
|
||||
try {
|
||||
IGridNode hostNode = this.host.getGridNode();
|
||||
IGridNode targetNode = this.target == null ? null : this.target.node();
|
||||
if (hostNode != null && targetNode != null) {
|
||||
IGridConnection existing = this.findExistingConnection(hostNode, targetNode);
|
||||
if (existing != null) {
|
||||
existing.destroy();
|
||||
try {
|
||||
if (hostNode.getGrid() != null) {
|
||||
hostNode.getGrid().getTickManager().wakeDevice(hostNode);
|
||||
}
|
||||
} catch (Throwable ignored) {}
|
||||
try {
|
||||
if (targetNode.getGrid() != null) {
|
||||
targetNode.getGrid().getTickManager().wakeDevice(targetNode);
|
||||
}
|
||||
} catch (Throwable ignored) {}
|
||||
}
|
||||
}
|
||||
} catch (Throwable ignored) {}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -184,14 +184,34 @@ public class LabeledWirelessTransceiverBlockEntity extends AEBaseBlockEntity imp
|
|||
}
|
||||
|
||||
public void onRemoved() {
|
||||
cleanupForRemoval();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkUnloaded() {
|
||||
cleanupForRemoval();
|
||||
super.onChunkUnloaded();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRemoved() {
|
||||
cleanupForRemoval();
|
||||
super.setRemoved();
|
||||
}
|
||||
|
||||
private void cleanupForRemoval() {
|
||||
if (this.beingRemoved) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.beingRemoved = true;
|
||||
labelLink.onUnloadOrRemove();
|
||||
this.labelLink.onUnloadOrRemove();
|
||||
ServerLevel sl = getServerLevel();
|
||||
if (sl != null) {
|
||||
LabelNetworkRegistry.get(sl).unregister(this);
|
||||
}
|
||||
if (managedNode != null) {
|
||||
managedNode.destroy();
|
||||
if (this.managedNode != null) {
|
||||
this.managedNode.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user