How to make npc playing packets like players?

Discussion in 'Spigot Plugin Development' started by TerZer, Jun 9, 2017.

  1. Title says it all. How to lay down npc? This code only lay down players:
    Code (Text):
        private void playSleepAnimation(Player asleep) {
            final PacketContainer bedPacket = manager.createPacket(PacketType.Play.Server.BED, false);
            Location loc = new Location(asleep.getWorld(), -209, 89, -178); //Location of bed you hided.
            BlockPosition blockPos = new BlockPosition(loc.getBlock().getX(), loc.getBlock().getY(), loc.getBlock().getZ());
                write(0, asleep);
            bedPacket.getBlockPositionModifier().write(0, blockPos);
            broadcastNearby(asleep, bedPacket);
            new BukkitRunnable() {

                public void run() {
            }.runTaskLater(plugin, 20*5);
  2. How are you handling your npcs?
    It is important the client thinks there is a bed at that place. At the protocol wiki -> "Any packets sent with a location not currently occupied by a bed will be ignored by clients."
  3. I am creating npc with this code:

    Code (Text):
    MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer();
                    WorldServer nmsWorld = ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle();
                    npc = new EntityPlayer(nmsServer, nmsWorld, new GameProfile(UUID.fromString("c793afb5-c4b7-4fdb-a100-b761315913c4"), "PogoStick29"), new PlayerInteractManager(nmsWorld));
    Spawning with this one:
    Code (Text):
    npc.setLocation(e.getPlayer().getLocation().getX(), e.getPlayer().getLocation().getY(), e.getPlayer().getLocation().getZ(), 0, 0);
                    PlayerConnection connection = ((CraftPlayer) e.getPlayer()).getHandle().playerConnection;
                    connection.sendPacket(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, npc));
                    connection.sendPacket(new PacketPlayOutNamedEntitySpawn(npc));
  4. Then you just have to send a Use Bed packet ( to all nearby players to make the npc lay down. Important: the bed must be there!
  5. Not working... :((( No errors. But npc just standing still, not laying down.

    @Remceau so maybe you can help me with that?
    #5 TerZer, Jun 9, 2017
    Last edited: Jun 9, 2017
  6. Weird... Can you post your full code? I will test the packet myself.

    I don't get it working, and i don't know why.
    #6 Remceau, Jun 9, 2017
    Last edited: Jun 9, 2017
  7. Same, like wtf? You still need code?
  8. Just post if for if someone else comes by.