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 bec) {
        this.entityId = bec.getId();
        this.playerId = bec.getGameProfile().getId();
        this.x = bec.getX();
        this.y = bec.getY();
        this.z = bec.getZ();
        this.yRot = (byte)(bec.yRot * 256.0f / 360.0f);
        this.xRot = (byte)(bec.xRot * 256.0f / 360.0f);
    }
    
    @Override
    public void read(final FriendlyByteBuf mg) throws IOException {
        this.entityId = mg.readVarInt();
        this.playerId = mg.readUUID();
        this.x = mg.readDouble();
        this.y = mg.readDouble();
        this.z = mg.readDouble();
        this.yRot = mg.readByte();
        this.xRot = mg.readByte();
    }
    
    @Override
    public void write(final FriendlyByteBuf mg) throws IOException {
        mg.writeVarInt(this.entityId);
        mg.writeUUID(this.playerId);
        mg.writeDouble(this.x);
        mg.writeDouble(this.y);
        mg.writeDouble(this.z);
        mg.writeByte(this.yRot);
        mg.writeByte(this.xRot);
    }
    
    @Override
    public void handle(final ClientGamePacketListener nl) {
        nl.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;
    }
}
