97 lines
2.6 KiB
Java
97 lines
2.6 KiB
Java
package net.minecraft.network.protocol.game;
|
|
|
|
import java.util.Set;
|
|
import net.minecraft.network.FriendlyByteBuf;
|
|
import net.minecraft.network.codec.StreamCodec;
|
|
import net.minecraft.network.protocol.Packet;
|
|
import net.minecraft.network.protocol.PacketType;
|
|
import net.minecraft.world.entity.RelativeMovement;
|
|
|
|
public class ClientboundPlayerPositionPacket implements Packet<ClientGamePacketListener> {
|
|
public static final StreamCodec<FriendlyByteBuf, ClientboundPlayerPositionPacket> STREAM_CODEC = Packet.codec(
|
|
ClientboundPlayerPositionPacket::write, ClientboundPlayerPositionPacket::new
|
|
);
|
|
private final double x;
|
|
private final double y;
|
|
private final double z;
|
|
private final float yRot;
|
|
private final float xRot;
|
|
private final Set<RelativeMovement> relativeArguments;
|
|
private final int id;
|
|
|
|
public ClientboundPlayerPositionPacket(double x, double y, double z, float yRot, float xRot, Set<RelativeMovement> relativeArguments, int id) {
|
|
this.x = x;
|
|
this.y = y;
|
|
this.z = z;
|
|
this.yRot = yRot;
|
|
this.xRot = xRot;
|
|
this.relativeArguments = relativeArguments;
|
|
this.id = id;
|
|
}
|
|
|
|
private ClientboundPlayerPositionPacket(FriendlyByteBuf buffer) {
|
|
this.x = buffer.readDouble();
|
|
this.y = buffer.readDouble();
|
|
this.z = buffer.readDouble();
|
|
this.yRot = buffer.readFloat();
|
|
this.xRot = buffer.readFloat();
|
|
this.relativeArguments = RelativeMovement.unpack(buffer.readUnsignedByte());
|
|
this.id = buffer.readVarInt();
|
|
}
|
|
|
|
/**
|
|
* Writes the raw packet data to the data stream.
|
|
*/
|
|
private void write(FriendlyByteBuf buffer) {
|
|
buffer.writeDouble(this.x);
|
|
buffer.writeDouble(this.y);
|
|
buffer.writeDouble(this.z);
|
|
buffer.writeFloat(this.yRot);
|
|
buffer.writeFloat(this.xRot);
|
|
buffer.writeByte(RelativeMovement.pack(this.relativeArguments));
|
|
buffer.writeVarInt(this.id);
|
|
}
|
|
|
|
@Override
|
|
public PacketType<ClientboundPlayerPositionPacket> type() {
|
|
return GamePacketTypes.CLIENTBOUND_PLAYER_POSITION;
|
|
}
|
|
|
|
/**
|
|
* Passes this Packet on to the NetHandler for processing.
|
|
*/
|
|
public void handle(ClientGamePacketListener handler) {
|
|
handler.handleMovePlayer(this);
|
|
}
|
|
|
|
public double getX() {
|
|
return this.x;
|
|
}
|
|
|
|
public double getY() {
|
|
return this.y;
|
|
}
|
|
|
|
public double getZ() {
|
|
return this.z;
|
|
}
|
|
|
|
public float getYRot() {
|
|
return this.yRot;
|
|
}
|
|
|
|
public float getXRot() {
|
|
return this.xRot;
|
|
}
|
|
|
|
public int getId() {
|
|
return this.id;
|
|
}
|
|
|
|
/**
|
|
* Returns a set of which fields are relative. Items in this set indicate that the value is a relative change applied to the player's position, rather than an exact value.
|
|
*/
|
|
public Set<RelativeMovement> getRelativeArguments() {
|
|
return this.relativeArguments;
|
|
}
|
|
}
|