基本实现

This commit is contained in:
GaLicn 2025-12-11 22:03:49 +08:00
parent 044a0c39f7
commit f6a86ad4ac
10 changed files with 99 additions and 46 deletions

View File

@ -56,7 +56,9 @@ public class LabeledWirelessTransceiverScreen extends AbstractContainerScreen<La
private int selectedIndex = -1; private int selectedIndex = -1;
private String lastSelectedLabel = ""; private String lastSelectedLabel = "";
private String currentLabel = ""; private String currentLabel = "";
private long currentChannel = 0L; private String currentOwner = "";
private int usedChannels = 0;
private int maxChannels = 0;
public LabeledWirelessTransceiverScreen(LabeledWirelessTransceiverMenu menu, Inventory inv, Component title) { public LabeledWirelessTransceiverScreen(LabeledWirelessTransceiverMenu menu, Inventory inv, Component title) {
super(menu, inv, title); super(menu, inv, title);
@ -202,9 +204,13 @@ public class LabeledWirelessTransceiverScreen extends AbstractContainerScreen<La
int infoX = this.leftPos + 124; int infoX = this.leftPos + 124;
int infoY = this.topPos + 36; int infoY = this.topPos + 36;
String labelLine = Component.translatable("gui.extendedae_plus.labeled_wireless.current_label").getString() + ": " + (currentLabel == null || currentLabel.isEmpty() ? "-" : currentLabel); String labelLine = Component.translatable("gui.extendedae_plus.labeled_wireless.current_label").getString() + ": " + (currentLabel == null || currentLabel.isEmpty() ? "-" : currentLabel);
String channelLine = Component.translatable("gui.extendedae_plus.labeled_wireless.current_channel").getString() + ": " + currentChannel; 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);
Component channelComp = maxChannels <= 0
? Component.translatable("extendedae_plus.jade.channels", usedChannels)
: Component.translatable("extendedae_plus.jade.channels_of", usedChannels, maxChannels);
gfx.drawString(this.font, labelLine, infoX, infoY, 0x404040, false); gfx.drawString(this.font, labelLine, infoX, infoY, 0x404040, false);
gfx.drawString(this.font, channelLine, infoX, infoY + 12, 0x404040, false); gfx.drawString(this.font, ownerLine, infoX, infoY + 12, 0x404040, false);
gfx.drawString(this.font, channelComp, infoX, infoY + 24, 0x404040, false);
} }
private void renderScrollBar(GuiGraphics gfx) { private void renderScrollBar(GuiGraphics gfx) {
@ -308,14 +314,16 @@ public class LabeledWirelessTransceiverScreen extends AbstractContainerScreen<La
return ""; return "";
} }
public void updateList(List<LabelNetworkRegistry.LabelNetworkSnapshot> list, String currentLabel, long currentChannel) { public void updateList(List<LabelNetworkRegistry.LabelNetworkSnapshot> list, String currentLabel, String ownerName, int usedChannels, int maxChannels) {
String prevSelected = getSelectedLabel(); String prevSelected = getSelectedLabel();
this.entries.clear(); this.entries.clear();
for (LabelNetworkRegistry.LabelNetworkSnapshot s : list) { for (LabelNetworkRegistry.LabelNetworkSnapshot s : list) {
this.entries.add(new LabelEntry(s.label(), s.channel())); this.entries.add(new LabelEntry(s.label(), s.channel()));
} }
this.currentLabel = currentLabel == null ? "" : currentLabel; this.currentLabel = currentLabel == null ? "" : currentLabel;
this.currentChannel = currentChannel; this.currentOwner = ownerName == null ? "" : ownerName;
this.usedChannels = usedChannels;
this.maxChannels = maxChannels;
if (prevSelected != null && !prevSelected.isEmpty()) { if (prevSelected != null && !prevSelected.isEmpty()) {
this.lastSelectedLabel = prevSelected; this.lastSelectedLabel = prevSelected;
} else if (this.currentLabel != null && !this.currentLabel.isEmpty()) { } else if (this.currentLabel != null && !this.currentLabel.isEmpty()) {

View File

@ -79,18 +79,6 @@ public class LabeledWirelessTransceiverBlock extends Block implements EntityBloc
super.onRemove(state, level, pos, newState, isMoving); super.onRemove(state, level, pos, newState, isMoving);
} }
@Override
public float getDestroyProgress(BlockState state, Player player, BlockGetter level, BlockPos pos) {
// 与旧收发器保持一致锁定时降低挖掘速度
float baseProgress = super.getDestroyProgress(state, player, level, pos);
if (level.getBlockEntity(pos) instanceof LabeledWirelessTransceiverBlockEntity te) {
if (te.isLocked()) {
return baseProgress * 0.1f;
}
}
return baseProgress;
}
@Override @Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> type) { public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> type) {
if (level.isClientSide) return null; if (level.isClientSide) return null;

View File

@ -44,7 +44,6 @@ public class LabeledWirelessTransceiverBlockEntity extends AEBaseBlockEntity imp
private long frequency = 0L; private long frequency = 0L;
@Nullable @Nullable
private String labelForDisplay; private String labelForDisplay;
private boolean locked = false;
private boolean beingRemoved = false; private boolean beingRemoved = false;
@Nullable @Nullable
@ -131,16 +130,6 @@ public class LabeledWirelessTransceiverBlockEntity extends AEBaseBlockEntity imp
return labelForDisplay; return labelForDisplay;
} }
public boolean isLocked() {
return locked;
}
public void setLocked(boolean locked) {
if (this.locked == locked) return;
this.locked = locked;
setChanged();
}
/** /**
* 应用/切换标签空或非法标签将清空并断开 * 应用/切换标签空或非法标签将清空并断开
*/ */
@ -290,7 +279,6 @@ public class LabeledWirelessTransceiverBlockEntity extends AEBaseBlockEntity imp
public void saveAdditional(CompoundTag tag) { public void saveAdditional(CompoundTag tag) {
super.saveAdditional(tag); super.saveAdditional(tag);
tag.putLong("frequency", frequency); tag.putLong("frequency", frequency);
tag.putBoolean("locked", locked);
if (labelForDisplay != null) { if (labelForDisplay != null) {
tag.putString("label", labelForDisplay); tag.putString("label", labelForDisplay);
} }
@ -309,7 +297,6 @@ public class LabeledWirelessTransceiverBlockEntity extends AEBaseBlockEntity imp
public void loadTag(CompoundTag tag) { public void loadTag(CompoundTag tag) {
super.loadTag(tag); super.loadTag(tag);
this.frequency = tag.getLong("frequency"); this.frequency = tag.getLong("frequency");
this.locked = tag.getBoolean("locked");
if (tag.contains("label")) { if (tag.contains("label")) {
this.labelForDisplay = tag.getString("label"); this.labelForDisplay = tag.getString("label");
} else { } else {

View File

@ -12,10 +12,30 @@ public enum LabeledWirelessTransceiverComponents implements IBlockComponentProvi
@Override @Override
protected void add(BlockAccessor accessor, ITooltip tooltip, IPluginConfig config, net.minecraft.nbt.CompoundTag data) { protected void add(BlockAccessor accessor, ITooltip tooltip, IPluginConfig config, net.minecraft.nbt.CompoundTag data) {
String label = data.contains("label") ? data.getString("label") : ""; String label = data.contains("label") ? data.getString("label") : "";
long channel = data.contains("channel") ? data.getLong("channel") : 0L;
tooltip.add(Component.translatable("extendedae_plus.jade.label", label.isEmpty() ? "-" : label)); tooltip.add(Component.translatable("extendedae_plus.jade.label", label.isEmpty() ? "-" : label));
tooltip.add(Component.translatable("extendedae_plus.jade.frequency", channel));
// 所有者
if (data.contains("ownerName")) {
tooltip.add(Component.translatable("extendedae_plus.jade.owner", data.getString("ownerName")));
} else if (data.contains("placerId")) {
java.util.UUID placerId = data.getUUID("placerId");
tooltip.add(Component.translatable("extendedae_plus.jade.owner", placerId.toString().substring(0, 8) + "..."));
} else {
tooltip.add(Component.translatable("extendedae_plus.jade.owner.public"));
}
// 频道占用
if (data.contains("usedChannels") && data.contains("maxChannels")) {
int used = data.getInt("usedChannels");
int max = data.getInt("maxChannels");
if (max <= 0) {
tooltip.add(Component.translatable("extendedae_plus.jade.channels", used));
} else {
tooltip.add(Component.translatable("extendedae_plus.jade.channels_of", used, max));
}
}
// 网络在线
if (data.contains("networkUsable")) { if (data.contains("networkUsable")) {
boolean online = data.getBoolean("networkUsable"); boolean online = data.getBoolean("networkUsable");
tooltip.add(Component.translatable(online ? "extendedae_plus.jade.online" : "extendedae_plus.jade.offline")); tooltip.add(Component.translatable(online ? "extendedae_plus.jade.online" : "extendedae_plus.jade.offline"));

View File

@ -3,14 +3,14 @@ package com.extendedae_plus.integration.jade;
import appeng.api.networking.IGrid; import appeng.api.networking.IGrid;
import appeng.api.networking.IGridNode; import appeng.api.networking.IGridNode;
import com.extendedae_plus.content.wireless.LabeledWirelessTransceiverBlockEntity; import com.extendedae_plus.content.wireless.LabeledWirelessTransceiverBlockEntity;
import com.extendedae_plus.util.wireless.WirelessTeamUtil;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
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;
/** /**
* 标签无线收发器服务端数据同步 * 标签无线收发器服务端数据同步无主从
* 仅包含标签名频道网络在线状态
*/ */
public enum LabeledWirelessTransceiverProvider implements IServerDataProvider<BlockAccessor> { public enum LabeledWirelessTransceiverProvider implements IServerDataProvider<BlockAccessor> {
INSTANCE; INSTANCE;
@ -29,11 +29,31 @@ public enum LabeledWirelessTransceiverProvider implements IServerDataProvider<Bl
if (label != null) { if (label != null) {
data.putString("label", label); data.putString("label", label);
} }
data.putLong("channel", be.getFrequency()); // 所有者
var placerId = be.getPlacerId();
if (placerId != null && be.getServerLevel() != null) {
data.putUUID("placerId", placerId);
data.putString("ownerName", WirelessTeamUtil.getNetworkOwnerName(be.getServerLevel(), placerId).getString());
}
IGridNode node = be.getGridNode(); IGridNode node = be.getGridNode();
IGrid grid = node == null ? null : node.getGrid(); IGrid grid = node == null ? null : node.getGrid();
boolean networkUsable = false; boolean networkUsable = false;
int usedChannels = 0;
int maxChannels = 0;
if (node != null && node.isActive()) {
for (var connection : node.getConnections()) {
usedChannels = Math.max(connection.getUsedChannels(), usedChannels);
}
if (node instanceof appeng.me.GridNode gridNode) {
var channelMode = gridNode.getGrid().getPathingService().getChannelMode();
if (channelMode == appeng.api.networking.pathing.ChannelMode.INFINITE) {
maxChannels = -1;
} else {
maxChannels = gridNode.getMaxChannels();
}
}
}
if (grid != null) { if (grid != null) {
try { try {
networkUsable = grid.getEnergyService().isNetworkPowered(); networkUsable = grid.getEnergyService().isNetworkPowered();
@ -41,6 +61,8 @@ public enum LabeledWirelessTransceiverProvider implements IServerDataProvider<Bl
networkUsable = false; networkUsable = false;
} }
} }
data.putInt("usedChannels", usedChannels);
data.putInt("maxChannels", maxChannels);
data.putBoolean("networkUsable", networkUsable); data.putBoolean("networkUsable", networkUsable);
} }
} }

View File

@ -2,6 +2,7 @@ package com.extendedae_plus.network;
import com.extendedae_plus.ae.wireless.LabelNetworkRegistry; import com.extendedae_plus.ae.wireless.LabelNetworkRegistry;
import com.extendedae_plus.content.wireless.LabeledWirelessTransceiverBlockEntity; import com.extendedae_plus.content.wireless.LabeledWirelessTransceiverBlockEntity;
import com.extendedae_plus.util.wireless.WirelessTeamUtil;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
@ -39,8 +40,27 @@ public class LabelNetworkListC2SPacket {
var list = LabelNetworkRegistry.get(level).listNetworks(level, te.getPlacerId()); var list = LabelNetworkRegistry.get(level).listNetworks(level, te.getPlacerId());
String currentLabel = te.getLabelForDisplay(); String currentLabel = te.getLabelForDisplay();
long currentChannel = te.getFrequency(); String ownerName = te.getPlacerId() != null ? WirelessTeamUtil.getNetworkOwnerName(level, te.getPlacerId()).getString() : "";
LabelNetworkListS2CPacket rsp = new LabelNetworkListS2CPacket(pkt.pos, list, currentLabel, currentChannel);
// 计算频道占用信息 Jade 显示一致
int usedChannels = 0;
int maxChannels = 0;
var node = te.getGridNode();
if (node != null && node.isActive()) {
for (var connection : node.getConnections()) {
usedChannels = Math.max(connection.getUsedChannels(), usedChannels);
}
if (node instanceof appeng.me.GridNode gridNode) {
var channelMode = gridNode.getGrid().getPathingService().getChannelMode();
if (channelMode == appeng.api.networking.pathing.ChannelMode.INFINITE) {
maxChannels = -1;
} else {
maxChannels = gridNode.getMaxChannels();
}
}
}
LabelNetworkListS2CPacket rsp = new LabelNetworkListS2CPacket(pkt.pos, list, currentLabel, ownerName, usedChannels, maxChannels);
com.extendedae_plus.init.ModNetwork.CHANNEL.send(PacketDistributor.PLAYER.with(() -> player), rsp); com.extendedae_plus.init.ModNetwork.CHANNEL.send(PacketDistributor.PLAYER.with(() -> player), rsp);
}); });
ctx.get().setPacketHandled(true); ctx.get().setPacketHandled(true);

View File

@ -20,19 +20,25 @@ public class LabelNetworkListS2CPacket {
private final BlockPos pos; private final BlockPos pos;
private final List<LabelNetworkRegistry.LabelNetworkSnapshot> list; private final List<LabelNetworkRegistry.LabelNetworkSnapshot> list;
private final String currentLabel; private final String currentLabel;
private final long currentChannel; private final String ownerName;
private final int usedChannels;
private final int maxChannels;
public LabelNetworkListS2CPacket(BlockPos pos, List<LabelNetworkRegistry.LabelNetworkSnapshot> list, String currentLabel, long currentChannel) { public LabelNetworkListS2CPacket(BlockPos pos, List<LabelNetworkRegistry.LabelNetworkSnapshot> list, String currentLabel, String ownerName, int usedChannels, int maxChannels) {
this.pos = pos; this.pos = pos;
this.list = list; this.list = list;
this.currentLabel = currentLabel; this.currentLabel = currentLabel;
this.currentChannel = currentChannel; this.ownerName = ownerName;
this.usedChannels = usedChannels;
this.maxChannels = maxChannels;
} }
public static void encode(LabelNetworkListS2CPacket pkt, FriendlyByteBuf buf) { public static void encode(LabelNetworkListS2CPacket pkt, FriendlyByteBuf buf) {
buf.writeBlockPos(pkt.pos); buf.writeBlockPos(pkt.pos);
buf.writeUtf(pkt.currentLabel == null ? "" : pkt.currentLabel, 128); buf.writeUtf(pkt.currentLabel == null ? "" : pkt.currentLabel, 128);
buf.writeLong(pkt.currentChannel); buf.writeUtf(pkt.ownerName == null ? "" : pkt.ownerName, 128);
buf.writeVarInt(pkt.usedChannels);
buf.writeVarInt(pkt.maxChannels);
buf.writeVarInt(pkt.list.size()); buf.writeVarInt(pkt.list.size());
for (LabelNetworkRegistry.LabelNetworkSnapshot s : pkt.list) { for (LabelNetworkRegistry.LabelNetworkSnapshot s : pkt.list) {
buf.writeUtf(s.label(), 128); buf.writeUtf(s.label(), 128);
@ -43,7 +49,9 @@ public class LabelNetworkListS2CPacket {
public static LabelNetworkListS2CPacket decode(FriendlyByteBuf buf) { public static LabelNetworkListS2CPacket decode(FriendlyByteBuf buf) {
BlockPos pos = buf.readBlockPos(); BlockPos pos = buf.readBlockPos();
String curLabel = buf.readUtf(128); String curLabel = buf.readUtf(128);
long curChannel = buf.readLong(); String ownerName = buf.readUtf(128);
int usedChannels = buf.readVarInt();
int maxChannels = buf.readVarInt();
int size = buf.readVarInt(); int size = buf.readVarInt();
List<LabelNetworkRegistry.LabelNetworkSnapshot> list = new ArrayList<>(size); List<LabelNetworkRegistry.LabelNetworkSnapshot> list = new ArrayList<>(size);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
@ -51,7 +59,7 @@ public class LabelNetworkListS2CPacket {
long channel = buf.readLong(); long channel = buf.readLong();
list.add(new LabelNetworkRegistry.LabelNetworkSnapshot(label, channel)); list.add(new LabelNetworkRegistry.LabelNetworkSnapshot(label, channel));
} }
return new LabelNetworkListS2CPacket(pos, list, curLabel, curChannel); return new LabelNetworkListS2CPacket(pos, list, curLabel, ownerName, usedChannels, maxChannels);
} }
public static void handle(LabelNetworkListS2CPacket pkt, Supplier<NetworkEvent.Context> ctx) { public static void handle(LabelNetworkListS2CPacket pkt, Supplier<NetworkEvent.Context> ctx) {
@ -63,7 +71,7 @@ public class LabelNetworkListS2CPacket {
private static void handleClient(LabelNetworkListS2CPacket pkt) { private static void handleClient(LabelNetworkListS2CPacket pkt) {
Minecraft mc = Minecraft.getInstance(); Minecraft mc = Minecraft.getInstance();
if (mc.screen instanceof LabeledWirelessTransceiverScreen screen && screen.isFor(pkt.pos)) { if (mc.screen instanceof LabeledWirelessTransceiverScreen screen && screen.isFor(pkt.pos)) {
screen.updateList(pkt.list, pkt.currentLabel, pkt.currentChannel); screen.updateList(pkt.list, pkt.currentLabel, pkt.ownerName, pkt.usedChannels, pkt.maxChannels);
} }
} }
} }

View File

@ -104,7 +104,7 @@
"gui.extendedae_plus.labeled_wireless.button.set": "Set Current", "gui.extendedae_plus.labeled_wireless.button.set": "Set Current",
"gui.extendedae_plus.labeled_wireless.button.refresh": "Disconnect", "gui.extendedae_plus.labeled_wireless.button.refresh": "Disconnect",
"gui.extendedae_plus.labeled_wireless.current_label": "Current Label", "gui.extendedae_plus.labeled_wireless.current_label": "Current Label",
"gui.extendedae_plus.labeled_wireless.current_channel": "Current Channel", "gui.extendedae_plus.labeled_wireless.current_owner": "Owner",
"extendedae_plus.screen.reload_mapping": "Reload Mapping", "extendedae_plus.screen.reload_mapping": "Reload Mapping",
"extendedae_plus.screen.reload_mapping_success": "Overloading mapping successful", "extendedae_plus.screen.reload_mapping_success": "Overloading mapping successful",

View File

@ -103,7 +103,7 @@
"gui.extendedae_plus.labeled_wireless.button.set": "设为当前", "gui.extendedae_plus.labeled_wireless.button.set": "设为当前",
"gui.extendedae_plus.labeled_wireless.button.refresh": "断开连接", "gui.extendedae_plus.labeled_wireless.button.refresh": "断开连接",
"gui.extendedae_plus.labeled_wireless.current_label": "当前标签", "gui.extendedae_plus.labeled_wireless.current_label": "当前标签",
"gui.extendedae_plus.labeled_wireless.current_channel": "当前频道", "gui.extendedae_plus.labeled_wireless.current_owner": "所有者",
"extendedae_plus.screen.reload_mapping": "重载映射", "extendedae_plus.screen.reload_mapping": "重载映射",
"extendedae_plus.screen.reload_mapping_success": "重载映射成功", "extendedae_plus.screen.reload_mapping_success": "重载映射成功",

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB