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 aoy) {
        this.id = aoy.getId();
        this.uuid = aoy.getUUID();
        this.type = Registry.ENTITY_TYPE.getId(aoy.getType());
        this.x = aoy.getX();
        this.y = aoy.getY();
        this.z = aoy.getZ();
        this.yRot = (byte)(aoy.yRot * 256.0f / 360.0f);
        this.xRot = (byte)(aoy.xRot * 256.0f / 360.0f);
        this.yHeadRot = (byte)(aoy.yHeadRot * 256.0f / 360.0f);
        final double double3 = 3.9;
        final Vec3 dem5 = aoy.getDeltaMovement();
        final double double4 = Mth.clamp(dem5.x, -3.9, 3.9);
        final double double5 = Mth.clamp(dem5.y, -3.9, 3.9);
        final double double6 = Mth.clamp(dem5.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 mg) throws IOException {
        this.id = mg.readVarInt();
        this.uuid = mg.readUUID();
        this.type = mg.readVarInt();
        this.x = mg.readDouble();
        this.y = mg.readDouble();
        this.z = mg.readDouble();
        this.yRot = mg.readByte();
        this.xRot = mg.readByte();
        this.yHeadRot = mg.readByte();
        this.xd = mg.readShort();
        this.yd = mg.readShort();
        this.zd = mg.readShort();
    }
    
    @Override
    public void write(final FriendlyByteBuf mg) throws IOException {
        mg.writeVarInt(this.id);
        mg.writeUUID(this.uuid);
        mg.writeVarInt(this.type);
        mg.writeDouble(this.x);
        mg.writeDouble(this.y);
        mg.writeDouble(this.z);
        mg.writeByte(this.yRot);
        mg.writeByte(this.xRot);
        mg.writeByte(this.yHeadRot);
        mg.writeShort(this.xd);
        mg.writeShort(this.yd);
        mg.writeShort(this.zd);
    }
    
    @Override
    public void handle(final ClientGamePacketListener nl) {
        nl.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;
    }
}
