minecraft - 如何在 NPC 上显示第二层皮肤
问题描述
我创建了一个 NPC 并为其添加了玩家的皮肤,但是没有显示第二层皮肤。怎么添加到NPC?我已经找到了一些新版本的解决方案,但它们不适用于 1.8
Location loc = new Location(world, x, y, z, 0, 0);
MinecraftServer minecraftServer = ((CraftServer) Bukkit.getServer()).getServer();
WorldServer worldServer = ((CraftWorld) main.getVotingUtils().world).getHandle();
GameProfile gameProfile = new GameProfile(UUID.randomUUID(), "§6Shop");
for (Player all : Bukkit.getOnlinePlayers()) {
EntityPlayer allEntity = ((CraftPlayer) all).getHandle();
GameProfile allGP = allEntity.getProfile();
Property skin = allGP.getProperties().get("textures").iterator().next();
gameProfile.getProperties().put("textures", skin);
EntityPlayer npc = new EntityPlayer(minecraftServer, worldServer, gameProfile, new PlayerInteractManager(worldServer));
npc.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
PlayerConnection connection = ((CraftPlayer) all).getHandle().playerConnection;
connection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, npc));
connection.sendPacket(new PacketPlayOutNamedEntitySpawn(npc));
Bukkit.getScheduler().scheduleSyncDelayedTask(main, () -> {
connection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, npc));
},5);
}
解决方案
您必须发送一个PacketPlayOutEntityMetadata
数据包,其中的 DataWrapper 填充了https://wiki.vg/Entity_metadata#Player中的相应位掩码
例如,如果要启用披风和左袖,则必须按如下方式设置位掩码:
byte bitmask = (byte) (0x01 | 0x04)
然后将此字节输入到您的 DataWatcher 中,然后将其包装PacketPlayOutEntityMetadata
并发送给您刚刚为其生成 NPC 的玩家。
请注意,在 1.8.x 版本中,玩家显示的皮肤部分的索引为 10。
因此,如果您想启用所有皮肤部件,您将使用以下代码:
DataWatcher dw = new DataWatcher(null);
dw.a(10, (byte) (0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40));
PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(npc.getId(), dw, true);
connection.sendPacket(packet);
推荐阅读
- reactjs - 拥有多个 React 实例意味着什么?
- python - django NoReverseMatch 尝试将模板链接到视图函数时出错
- database - Bigquery - 不保证外部数据源的数据一致性
- android - Android 10+ pdf doesnt send to Gmail
- gradle - Gradle 'include' 或 'exclude' 字符串列表
- r - R 编程,使用自定义脚本(针对每个 i)进行逐行数据帧计算以解决“桥牌游戏”
- python - matplotlib 子图没有间距,限制图形大小和tight_layout()
- javascript - 反应,在石头、纸、剪刀游戏中创造分数
- scala - 将数字矩阵(可转换为 Double)转换为 Double 矩阵
- wolframalpha - 当我尝试在 VS 代码 python ValueError 中使用 Wolfram Alpha 时出现此错误:字典更新序列元素 #0 的长度为 1;2 是必需的