package net.minecraft.network.protocol.game;

import net.minecraft.network.PacketListener;
import java.io.IOException;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.entity.player.Player;
import java.util.UUID;
import net.minecraft.network.protocol.Packet;

public class ClientboundAddPlayerPacket implements Packet<ClientGamePacketListener> {
    private int entityId;
    private UUID playerId;
    private double x;
    private double y;
    private double z;
    private byte yRot;
    private byte xRot;
    
    public ClientboundAddPlayerPacket() {
    }
    
    public ClientboundAddPlayerPacket(final Player ayj) {
        this.entityId = ayj.getId();
        this.playerId = ayj.getGameProfile().getId();
        this.x = ayj.getX();
        this.y = ayj.getY();
        this.z = ayj.getZ();
        this.yRot = (byte)(ayj.yRot * 256.0f / 360.0f);
        this.xRot = (byte)(ayj.xRot * 256.0f / 360.0f);
    }
    
    @Override
    public void read(final FriendlyByteBuf kv) throws IOException {
        this.entityId = kv.readVarInt();
        this.playerId = kv.readUUID();
        this.x = kv.readDouble();
        this.y = kv.readDouble();
        this.z = kv.readDouble();
        this.yRot = kv.readByte();
        this.xRot = kv.readByte();
    }
    
    @Override
    public void write(final FriendlyByteBuf kv) throws IOException {
        kv.writeVarInt(this.entityId);
        kv.writeUUID(this.playerId);
        kv.writeDouble(this.x);
        kv.writeDouble(this.y);
        kv.writeDouble(this.z);
        kv.writeByte(this.yRot);
        kv.writeByte(this.xRot);
    }
    
    @Override
    public void handle(final ClientGamePacketListener lw) {
        lw.handleAddPlayer(this);
    }
    
    public int getEntityId() {
        return this.entityId;
    }
    
    public UUID getPlayerId() {
        return this.playerId;
    }
    
    public double getX() {
        return this.x;
    }
    
    public double getY() {
        return this.y;
    }
    
    public double getZ() {
        return this.z;
    }
    
    public byte getyRot() {
        return this.yRot;
    }
    
    public byte getxRot() {
        return this.xRot;
    }
}
