110000
我想实现让玩家右击一下任意方块(除了空气),就可以像用床一样睡觉,不是简单的躺下,而是让玩家进入睡眠状态(与床一样都得晚上),和床的功能一模一样,该怎么做?(判定右键点击没有问题,问题就是如何让玩家进入睡眠状态)
我之前去spigot或者bukkit的论坛里看到类似的问题,他们都说要用到数据包,然后我看到他们给出的代码都有用到PacketPlayOutBed这个类,但是我把他们给出的代码复制进去,运行的时候什么也没出现……

为什么要用到数据包呢?没有一个函数直接调用就让玩家睡觉?


q88724653
用ProtocolLib发数据包

DefineEvil
Use Bed

This packet tells that a player goes to bed.

The client with the matching Entity ID will go into bed mode.

This Packet is sent to all nearby players including the one sent to bed.

Any packets sent with a location not currently occupied by a bed will be ignored by clients.
Packet ID         State         Bound To         Field Name         Field Type         Notes
0x2F         Play         Client         Entity ID         VarInt         Sleeping player's EID
Location         Position         Block location of the head part of the bed

转自wiki.vg

好了,构造包吧

下一页 最后一页