Archived
0

CPlayerPositionAndLookPacket

This commit is contained in:
2021-05-02 20:45:10 +03:00
parent 0835683294
commit 824fdf9569
5 changed files with 67 additions and 8 deletions

View File

@@ -46,14 +46,15 @@ public enum State {
Map.of(
0x00, TeleportConfirmPacket.class,
0x04, ClientSettingsPacket.class,
0x09, PluginMessagePacket.class
0x09, PluginMessagePacket.class,
0x0E, CPlayerPositionAndLookPacket.class
),
// client bound
Map.of(
JoinGamePacket.class, 0x23,
SpawnPositionPacket.class, 0x46,
PlayerAbilitiesPacket.class,0x2C,
PlayerPositionAndLookPacket.class, 0x2F
SPlayerPositionAndLookPacket.class, 0x2F
)
);

View File

@@ -0,0 +1,58 @@
package mc.protocol.packets.client;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import mc.protocol.io.NetByteBuf;
import mc.protocol.model.Location;
import mc.protocol.model.Look;
import mc.protocol.packets.ClientSidePacket;
/**
* Клиент сообщает о движении Игрока.
*
* <p>Структура пакета</p>
* <pre>
* | FIELD | TYPE | NOTES |
* |-----------|---------|------------------------------------------------------------|
* | X | Double | Абсолютная позиция по X |
* | Y | Double | Абсолютная позиция по Y. |
* | | | Имеется ввиду позиция ног. Голова находиться выше на 1.62f |
* | Z | Double | Абсолютная позиция по Z |
* | Yaw | Float | Абсолютный поворот головы по OX, в градусах |
* | Pitch | Float | Абсолютный поворот головы по OY, в градусах |
* | On Ground | Boolean | true, если Игрок находится на земле |
* </pre>
*
* @see <a href="https://wiki.vg/index.php?title=Protocol&oldid=14204#Player_Position_And_Look_.28serverbound.29">Player Position And Look (serverbound)</a>
*/
@NoArgsConstructor
@Getter
@EqualsAndHashCode
@ToString
public class CPlayerPositionAndLookPacket implements ClientSidePacket {
private Location position;
private Look look;
@SuppressWarnings("java:S116")
private boolean onGround;
@Override
public void readSelf(NetByteBuf netByteBuf) {
double x = netByteBuf.readDouble();
double y = netByteBuf.readDouble();
double z = netByteBuf.readDouble();
this.position = new Location(x, y, z);
float yaw = netByteBuf.readFloat();
float pitch = netByteBuf.readFloat();
this.look = new Look(yaw, pitch);
this.onGround = netByteBuf.readBoolean();
}
public double getYPositionHead() {
return this.position.getY() + 1.62f;
}
}

View File

@@ -6,7 +6,7 @@ import lombok.NoArgsConstructor;
import lombok.ToString;
import mc.protocol.io.NetByteBuf;
import mc.protocol.packets.ClientSidePacket;
import mc.protocol.packets.server.PlayerPositionAndLookPacket;
import mc.protocol.packets.server.SPlayerPositionAndLookPacket;
/**
* Teleport сonfirm packet.
@@ -15,11 +15,11 @@ import mc.protocol.packets.server.PlayerPositionAndLookPacket;
* <pre>
* | FIELD | TYPE | NOTES |
* |-------------|--------|-----------------------------------------------------------|
* | Teleport ID | VarInt | ID, который был выдан пакетом {@link PlayerPositionAndLookPacket} |
* | Teleport ID | VarInt | ID, который был выдан пакетом {@link SPlayerPositionAndLookPacket} |
* </pre>
*
* @see <a href="https://wiki.vg/index.php?title=Protocol&oldid=7368#Login_Start" target="_top">Login start</a>
* @see PlayerPositionAndLookPacket
* @see SPlayerPositionAndLookPacket
*/
@NoArgsConstructor
@Getter

View File

@@ -37,11 +37,11 @@ import mc.protocol.packets.client.TeleportConfirmPacket;
* <p>Примечание от Dinnerbone про "Flags":</p>
* <i>"It's a bitfield, X/Y/Z/Y_ROT/X_ROT. If X is set, the x value is relative and not absolute."</i>
*
* @see <a href="https://wiki.vg/index.php?title=Protocol&oldid=14204#Player_Position_And_Look_.28clientbound.29">Player Position And Look</a>
* @see <a href="https://wiki.vg/index.php?title=Protocol&oldid=14204#Player_Position_And_Look_.28clientbound.29">Player Position And Look (clientbound)</a>
* @see TeleportConfirmPacket
*/
@Data
public class PlayerPositionAndLookPacket implements ServerSidePacket {
public class SPlayerPositionAndLookPacket implements ServerSidePacket {
private Location position;
private Look look;

View File

@@ -99,7 +99,7 @@ public class PacketHandler {
channel.getCtx().flush();
var playerPositionAndLookPacket = new PlayerPositionAndLookPacket();
var playerPositionAndLookPacket = new SPlayerPositionAndLookPacket();
playerPositionAndLookPacket.setPosition(spawnLocation);
playerPositionAndLookPacket.setLook(new Look(0f, 0f));
playerPositionAndLookPacket.setTeleportId(random.nextInt());