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<?> aoq, final int integer9, final Vec3 dem) {
        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 = aoq;
        this.data = integer9;
        this.xa = (int)(Mth.clamp(dem.x, -3.9, 3.9) * 8000.0);
        this.ya = (int)(Mth.clamp(dem.y, -3.9, 3.9) * 8000.0);
        this.za = (int)(Mth.clamp(dem.z, -3.9, 3.9) * 8000.0);
    }
    
    public ClientboundAddEntityPacket(final Entity aom) {
        this(aom, 0);
    }
    
    public ClientboundAddEntityPacket(final Entity aom, final int integer) {
        this(aom.getId(), aom.getUUID(), aom.getX(), aom.getY(), aom.getZ(), aom.xRot, aom.yRot, aom.getType(), integer, aom.getDeltaMovement());
    }
    
    public ClientboundAddEntityPacket(final Entity aom, final EntityType<?> aoq, final int integer, final BlockPos fu) {
        this(aom.getId(), aom.getUUID(), fu.getX(), fu.getY(), fu.getZ(), aom.xRot, aom.yRot, aoq, integer, aom.getDeltaMovement());
    }
    
    @Override
    public void read(final FriendlyByteBuf mg) throws IOException {
        this.id = mg.readVarInt();
        this.uuid = mg.readUUID();
        this.type = Registry.ENTITY_TYPE.byId(mg.readVarInt());
        this.x = mg.readDouble();
        this.y = mg.readDouble();
        this.z = mg.readDouble();
        this.xRot = mg.readByte();
        this.yRot = mg.readByte();
        this.data = mg.readInt();
        this.xa = mg.readShort();
        this.ya = mg.readShort();
        this.za = mg.readShort();
    }
    
    @Override
    public void write(final FriendlyByteBuf mg) throws IOException {
        mg.writeVarInt(this.id);
        mg.writeUUID(this.uuid);
        mg.writeVarInt(Registry.ENTITY_TYPE.getId(this.type));
        mg.writeDouble(this.x);
        mg.writeDouble(this.y);
        mg.writeDouble(this.z);
        mg.writeByte(this.xRot);
        mg.writeByte(this.yRot);
        mg.writeInt(this.data);
        mg.writeShort(this.xa);
        mg.writeShort(this.ya);
        mg.writeShort(this.za);
    }
    
    @Override
    public void handle(final ClientGamePacketListener nl) {
        nl.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;
    }
}
