SetCameraEntityS2CPacket
is a clientbound packet that will be sent to client when player interacts an entity while in spectator mode. This packet is mainly used for setting the player's camera to entity's position.
But what if we send SetCameraEntityS2CPacket
when player is NOT in spectator mode? Surprisingly, player didn't kick themselves from server, plus their camera is now attached to target entity! The camera behavior is what you would normally expect like spectating mob the normal way (eg: hide hotbars, add linear interpolation to camera). Setting the camera to self (self as in the player whose connection handler is controlling) returns everything to normal. I haven't tested what happens when you set the camera to other players.
While the camera is attached to another entity, player's input like moving, sneaking, jumping and looking around will still working normally. You can test this by placing an armor stand, sit on a boat, send SetCameraEntityS2CPacket
with that armor stand as target, and move around like how you would ride the boat. You'll see the boat moving around.
Since maps can be used to draw bitmaps, you can combines with this janky tech to make server-side GUI, without requiring player to download a resource pack. This is exactly what Patbox's patch of "CC: Tweaked" is abusing to have server-side computer GUI.
What if you want to make a Zelda clone in Minecraft? You need a way to force player to be in 3rd person, but you also want to position player's model off-center as well (eg: when using bow).
With SetCameraEntityS2CPacket
, a bit of packets intercepting (pretty easy with some Mixins) and armor stands (does display entities works?), you can force any player to be in 3rd person! Attach camera to armor stand, then teleport it around to position the camera. For the model, you can use Nylon or my Crystalize library (shameless promotion 😉) to attach it to player's location, and suddenly you got yourself Genshin Zelda clone, completely server-side.
- Plasmid game test (
JankGame
) - See the Java code attached in this gist for quick easy
/setcamera
command.