添加在线数信息展示行
This commit is contained in:
parent
2a865f74d5
commit
63a2f7b1b9
|
|
@ -103,7 +103,7 @@ public class LabelNetworkRegistry extends SavedData {
|
|||
}
|
||||
|
||||
/**
|
||||
* 注销端点;不再自动删除网络,网络的移除需显式调用 removeNetwork。
|
||||
* 注销端点;不自动删除网络,网络的移除需显式调用 removeNetwork。
|
||||
*/
|
||||
public synchronized void unregister(IWirelessEndpoint endpoint) {
|
||||
ServerLevel level = endpoint.getServerLevel();
|
||||
|
|
@ -256,8 +256,8 @@ public class LabelNetworkRegistry extends SavedData {
|
|||
this.virtualHost = new VirtualLabelNodeHost();
|
||||
this.managedNode = GridHelper.createManagedNode(virtualHost, NodeListener.INSTANCE);
|
||||
this.virtualHost.setManagedNode(this.managedNode);
|
||||
// 虚拟节点不占用频道
|
||||
this.managedNode.setFlags();
|
||||
// 虚拟节点不占用频道,且提供致密(32)频道能力
|
||||
this.managedNode.setFlags(GridFlags.DENSE_CAPACITY);
|
||||
this.managedNode.setIdlePowerUsage(0.0);
|
||||
this.managedNode.setInWorldNode(false);
|
||||
this.managedNode.setVisualRepresentation(com.extendedae_plus.init.ModItems.LABELED_WIRELESS_TRANSCEIVER.get().getDefaultInstance());
|
||||
|
|
@ -288,6 +288,10 @@ public class LabelNetworkRegistry extends SavedData {
|
|||
endpoints.add(EndpointRef.load(list.getCompound(i)));
|
||||
}
|
||||
}
|
||||
|
||||
public int endpointCount() {
|
||||
return endpoints.size();
|
||||
}
|
||||
}
|
||||
|
||||
public record EndpointRef(@Nullable ResourceKey<Level> dim, BlockPos pos) {
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ public class LabeledWirelessTransceiverScreen extends AbstractContainerScreen<La
|
|||
private String lastSelectedLabel = "";
|
||||
private String currentLabel = "";
|
||||
private String currentOwner = "";
|
||||
private int onlineCount = 0;
|
||||
private int usedChannels = 0;
|
||||
private int maxChannels = 0;
|
||||
|
||||
|
|
@ -215,12 +216,14 @@ public class LabeledWirelessTransceiverScreen extends AbstractContainerScreen<La
|
|||
float infoScale = getInfoScale();
|
||||
String labelLine = Component.translatable("gui.extendedae_plus.labeled_wireless.current_label").getString() + ": " + (currentLabel == null || currentLabel.isEmpty() ? "-" : currentLabel);
|
||||
String ownerLine = Component.translatable("gui.extendedae_plus.labeled_wireless.current_owner").getString() + ": " + (currentOwner == null || currentOwner.isEmpty() ? Component.translatable("extendedae_plus.jade.owner.public").getString() : currentOwner);
|
||||
String onlineLine = Component.translatable("gui.extendedae_plus.labeled_wireless.online_count").getString() + ": " + onlineCount;
|
||||
Component channelComp = maxChannels <= 0
|
||||
? Component.translatable("extendedae_plus.jade.channels", usedChannels)
|
||||
: Component.translatable("extendedae_plus.jade.channels_of", usedChannels, maxChannels);
|
||||
drawInfoLine(gfx, labelLine, infoX, infoY, infoScale);
|
||||
drawInfoLine(gfx, ownerLine, infoX, infoY + 12, infoScale);
|
||||
drawInfoLine(gfx, channelComp.getString(), infoX, infoY + 24, infoScale);
|
||||
drawInfoLine(gfx, onlineLine, infoX, infoY + 24, infoScale);
|
||||
drawInfoLine(gfx, channelComp.getString(), infoX, infoY + 36, infoScale);
|
||||
}
|
||||
|
||||
private void renderScrollBar(GuiGraphics gfx) {
|
||||
|
|
@ -324,7 +327,7 @@ public class LabeledWirelessTransceiverScreen extends AbstractContainerScreen<La
|
|||
return "";
|
||||
}
|
||||
|
||||
public void updateList(List<LabelNetworkRegistry.LabelNetworkSnapshot> list, String currentLabel, String ownerName, int usedChannels, int maxChannels) {
|
||||
public void updateList(List<LabelNetworkRegistry.LabelNetworkSnapshot> list, String currentLabel, String ownerName, int usedChannels, int maxChannels, int onlineCount) {
|
||||
String prevSelected = getSelectedLabel();
|
||||
this.entries.clear();
|
||||
for (LabelNetworkRegistry.LabelNetworkSnapshot s : list) {
|
||||
|
|
@ -332,8 +335,10 @@ public class LabeledWirelessTransceiverScreen extends AbstractContainerScreen<La
|
|||
}
|
||||
this.currentLabel = currentLabel == null ? "" : currentLabel;
|
||||
this.currentOwner = ownerName == null ? "" : ownerName;
|
||||
this.onlineCount = onlineCount;
|
||||
this.usedChannels = usedChannels;
|
||||
this.maxChannels = maxChannels;
|
||||
|
||||
if (prevSelected != null && !prevSelected.isEmpty()) {
|
||||
this.lastSelectedLabel = prevSelected;
|
||||
} else if (this.currentLabel != null && !this.currentLabel.isEmpty()) {
|
||||
|
|
|
|||
|
|
@ -42,6 +42,14 @@ public class LabelNetworkListC2SPacket {
|
|||
String currentLabel = te.getLabelForDisplay();
|
||||
String ownerName = te.getPlacerId() != null ? WirelessTeamUtil.getNetworkOwnerName(level, te.getPlacerId()).getString() : "";
|
||||
|
||||
int onlineCount = 0;
|
||||
if (currentLabel != null && !currentLabel.isEmpty()) {
|
||||
var network = LabelNetworkRegistry.get(level).getNetwork(level, currentLabel, te.getPlacerId());
|
||||
if (network != null) {
|
||||
onlineCount = network.endpointCount();
|
||||
}
|
||||
}
|
||||
|
||||
// 计算频道占用信息(与 Jade 显示一致)
|
||||
int usedChannels = 0;
|
||||
int maxChannels = 0;
|
||||
|
|
@ -60,7 +68,7 @@ public class LabelNetworkListC2SPacket {
|
|||
}
|
||||
}
|
||||
|
||||
LabelNetworkListS2CPacket rsp = new LabelNetworkListS2CPacket(pkt.pos, list, currentLabel, ownerName, usedChannels, maxChannels);
|
||||
LabelNetworkListS2CPacket rsp = new LabelNetworkListS2CPacket(pkt.pos, list, currentLabel, ownerName, usedChannels, maxChannels, onlineCount);
|
||||
com.extendedae_plus.init.ModNetwork.CHANNEL.send(PacketDistributor.PLAYER.with(() -> player), rsp);
|
||||
});
|
||||
ctx.get().setPacketHandled(true);
|
||||
|
|
|
|||
|
|
@ -23,14 +23,16 @@ public class LabelNetworkListS2CPacket {
|
|||
private final String ownerName;
|
||||
private final int usedChannels;
|
||||
private final int maxChannels;
|
||||
private final int onlineCount;
|
||||
|
||||
public LabelNetworkListS2CPacket(BlockPos pos, List<LabelNetworkRegistry.LabelNetworkSnapshot> list, String currentLabel, String ownerName, int usedChannels, int maxChannels) {
|
||||
public LabelNetworkListS2CPacket(BlockPos pos, List<LabelNetworkRegistry.LabelNetworkSnapshot> list, String currentLabel, String ownerName, int usedChannels, int maxChannels, int onlineCount) {
|
||||
this.pos = pos;
|
||||
this.list = list;
|
||||
this.currentLabel = currentLabel;
|
||||
this.ownerName = ownerName;
|
||||
this.usedChannels = usedChannels;
|
||||
this.maxChannels = maxChannels;
|
||||
this.onlineCount = onlineCount;
|
||||
}
|
||||
|
||||
public static void encode(LabelNetworkListS2CPacket pkt, FriendlyByteBuf buf) {
|
||||
|
|
@ -39,6 +41,7 @@ public class LabelNetworkListS2CPacket {
|
|||
buf.writeUtf(pkt.ownerName == null ? "" : pkt.ownerName, 128);
|
||||
buf.writeVarInt(pkt.usedChannels);
|
||||
buf.writeVarInt(pkt.maxChannels);
|
||||
buf.writeVarInt(pkt.onlineCount);
|
||||
buf.writeVarInt(pkt.list.size());
|
||||
for (LabelNetworkRegistry.LabelNetworkSnapshot s : pkt.list) {
|
||||
buf.writeUtf(s.label(), 128);
|
||||
|
|
@ -52,6 +55,7 @@ public class LabelNetworkListS2CPacket {
|
|||
String ownerName = buf.readUtf(128);
|
||||
int usedChannels = buf.readVarInt();
|
||||
int maxChannels = buf.readVarInt();
|
||||
int onlineCount = buf.readVarInt();
|
||||
int size = buf.readVarInt();
|
||||
List<LabelNetworkRegistry.LabelNetworkSnapshot> list = new ArrayList<>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
|
|
@ -59,7 +63,7 @@ public class LabelNetworkListS2CPacket {
|
|||
long channel = buf.readLong();
|
||||
list.add(new LabelNetworkRegistry.LabelNetworkSnapshot(label, channel));
|
||||
}
|
||||
return new LabelNetworkListS2CPacket(pos, list, curLabel, ownerName, usedChannels, maxChannels);
|
||||
return new LabelNetworkListS2CPacket(pos, list, curLabel, ownerName, usedChannels, maxChannels, onlineCount);
|
||||
}
|
||||
|
||||
public static void handle(LabelNetworkListS2CPacket pkt, Supplier<NetworkEvent.Context> ctx) {
|
||||
|
|
@ -71,7 +75,7 @@ public class LabelNetworkListS2CPacket {
|
|||
private static void handleClient(LabelNetworkListS2CPacket pkt) {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (mc.screen instanceof LabeledWirelessTransceiverScreen screen && screen.isFor(pkt.pos)) {
|
||||
screen.updateList(pkt.list, pkt.currentLabel, pkt.ownerName, pkt.usedChannels, pkt.maxChannels);
|
||||
screen.updateList(pkt.list, pkt.currentLabel, pkt.ownerName, pkt.usedChannels, pkt.maxChannels, pkt.onlineCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -105,6 +105,7 @@
|
|||
"gui.extendedae_plus.labeled_wireless.button.refresh": "Disconnect",
|
||||
"gui.extendedae_plus.labeled_wireless.current_label": "Current Label",
|
||||
"gui.extendedae_plus.labeled_wireless.current_owner": "Owner",
|
||||
"gui.extendedae_plus.labeled_wireless.online_count": "Online",
|
||||
|
||||
"extendedae_plus.screen.reload_mapping": "Reload Mapping",
|
||||
"extendedae_plus.screen.reload_mapping_success": "Overloading mapping successful",
|
||||
|
|
|
|||
|
|
@ -104,6 +104,7 @@
|
|||
"gui.extendedae_plus.labeled_wireless.button.refresh": "断开连接",
|
||||
"gui.extendedae_plus.labeled_wireless.current_label": "当前标签",
|
||||
"gui.extendedae_plus.labeled_wireless.current_owner": "所有者",
|
||||
"gui.extendedae_plus.labeled_wireless.online_count": "在线数",
|
||||
|
||||
"extendedae_plus.screen.reload_mapping": "重载映射",
|
||||
"extendedae_plus.screen.reload_mapping_success": "重载映射成功",
|
||||
|
|
|
|||
Binary file not shown.
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.3 KiB |
Loading…
Reference in New Issue
Block a user