package net.minecraft.network.protocol.game;

import net.minecraft.network.PacketListener;
import java.io.IOException;
import net.minecraft.core.Registry;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Entity;
import net.minecraft.util.Mth;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.entity.EntityType;
import java.util.UUID;
import net.minecraft.network.protocol.Packet;

public class ClientboundAddEntityPacket implements Packet<ClientGamePacketListener> {
    private int id;
    private UUID uuid;
    private double x;
    private double y;
    private double z;
    private int xa;
    private int ya;
    private int za;
    private int xRot;
    private int yRot;
    private EntityType<?> type;
    private int data;
    
    public ClientboundAddEntityPacket() {
    }
    
    public ClientboundAddEntityPacket(final int integer1, final UUID uUID, final double double3, final double double4, final double double5, final float float6, final float float7, final EntityType<?> aku, final int integer9, final Vec3 cvl) {
        this.id = integer1;
        this.uuid = uUID;
        this.x = double3;
        this.y = double4;
        this.z = double5;
        this.xRot = Mth.floor(float6 * 256.0f / 360.0f);
        this.yRot = Mth.floor(float7 * 256.0f / 360.0f);
        this.type = aku;
        this.data = integer9;
        this.xa = (int)(Mth.clamp(cvl.x, -3.9, 3.9) * 8000.0);
        this.ya = (int)(Mth.clamp(cvl.y, -3.9, 3.9) * 8000.0);
        this.za = (int)(Mth.clamp(cvl.z, -3.9, 3.9) * 8000.0);
    }
    
    public ClientboundAddEntityPacket(final Entity akq) {
        this(akq, 0);
    }
    
    public ClientboundAddEntityPacket(final Entity akq, final int integer) {
        this(akq.getId(), akq.getUUID(), akq.getX(), akq.getY(), akq.getZ(), akq.xRot, akq.yRot, akq.getType(), integer, akq.getDeltaMovement());
    }
    
    public ClientboundAddEntityPacket(final Entity akq, final EntityType<?> aku, final int integer, final BlockPos fk) {
        this(akq.getId(), akq.getUUID(), fk.getX(), fk.getY(), fk.getZ(), akq.xRot, akq.yRot, aku, integer, akq.getDeltaMovement());
    }
    
    @Override
    public void read(final FriendlyByteBuf kv) throws IOException {
        this.id = kv.readVarInt();
        this.uuid = kv.readUUID();
        this.type = Registry.ENTITY_TYPE.byId(kv.readVarInt());
        this.x = kv.readDouble();
        this.y = kv.readDouble();
        this.z = kv.readDouble();
        this.xRot = kv.readByte();
        this.yRot = kv.readByte();
        this.data = kv.readInt();
        this.xa = kv.readShort();
        this.ya = kv.readShort();
        this.za = kv.readShort();
    }
    
    @Override
    public void write(final FriendlyByteBuf kv) throws IOException {
        kv.writeVarInt(this.id);
        kv.writeUUID(this.uuid);
        kv.writeVarInt(Registry.ENTITY_TYPE.getId(this.type));
        kv.writeDouble(this.x);
        kv.writeDouble(this.y);
        kv.writeDouble(this.z);
        kv.writeByte(this.xRot);
        kv.writeByte(this.yRot);
        kv.writeInt(this.data);
        kv.writeShort(this.xa);
        kv.writeShort(this.ya);
        kv.writeShort(this.za);
    }
    
    @Override
    public void handle(final ClientGamePacketListener lw) {
        lw.handleAddEntity(this);
    }
    
    public int getId() {
        return this.id;
    }
    
    public UUID getUUID() {
        return this.uuid;
    }
    
    public double getX() {
        return this.x;
    }
    
    public double getY() {
        return this.y;
    }
    
    public double getZ() {
        return this.z;
    }
    
    public double getXa() {
        return this.xa / 8000.0;
    }
    
    public double getYa() {
        return this.ya / 8000.0;
    }
    
    public double getZa() {
        return this.za / 8000.0;
    }
    
    public int getxRot() {
        return this.xRot;
    }
    
    public int getyRot() {
        return this.yRot;
    }
    
    public EntityType<?> getType() {
        return this.type;
    }
    
    public int getData() {
        return this.data;
    }
}
