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 aom) {
        this(aom.getId(), aom.getDeltaMovement());
    }
    
    public ClientboundSetEntityMotionPacket(final int integer, final Vec3 dem) {
        this.id = integer;
        final double double4 = 3.9;
        final double double5 = Mth.clamp(dem.x, -3.9, 3.9);
        final double double6 = Mth.clamp(dem.y, -3.9, 3.9);
        final double double7 = Mth.clamp(dem.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 mg) throws IOException {
        this.id = mg.readVarInt();
        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.writeShort(this.xa);
        mg.writeShort(this.ya);
        mg.writeShort(this.za);
    }
    
    @Override
    public void handle(final ClientGamePacketListener nl) {
        nl.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;
    }
}
