package net.minecraft.network.protocol.game;

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

public class ClientboundSetEntityMotionPacket implements Packet<ClientGamePacketListener> {
    private int id;
    private int xa;
    private int ya;
    private int za;
    
    public ClientboundSetEntityMotionPacket() {
    }
    
    public ClientboundSetEntityMotionPacket(final Entity akq) {
        this(akq.getId(), akq.getDeltaMovement());
    }
    
    public ClientboundSetEntityMotionPacket(final int integer, final Vec3 cvl) {
        this.id = integer;
        final double double4 = 3.9;
        final double double5 = Mth.clamp(cvl.x, -3.9, 3.9);
        final double double6 = Mth.clamp(cvl.y, -3.9, 3.9);
        final double double7 = Mth.clamp(cvl.z, -3.9, 3.9);
        this.xa = (int)(double5 * 8000.0);
        this.ya = (int)(double6 * 8000.0);
        this.za = (int)(double7 * 8000.0);
    }
    
    @Override
    public void read(final FriendlyByteBuf kv) throws IOException {
        this.id = kv.readVarInt();
        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.writeShort(this.xa);
        kv.writeShort(this.ya);
        kv.writeShort(this.za);
    }
    
    @Override
    public void handle(final ClientGamePacketListener lw) {
        lw.handleSetEntityMotion(this);
    }
    
    public int getId() {
        return this.id;
    }
    
    public int getXa() {
        return this.xa;
    }
    
    public int getYa() {
        return this.ya;
    }
    
    public int getZa() {
        return this.za;
    }
}
