package net.minecraft.network.protocol.game;

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

public class ClientboundMoveEntityPacket implements Packet<ClientGamePacketListener> {
    protected int entityId;
    protected short xa;
    protected short ya;
    protected short za;
    protected byte yRot;
    protected byte xRot;
    protected boolean onGround;
    protected boolean hasRot;
    protected boolean hasPos;
    
    public static long entityToPacket(final double double1) {
        return Mth.lfloor(double1 * 4096.0);
    }
    
    public static Vec3 packetToEntity(final long long1, final long long2, final long long3) {
        return new Vec3((double)long1, (double)long2, (double)long3).scale(2.44140625E-4);
    }
    
    public ClientboundMoveEntityPacket() {
    }
    
    public ClientboundMoveEntityPacket(final int integer) {
        this.entityId = integer;
    }
    
    @Override
    public void read(final FriendlyByteBuf kv) throws IOException {
        this.entityId = kv.readVarInt();
    }
    
    @Override
    public void write(final FriendlyByteBuf kv) throws IOException {
        kv.writeVarInt(this.entityId);
    }
    
    @Override
    public void handle(final ClientGamePacketListener lw) {
        lw.handleMoveEntity(this);
    }
    
    @Override
    public String toString() {
        return "Entity_" + super.toString();
    }
    
    public Entity getEntity(final Level bjw) {
        return bjw.getEntity(this.entityId);
    }
    
    public short getXa() {
        return this.xa;
    }
    
    public short getYa() {
        return this.ya;
    }
    
    public short getZa() {
        return this.za;
    }
    
    public byte getyRot() {
        return this.yRot;
    }
    
    public byte getxRot() {
        return this.xRot;
    }
    
    public boolean hasRotation() {
        return this.hasRot;
    }
    
    public boolean hasPosition() {
        return this.hasPos;
    }
    
    public boolean isOnGround() {
        return this.onGround;
    }
    
    public static class PosRot extends ClientboundMoveEntityPacket {
        public PosRot() {
            this.hasRot = true;
            this.hasPos = true;
        }
        
        public PosRot(final int integer, final short short2, final short short3, final short short4, final byte byte5, final byte byte6, final boolean boolean7) {
            super(integer);
            this.xa = short2;
            this.ya = short3;
            this.za = short4;
            this.yRot = byte5;
            this.xRot = byte6;
            this.onGround = boolean7;
            this.hasRot = true;
            this.hasPos = true;
        }
        
        @Override
        public void read(final FriendlyByteBuf kv) throws IOException {
            super.read(kv);
            this.xa = kv.readShort();
            this.ya = kv.readShort();
            this.za = kv.readShort();
            this.yRot = kv.readByte();
            this.xRot = kv.readByte();
            this.onGround = kv.readBoolean();
        }
        
        @Override
        public void write(final FriendlyByteBuf kv) throws IOException {
            super.write(kv);
            kv.writeShort(this.xa);
            kv.writeShort(this.ya);
            kv.writeShort(this.za);
            kv.writeByte(this.yRot);
            kv.writeByte(this.xRot);
            kv.writeBoolean(this.onGround);
        }
    }
    
    public static class Pos extends ClientboundMoveEntityPacket {
        public Pos() {
            this.hasPos = true;
        }
        
        public Pos(final int integer, final short short2, final short short3, final short short4, final boolean boolean5) {
            super(integer);
            this.xa = short2;
            this.ya = short3;
            this.za = short4;
            this.onGround = boolean5;
            this.hasPos = true;
        }
        
        @Override
        public void read(final FriendlyByteBuf kv) throws IOException {
            super.read(kv);
            this.xa = kv.readShort();
            this.ya = kv.readShort();
            this.za = kv.readShort();
            this.onGround = kv.readBoolean();
        }
        
        @Override
        public void write(final FriendlyByteBuf kv) throws IOException {
            super.write(kv);
            kv.writeShort(this.xa);
            kv.writeShort(this.ya);
            kv.writeShort(this.za);
            kv.writeBoolean(this.onGround);
        }
    }
    
    public static class Rot extends ClientboundMoveEntityPacket {
        public Rot() {
            this.hasRot = true;
        }
        
        public Rot(final int integer, final byte byte2, final byte byte3, final boolean boolean4) {
            super(integer);
            this.yRot = byte2;
            this.xRot = byte3;
            this.hasRot = true;
            this.onGround = boolean4;
        }
        
        @Override
        public void read(final FriendlyByteBuf kv) throws IOException {
            super.read(kv);
            this.yRot = kv.readByte();
            this.xRot = kv.readByte();
            this.onGround = kv.readBoolean();
        }
        
        @Override
        public void write(final FriendlyByteBuf kv) throws IOException {
            super.write(kv);
            kv.writeByte(this.yRot);
            kv.writeByte(this.xRot);
            kv.writeBoolean(this.onGround);
        }
    }
}
