AXHud
本模组是我为部分插件开发的 HUD 模组。
功能:
- 目前,该模组可以在用户屏幕顶部物品的旁边显示文本
命令
/axhud test diamond:测试显示效果/axhud clear:清除显示
依赖项:
你可以将此模组用于你自己的模组/插件。
查看方法
[Paper/Spigot 1.21.x]package <your_package>;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
public class CommunicationInterface {
private final JavaPlugin plugin;
/**
* 构造函数 - 传入你的插件实例
*
* 在你的主插件类中的用法:
*
* public class <your_plugin> extends JavaPlugin {
* private CommunicationInterface commInterface;
*
* @Override
* public void onEnable() {
* this.getServer().getMessenger().registerOutgoingPluginChannel(this, "axhud:display_item");
* this.commInterface = new CommunicationInterface(this);
* }
*
* public CommunicationInterface getCommInterface() {
* return commInterface;
* }
* }
*
*/
public CommunicationInterface(JavaPlugin plugin) {
this.plugin = plugin;
}
/**
* 向玩家客户端发送物品显示数据
*
* @param player 接收数据的玩家
* @param itemId 物品 ID(例如:"minecraft:diamond"、"minecraft:emerald")
* @param displayName 在物品旁边显示的名称(支持颜色代码如 §a、§b 等)
*/
public void sendItemDisplay(Player player, String itemId, String displayName) {
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(byteStream);
try {
// 写入物品 ID 字符串
writeString(out, itemId);
// 写入显示名称字符串
writeString(out, displayName);
// 发送插件消息
player.sendPluginMessage(plugin, "axhud:display_item", byteStream.toByteArray());
} catch (IOException e) {
plugin.getLogger().warning("Failed to send item display to player: " + e.getMessage());
}
}
/**
* 按照 Minecraft 的格式将字符串写入 DataOutputStream
* (VarInt 长度 + UTF-8 字节)
*/
private void writeString(DataOutputStream out, String str) throws IOException {
byte[] bytes = str.getBytes(java.nio.charset.StandardCharsets.UTF_8);
writeVarInt(out, bytes.length);
out.write(bytes);
}
/**
* 向 DataOutputStream 写入 VarInt(Minecraft 协议格式)
*/
private void writeVarInt(DataOutputStream out, int value) throws IOException {
while ((value & 0xFFFFFF80) != 0) {
out.writeByte((value & 0x7F) | 0x80);
value >>>= 7;
}
out.writeByte(value & 0x7F);
}
}
你是这个资源的作者?登录后可认领此资源。
相似资源
Woot Revived
pharuxtan
一个用于收集生物掉落物的多区块模组。
生物科技
349
玉Jade ?
Snownee
显示你正在注视的方块的信息。(适用于 Minecraft 1.16+ 的 Hwyla/Waila 分支)
实用前置
339
KubeJS
Lat
使用 JavaScript 编辑配方、添加自定义物品、编写世界事件!
前置实用
239
物品管理器Just Enough Items (JEI)
mezz
查看物品与配方
前置实用
239
Xaero的小地图
thexaero
在游戏画面角落显示附近世界地形、玩家、生物和实体的地图。可创建路径点,帮助你找到标记过的位置。
冒险交通
239
Applied Energistics 2
shartte
AE2:一款流行的自动化与存储模组
存储科技
217
评论 0
登录后参与评分
还没有评论,来抢沙发吧