package net.minecraft.network.protocol.game;

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

public class ClientboundAddMobPacket implements Packet<ClientGamePacketListener> {
    private int id;
    private UUID uuid;
    private int type;
    private double x;
    private double y;
    private double z;
    private int xd;
    private int yd;
    private int zd;
    private byte yRot;
    private byte xRot;
    private byte yHeadRot;
    
    public ClientboundAddMobPacket() {
    }
    
    public ClientboundAddMobPacket(final LivingEntity akz) {
        this.id = akz.getId();
        this.uuid = akz.getUUID();
        this.type = Registry.ENTITY_TYPE.getId(akz.getType());
        this.x = akz.getX();
        this.y = akz.getY();
        this.z = akz.getZ();
        this.yRot = (byte)(akz.yRot * 256.0f / 360.0f);
        this.xRot = (byte)(akz.xRot * 256.0f / 360.0f);
        this.yHeadRot = (byte)(akz.yHeadRot * 256.0f / 360.0f);
        final double double3 = 3.9;
        final Vec3 cvl5 = akz.getDeltaMovement();
        final double double4 = Mth.clamp(cvl5.x, -3.9, 3.9);
        final double double5 = Mth.clamp(cvl5.y, -3.9, 3.9);
        final double double6 = Mth.clamp(cvl5.z, -3.9, 3.9);
        this.xd = (int)(double4 * 8000.0);
        this.yd = (int)(double5 * 8000.0);
        this.zd = (int)(double6 * 8000.0);
    }
    
    @Override
    public void read(final FriendlyByteBuf kv) throws IOException {
        this.id = kv.readVarInt();
        this.uuid = kv.readUUID();
        this.type = kv.readVarInt();
        this.x = kv.readDouble();
        this.y = kv.readDouble();
        this.z = kv.readDouble();
        this.yRot = kv.readByte();
        this.xRot = kv.readByte();
        this.yHeadRot = kv.readByte();
        this.xd = kv.readShort();
        this.yd = kv.readShort();
        this.zd = kv.readShort();
    }
    
    @Override
    public void write(final FriendlyByteBuf kv) throws IOException {
        kv.writeVarInt(this.id);
        kv.writeUUID(this.uuid);
        kv.writeVarInt(this.type);
        kv.writeDouble(this.x);
        kv.writeDouble(this.y);
        kv.writeDouble(this.z);
        kv.writeByte(this.yRot);
        kv.writeByte(this.xRot);
        kv.writeByte(this.yHeadRot);
        kv.writeShort(this.xd);
        kv.writeShort(this.yd);
        kv.writeShort(this.zd);
    }
    
    @Override
    public void handle(final ClientGamePacketListener lw) {
        lw.handleAddMob(this);
    }
    
    public int getId() {
        return this.id;
    }
    
    public UUID getUUID() {
        return this.uuid;
    }
    
    public int getType() {
        return this.type;
    }
    
    public double getX() {
        return this.x;
    }
    
    public double getY() {
        return this.y;
    }
    
    public double getZ() {
        return this.z;
    }
    
    public int getXd() {
        return this.xd;
    }
    
    public int getYd() {
        return this.yd;
    }
    
    public int getZd() {
        return this.zd;
    }
    
    public byte getyRot() {
        return this.yRot;
    }
    
    public byte getxRot() {
        return this.xRot;
    }
    
    public byte getyHeadRot() {
        return this.yHeadRot;
    }
}
