无线收发器添加jade显示所有者/团队

This commit is contained in:
GaLicn 2025-10-05 12:33:25 +08:00
parent b31ec61b54
commit 30bb52e2e9
6 changed files with 68 additions and 6 deletions

View File

@ -39,7 +39,7 @@ public class WirelessTransceiverBlock extends Block implements EntityBlock {
if (!level.isClientSide && placer instanceof Player player) { if (!level.isClientSide && placer instanceof Player player) {
BlockEntity be = level.getBlockEntity(pos); BlockEntity be = level.getBlockEntity(pos);
if (be instanceof WirelessTransceiverBlockEntity te) { if (be instanceof WirelessTransceiverBlockEntity te) {
te.setPlacerId(player.getUUID()); te.setPlacerId(player.getUUID(), player.getName().getString());
} }
} }
} }
@ -87,15 +87,15 @@ public class WirelessTransceiverBlock extends Block implements EntityBlock {
if (cardOwner != null) { if (cardOwner != null) {
// 写入频道卡的所有者到收发器 // 写入频道卡的所有者到收发器
te.setPlacerId(cardOwner);
String teamName = ChannelCardItem.getTeamName(channelCard); String teamName = ChannelCardItem.getTeamName(channelCard);
te.setPlacerId(cardOwner, teamName);
player.displayClientMessage( player.displayClientMessage(
Component.literal("已将收发器绑定至:" + (teamName != null ? teamName : cardOwner.toString().substring(0, 8))), Component.literal("已将收发器绑定至:" + (teamName != null ? teamName : cardOwner.toString().substring(0, 8))),
true true
); );
} else { } else {
// 频道卡未绑定所有者使用当前玩家 // 频道卡未绑定所有者使用当前玩家
te.setPlacerId(player.getUUID()); te.setPlacerId(player.getUUID(), player.getName().getString());
player.displayClientMessage(Component.literal("频道卡未绑定,已使用当前玩家"), true); player.displayClientMessage(Component.literal("频道卡未绑定,已使用当前玩家"), true);
} }
} }

View File

@ -38,6 +38,8 @@ public class WirelessTransceiverBlockEntity extends AEBaseBlockEntity implements
@Nullable @Nullable
private UUID placerId; // 放置者UUID用于队伍隔离 private UUID placerId; // 放置者UUID用于队伍隔离
@Nullable
private String placerName; // 放置者名称用于显示
private WirelessMasterLink masterLink; private WirelessMasterLink masterLink;
private WirelessSlaveLink slaveLink; private WirelessSlaveLink slaveLink;
@ -103,9 +105,9 @@ public class WirelessTransceiverBlockEntity extends AEBaseBlockEntity implements
/* ===================== 公共方法(交互调用) ===================== */ /* ===================== 公共方法(交互调用) ===================== */
/** /**
* 设置放置者UUID在方块放置时调用 * 设置放置者UUID和名称在方块放置时调用
*/ */
public void setPlacerId(@Nullable UUID placerId) { public void setPlacerId(@Nullable UUID placerId, @Nullable String placerName) {
if (this.placerId != null && !this.placerId.equals(placerId)) { if (this.placerId != null && !this.placerId.equals(placerId)) {
// 如果所有者改变需要重新注册 // 如果所有者改变需要重新注册
if (this.masterMode) { if (this.masterMode) {
@ -115,16 +117,29 @@ public class WirelessTransceiverBlockEntity extends AEBaseBlockEntity implements
} }
} }
this.placerId = placerId; this.placerId = placerId;
this.placerName = placerName;
this.masterLink.setPlacerId(placerId); this.masterLink.setPlacerId(placerId);
this.slaveLink.setPlacerId(placerId); this.slaveLink.setPlacerId(placerId);
setChanged(); setChanged();
} }
/**
* 仅设置UUID兼容旧代码
*/
public void setPlacerId(@Nullable UUID placerId) {
setPlacerId(placerId, null);
}
@Nullable @Nullable
public UUID getPlacerId() { public UUID getPlacerId() {
return placerId; return placerId;
} }
@Nullable
public String getPlacerName() {
return placerName;
}
public long getFrequency() { public long getFrequency() {
return frequency; return frequency;
} }
@ -224,6 +239,9 @@ public class WirelessTransceiverBlockEntity extends AEBaseBlockEntity implements
if (placerId != null) { if (placerId != null) {
tag.putUUID("placerId", placerId); tag.putUUID("placerId", placerId);
} }
if (placerName != null) {
tag.putString("placerName", placerName);
}
if (managedNode != null) { if (managedNode != null) {
managedNode.saveToNBT(tag); managedNode.saveToNBT(tag);
} }
@ -241,6 +259,10 @@ public class WirelessTransceiverBlockEntity extends AEBaseBlockEntity implements
this.masterLink.setPlacerId(this.placerId); this.masterLink.setPlacerId(this.placerId);
this.slaveLink.setPlacerId(this.placerId); this.slaveLink.setPlacerId(this.placerId);
} }
if (tag.contains("placerName")) {
this.placerName = tag.getString("placerName");
}
if (managedNode != null) { if (managedNode != null) {
managedNode.loadFromNBT(tag); managedNode.loadFromNBT(tag);

View File

@ -83,6 +83,22 @@ public enum WirelessTransceiverJadePluginComponents implements IBlockComponentPr
} }
} }
} }
},
OWNER("wt_owner") {
@Override
protected void add(BlockAccessor accessor, ITooltip tooltip, IPluginConfig config, CompoundTag data) {
if (data.contains("ownerName")) {
String ownerName = data.getString("ownerName");
tooltip.add(Component.translatable("extendedae_plus.tooltip.owner", ownerName));
} else if (data.contains("placerId")) {
// 有placerId但没有名称显示UUID
java.util.UUID placerId = data.getUUID("placerId");
tooltip.add(Component.translatable("extendedae_plus.tooltip.owner", placerId.toString().substring(0, 8) + "..."));
} else {
// 没有所有者信息旧版本存档
tooltip.add(Component.translatable("extendedae_plus.tooltip.owner.unset"));
}
}
}; };
private final ResourceLocation uid; private final ResourceLocation uid;

View File

@ -5,8 +5,10 @@ import appeng.api.networking.IGridNode;
import com.extendedae_plus.ae.wireless.IWirelessEndpoint; import com.extendedae_plus.ae.wireless.IWirelessEndpoint;
import com.extendedae_plus.ae.wireless.WirelessMasterRegistry; import com.extendedae_plus.ae.wireless.WirelessMasterRegistry;
import com.extendedae_plus.content.wireless.WirelessTransceiverBlockEntity; import com.extendedae_plus.content.wireless.WirelessTransceiverBlockEntity;
import com.extendedae_plus.util.WirelessTeamUtil;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import snownee.jade.api.BlockAccessor; import snownee.jade.api.BlockAccessor;
import snownee.jade.api.IServerDataProvider; import snownee.jade.api.IServerDataProvider;
@ -62,11 +64,23 @@ public enum WirelessTransceiverProvider implements IServerDataProvider<BlockAcce
data.putInt("usedChannels", usedChannels); data.putInt("usedChannels", usedChannels);
data.putInt("maxChannels", maxChannels); data.putInt("maxChannels", maxChannels);
// 添加所有者信息有FTBTeams时显示团队否则显示玩家
var placerId = blockEntity.getPlacerId();
if (placerId != null) {
data.putUUID("placerId", placerId);
var level = blockEntity.getServerLevel();
if (level != null) {
// 使用WirelessTeamUtil自动判断显示团队或玩家名称
Component ownerName = WirelessTeamUtil.getNetworkOwnerName(level, placerId);
data.putString("ownerName", ownerName.getString());
}
}
// 如果是从模式查询主节点位置与维度 // 如果是从模式查询主节点位置与维度
if (!blockEntity.isMasterMode()) { if (!blockEntity.isMasterMode()) {
var level = blockEntity.getServerLevel(); var level = blockEntity.getServerLevel();
long freq = blockEntity.getFrequency(); long freq = blockEntity.getFrequency();
var placerId = blockEntity.getPlacerId(); // 获取放置者UUID // 复用上面的placerId变量
IWirelessEndpoint master = WirelessMasterRegistry.get(level, freq, placerId); IWirelessEndpoint master = WirelessMasterRegistry.get(level, freq, placerId);
if (master != null && !master.isEndpointRemoved()) { if (master != null && !master.isEndpointRemoved()) {
if (master instanceof WirelessTransceiverBlockEntity masterBlockEntity && masterBlockEntity.getCustomName() != null) { if (master instanceof WirelessTransceiverBlockEntity masterBlockEntity && masterBlockEntity.getCustomName() != null) {

View File

@ -73,6 +73,7 @@
"config.jade.plugin_extendedae_plus.wt_locked": "Show Locked State", "config.jade.plugin_extendedae_plus.wt_locked": "Show Locked State",
"config.jade.plugin_extendedae_plus.wt_network_usable": "Show Network Online State", "config.jade.plugin_extendedae_plus.wt_network_usable": "Show Network Online State",
"config.jade.plugin_extendedae_plus.wt_channels": "Show Channel Usage", "config.jade.plugin_extendedae_plus.wt_channels": "Show Channel Usage",
"config.jade.plugin_extendedae_plus.wt_owner": "Show Owner Information",
"extendedae_plus.tooltip.frequency": "Frequency: %d", "extendedae_plus.tooltip.frequency": "Frequency: %d",
"extendedae_plus.tooltip.master_mode": "Mode: %s", "extendedae_plus.tooltip.master_mode": "Mode: %s",
"extendedae_plus.tooltip.locked": "Locked: %s", "extendedae_plus.tooltip.locked": "Locked: %s",
@ -108,6 +109,10 @@
"item.extendedae_plus.channel_card.owner.player": "Owner: Player %s", "item.extendedae_plus.channel_card.owner.player": "Owner: Player %s",
"item.extendedae_plus.channel_card.owner.bound": "Bound to: %s", "item.extendedae_plus.channel_card.owner.bound": "Bound to: %s",
"item.extendedae_plus.channel_card.owner.cleared": "Owner binding cleared", "item.extendedae_plus.channel_card.owner.cleared": "Owner binding cleared",
"extendedae_plus.tooltip.owner": "Owner: %s",
"extendedae_plus.tooltip.owner.unset": "Owner: Unset",
"group.pattern_provider.name": "Pattern Provider", "group.pattern_provider.name": "Pattern Provider",
"group.entity_ticker.name": "Entity Accelerator", "group.entity_ticker.name": "Entity Accelerator",
"group.storage.name": "StorageBus" "group.storage.name": "StorageBus"

View File

@ -74,6 +74,7 @@
"config.jade.plugin_extendedae_plus.wt_locked": "显示锁定状态", "config.jade.plugin_extendedae_plus.wt_locked": "显示锁定状态",
"config.jade.plugin_extendedae_plus.wt_network_usable": "显示网络在线状态", "config.jade.plugin_extendedae_plus.wt_network_usable": "显示网络在线状态",
"config.jade.plugin_extendedae_plus.wt_channels": "显示频道使用情况", "config.jade.plugin_extendedae_plus.wt_channels": "显示频道使用情况",
"config.jade.plugin_extendedae_plus.wt_owner": "显示所有者信息",
"extendedae_plus.tooltip.frequency": "频率: %d", "extendedae_plus.tooltip.frequency": "频率: %d",
"extendedae_plus.tooltip.master_mode": "模式: %s", "extendedae_plus.tooltip.master_mode": "模式: %s",
"extendedae_plus.tooltip.locked": "锁定状态: %s", "extendedae_plus.tooltip.locked": "锁定状态: %s",
@ -109,6 +110,10 @@
"item.extendedae_plus.channel_card.owner.player": "所有者:玩家 %s", "item.extendedae_plus.channel_card.owner.player": "所有者:玩家 %s",
"item.extendedae_plus.channel_card.owner.bound": "已绑定至:%s", "item.extendedae_plus.channel_card.owner.bound": "已绑定至:%s",
"item.extendedae_plus.channel_card.owner.cleared": "已清除所有者绑定", "item.extendedae_plus.channel_card.owner.cleared": "已清除所有者绑定",
"extendedae_plus.tooltip.owner": "所有者: %s",
"extendedae_plus.tooltip.owner.unset": "所有者: 未设置",
"group.pattern_provider.name": "样板供应器", "group.pattern_provider.name": "样板供应器",
"group.entity_ticker.name": "实体加速器", "group.entity_ticker.name": "实体加速器",
"group.storage.name": "存储总线" "group.storage.name": "存储总线"