首页 > 解决方案 > 如何在 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);
}

标签: minecraftbukkit

解决方案


您必须发送一个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);

推荐阅读