logo&无线收发器更新状态逻辑优化

This commit is contained in:
GaLicn 2025-12-02 22:10:16 +08:00
parent 1041d55b4e
commit b399d3c201
2 changed files with 13 additions and 1 deletions

View File

@ -35,6 +35,10 @@ public class WirelessTransceiverBlockEntity extends AEBaseBlockEntity implements
private long frequency = 1L;
private boolean masterMode = false;
private boolean locked = false;
/**
* 标记该方块实体是否正在被移除用于避免在移除流程中再次 setBlock 导致方块复活
*/
private boolean beingRemoved = false;
@Nullable
private UUID placerId; // 放置者UUID用于队伍隔离
@ -190,6 +194,8 @@ public class WirelessTransceiverBlockEntity extends AEBaseBlockEntity implements
}
public void onRemoved() {
// 标记正在被移除避免在 AE2 回调期间触发状态刷新把方块重新放回世界中
this.beingRemoved = true;
if (this.masterMode) {
masterLink.onUnloadOrRemove();
} else {
@ -216,6 +222,13 @@ public class WirelessTransceiverBlockEntity extends AEBaseBlockEntity implements
*/
private void updateState() {
if (this.level == null || this.level.isClientSide) return;
// 如果方块实体已经被标记为移除或已经从世界中移除不再尝试刷新状态
if (this.beingRemoved || this.isRemoved()) return;
// 确保当前位置仍然是本方块防止在方块被替换/破坏时错误地重新放置方块
BlockState currentState = this.getBlockState();
if (!(currentState.getBlock() instanceof WirelessTransceiverBlock)) {
return;
}
IGridNode node = this.getGridNode();
int newState = 5; // 默认状态无连接
@ -248,7 +261,6 @@ public class WirelessTransceiverBlockEntity extends AEBaseBlockEntity implements
}
// 更新方块状态
BlockState currentState = this.getBlockState();
if (currentState.getValue(WirelessTransceiverBlock.STATE) != newState) {
this.level.setBlock(this.worldPosition, currentState.setValue(WirelessTransceiverBlock.STATE, newState), 3);
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 200 KiB

After

Width:  |  Height:  |  Size: 13 KiB