feature:添加 Jade 支持(无线收发器信息: 频道/主从模式/主节点位置/锁定状态/AE网络状态及可配置开关)

This commit is contained in:
C-H716 2025-08-25 19:47:05 +08:00
parent 4ca02b923c
commit 4e03d4dc4f
5 changed files with 195 additions and 2 deletions

View File

@ -0,0 +1,26 @@
package com.extendedae_plus.integration.jade;
import com.extendedae_plus.content.wireless.WirelessTransceiverBlock;
import com.extendedae_plus.content.wireless.WirelessTransceiverBlockEntity;
import snownee.jade.api.IWailaClientRegistration;
import snownee.jade.api.IWailaCommonRegistration;
import snownee.jade.api.IWailaPlugin;
import snownee.jade.api.WailaPlugin;
@WailaPlugin("extendedae_plus") // 你的 mod ID
public class WirelessTransceiverJadePlugin implements IWailaPlugin {
@Override
public void register(IWailaCommonRegistration registration) {
// 注册服务端数据提供者用于同步数据
registration.registerBlockDataProvider(WirelessTransceiverProvider.INSTANCE, WirelessTransceiverBlockEntity.class);
}
@Override
public void registerClient(IWailaClientRegistration registration) {
// 遍历组件常量逐一注册
for (var component : WirelessTransceiverJadePluginComponents.values()) {
registration.registerBlockComponent(component, WirelessTransceiverBlock.class);
}
}
}

View File

@ -0,0 +1,87 @@
package com.extendedae_plus.integration.jade;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import snownee.jade.api.BlockAccessor;
import snownee.jade.api.IBlockComponentProvider;
import snownee.jade.api.ITooltip;
import snownee.jade.api.config.IPluginConfig;
/**
* 单文件聚合的 Jade 组件提供者包含四个子组件常量分别对应四个独立的开关/UID
*/
public enum WirelessTransceiverJadePluginComponents implements IBlockComponentProvider {
FREQUENCY("wt_frequency") {
@Override
protected void add(BlockAccessor accessor, ITooltip tooltip, IPluginConfig config, CompoundTag data) {
if (data.contains("frequency")) {
long frequency = data.getLong("frequency");
tooltip.add(Component.translatable("extendedae_plus.tooltip.frequency", frequency));
}
}
},
MODE("wt_master_mode") {
@Override
protected void add(BlockAccessor accessor, ITooltip tooltip, IPluginConfig config, CompoundTag data) {
if (data.contains("masterMode")) {
boolean masterMode = data.getBoolean("masterMode");
tooltip.add(Component.translatable("extendedae_plus.tooltip.master_mode", masterMode ? "主模式" : "从模式"));
}
}
},
MASTER_LOCATION("wt_master_location") {
@Override
protected void add(BlockAccessor accessor, ITooltip tooltip, IPluginConfig config, CompoundTag data) {
if (data.contains("masterMode") && !data.getBoolean("masterMode") && data.contains("masterPos")) {
BlockPos pos = BlockPos.of(data.getLong("masterPos"));
String dim = data.contains("masterDim") ? data.getString("masterDim") : "";
tooltip.add(Component.literal("主节点位置: (" + pos.getX() + ", " + pos.getY() + ", " + pos.getZ() + ")"));
if (!dim.isEmpty()) {
tooltip.add(Component.literal("维度: " + dim));
}
}
}
},
LOCKED("wt_locked") {
@Override
protected void add(BlockAccessor accessor, ITooltip tooltip, IPluginConfig config, CompoundTag data) {
if (data.contains("locked")) {
boolean locked = data.getBoolean("locked");
tooltip.add(Component.translatable("extendedae_plus.tooltip.locked", locked ? "已锁定" : "未锁定"));
}
}
},
NETWORK_USABLE("wt_network_usable") {
@Override
protected void add(BlockAccessor accessor, ITooltip tooltip, IPluginConfig config, CompoundTag data) {
if (data.contains("networkUsable")) {
boolean usable = data.getBoolean("networkUsable");
tooltip.add(Component.literal((usable ? "设备在线" : "设备离线")));
}
}
};
private final ResourceLocation uid;
WirelessTransceiverJadePluginComponents(String path) {
this.uid = new ResourceLocation("extendedae_plus", path);
}
@Override
public ResourceLocation getUid() {
return uid;
}
@Override
public final void appendTooltip(ITooltip tooltip, BlockAccessor accessor, IPluginConfig config) {
CompoundTag data = accessor.getServerData();
if (data == null) return;
add(accessor, tooltip, config, data);
}
protected abstract void add(BlockAccessor accessor, ITooltip tooltip, IPluginConfig config, CompoundTag data);
}

View File

@ -0,0 +1,60 @@
package com.extendedae_plus.integration.jade;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridNode;
import com.extendedae_plus.content.wireless.WirelessTransceiverBlockEntity;
import com.extendedae_plus.wireless.IWirelessEndpoint;
import com.extendedae_plus.wireless.WirelessMasterRegistry;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import snownee.jade.api.BlockAccessor;
import snownee.jade.api.IServerDataProvider;
public enum WirelessTransceiverProvider implements IServerDataProvider<BlockAccessor> {
INSTANCE;
private static final ResourceLocation UID = new ResourceLocation("extendedae_plus", "wireless_transceiver_info");
// 此类仅用于同步服务端数据不再包含客户端选项键
@Override
public ResourceLocation getUid() {
return UID;
}
@Override
public void appendServerData(CompoundTag data, BlockAccessor accessor) {
if (accessor.getBlockEntity() instanceof WirelessTransceiverBlockEntity blockEntity) {
data.putLong("frequency", blockEntity.getFrequency());
data.putBoolean("masterMode", blockEntity.isMasterMode());
data.putBoolean("locked", blockEntity.isLocked());
// 判断 AE 网络是否可用节点存在加入网路且网络通电
IGridNode node = blockEntity.getGridNode();
IGrid grid = node == null ? null : node.getGrid();
boolean networkUsable = false;
if (grid != null) {
try {
networkUsable = grid.getEnergyService().isNetworkPowered();
} catch (Throwable ignored) {
networkUsable = false;
}
}
data.putBoolean("networkUsable", networkUsable);
// 如果是从模式查询主节点位置与维度
if (!blockEntity.isMasterMode()) {
var level = blockEntity.getServerLevel();
long freq = blockEntity.getFrequency();
IWirelessEndpoint master = WirelessMasterRegistry.get(level, freq);
if (master != null && !master.isEndpointRemoved()) {
BlockPos pos = master.getBlockPos();
if (pos != null) {
data.putLong("masterPos", pos.asLong());
}
if (master.getServerLevel() != null) {
data.putString("masterDim", master.getServerLevel().dimension().location().toString());
}
}
}
}
}
}

View File

@ -14,5 +14,15 @@
"gui.extendedae_plus.group_header.choice": "Toggle Group Choice", "gui.extendedae_plus.group_header.choice": "Toggle Group Choice",
"gui.extendedae_plus.group_header.choiceable": "Group is choiceable", "gui.extendedae_plus.group_header.choiceable": "Group is choiceable",
"gui.extendedae_plus.group_header.not_choiceable": "Group is not choiceable", "gui.extendedae_plus.group_header.not_choiceable": "Group is not choiceable",
"itemGroup.extendedae_plus.main": "ExtendedAE Plus" "itemGroup.extendedae_plus.main": "ExtendedAE Plus",
"config.jade.plugin_extendedae_plus.wireless_transceiver_info": "Wireless Transceiver Info",
"config.jade.plugin_extendedae_plus.wt_frequency": "Show Frequency",
"config.jade.plugin_extendedae_plus.wt_master_mode": "Show Master/Slave Mode",
"config.jade.plugin_extendedae_plus.wt_master_location": "Show Master Position",
"config.jade.plugin_extendedae_plus.wt_locked": "Show Locked State",
"config.jade.plugin_extendedae_plus.wt_network_usable": "Show Network Online State",
"extendedae_plus.tooltip.frequency": "Frequency: %d",
"extendedae_plus.tooltip.master_mode": "Mode: %s",
"extendedae_plus.tooltip.locked": "Locked: %s"
} }

View File

@ -26,5 +26,15 @@
"item.extendedae_plus.16x_crafting_accelerator": "16x并行处理单元", "item.extendedae_plus.16x_crafting_accelerator": "16x并行处理单元",
"item.extendedae_plus.64x_crafting_accelerator": "64x并行处理单元", "item.extendedae_plus.64x_crafting_accelerator": "64x并行处理单元",
"item.extendedae_plus.256x_crafting_accelerator": "256x并行处理单元", "item.extendedae_plus.256x_crafting_accelerator": "256x并行处理单元",
"item.extendedae_plus.1024x_crafting_accelerator": "1024x并行处理单元" "item.extendedae_plus.1024x_crafting_accelerator": "1024x并行处理单元",
"config.jade.plugin_extendedae_plus.wireless_transceiver_info": "无线收发器信息",
"config.jade.plugin_extendedae_plus.wt_frequency": "显示频率",
"config.jade.plugin_extendedae_plus.wt_master_mode": "显示主/从模式",
"config.jade.plugin_extendedae_plus.wt_master_location": "显示主节点位置",
"config.jade.plugin_extendedae_plus.wt_locked": "显示锁定状态",
"config.jade.plugin_extendedae_plus.wt_network_usable": "显示网络在线状态",
"extendedae_plus.tooltip.frequency": "频率: %d",
"extendedae_plus.tooltip.master_mode": "模式: %s",
"extendedae_plus.tooltip.locked": "锁定状态: %s"
} }