Solved Laying Down (without a bed)?

Discussion in 'Plugin Development' started by TeeePeee, Mar 18, 2015.

Thread Status:
Not open for further replies.
  1. Hey guys,

    I know this has been possible in the past, but I can't seem to get it working on recent versions of Bukkit. Note that this code is being executed from a custom NPC (extends EntityPlayer).

    // Make a bed packet...
    PacketPlayOutBed packet = new PacketPlayOutBed(EntityPlayer.this, new BlockPosition((int) locX, (int) locY, (int) locZ));
    * Doing this is essentially equivalent to looping through all players on the server.
    EntityTrackerEntry tracked = ((EntityTrackerEntry) ((WorldServer) world).tracker.trackedEntities.get(getId()));
    // Send the bed packet.
    // Just for good measure.
    sleeping = true;
    So, my question is, why can't I get the player to lay down?

    Got the problem figured out. Clients will refuse to rotate the player model, no matter the state of their sleeping field unless a bed is present at their local bed location. So a player must have a bed location set, and there must be a bed there for the player to appear laying down.

    Thanks in advance,
    Last edited: Mar 18, 2015
  2. try first spawning in a fake player using packets and then sending a packet with the same entity is as the fake player
    but this may have been fixed clientside with the 1.8 update
  3. @Cycryl
    As you can see above, that is what I did. Only the packet player is a real entity. Do you know if there's a place that has remapped the obfuscated client.jar source?
  4. @DJSkepter
    Thanks! From my quick glance at it, it seems that all you're doing is sending a PacketPlayOutBed with the entity ID and location of the Player... This is also what I'm doing, but for some reason, mine won't work (maybe because it's in a custom EntityPlayer, playerConnection is disconnected?)

    I should update what my current code is.

    public class CustomPlayer extends EntityPlayer {
        public CustomPlayer(Player inPlayer) {
            super(((CraftServer Bukkit.getServer()).getServer(), (WorldServer) (CraftWorld (inPlayer.getWorld()).getHandle(), ((CraftPlayer) inPlayer).getHandle().getProfile(), new PlayerInteractManager(((CraftPlayer inPlayer).getHandle().world);
            Location l = inPlayer.getLocation();
            setPositionRotation(l.getX(), l.getY(), l.getZ(), l.getYaw(), l.getPitch());
            // NullConnection is just an extension of PlayerConnection to spoof a connection.
            playerConnection = new NullConnection(this);
        // Happens on tick of the entity.
        public void s_() {
            PacketPlayOutBed = new PacketPlayOutBed(this, new BlockPosition(locX, locY, locZ));
            // Sends the bed packet to all trackers of this player.
            ((WorldServer) world).getTracker().a(this, bed);
    And the grand result of this: The player's nametag goes down to his shins (but doesn't lay down)
    Last edited: Mar 18, 2015
    DJSkepter likes this.
  5. Offline


    Never mind. My phone somehow didn't showed the first posts :/
  6. @MexMaster
    The custom EntityPlayer does a lot more than what I just posted. I left out the irrelevant bits. But I solved it!
  7. Offline


    Yeah I just skipped the first posts somehow, sorry.
Thread Status:
Not open for further replies.

Share This Page