package net.minecraft.network.protocol.game;

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

public class ClientboundTeleportEntityPacket implements Packet<ClientGamePacketListener> {
    private int id;
    private double x;
    private double y;
    private double z;
    private byte yRot;
    private byte xRot;
    private boolean onGround;
    
    public ClientboundTeleportEntityPacket() {
    }
    
    public ClientboundTeleportEntityPacket(final Entity aom) {
        this.id = aom.getId();
        this.x = aom.getX();
        this.y = aom.getY();
        this.z = aom.getZ();
        this.yRot = (byte)(aom.yRot * 256.0f / 360.0f);
        this.xRot = (byte)(aom.xRot * 256.0f / 360.0f);
        this.onGround = aom.isOnGround();
    }
    
    @Override
    public void read(final FriendlyByteBuf mg) throws IOException {
        this.id = mg.readVarInt();
        this.x = mg.readDouble();
        this.y = mg.readDouble();
        this.z = mg.readDouble();
        this.yRot = mg.readByte();
        this.xRot = mg.readByte();
        this.onGround = mg.readBoolean();
    }
    
    @Override
    public void write(final FriendlyByteBuf mg) throws IOException {
        mg.writeVarInt(this.id);
        mg.writeDouble(this.x);
        mg.writeDouble(this.y);
        mg.writeDouble(this.z);
        mg.writeByte(this.yRot);
        mg.writeByte(this.xRot);
        mg.writeBoolean(this.onGround);
    }
    
    @Override
    public void handle(final ClientGamePacketListener nl) {
        nl.handleTeleportEntity(this);
    }
    
    public int getId() {
        return this.id;
    }
    
    public double getX() {
        return this.x;
    }
    
    public double getY() {
        return this.y;
    }
    
    public double getZ() {
        return this.z;
    }
    
    public byte getyRot() {
        return this.yRot;
    }
    
    public byte getxRot() {
        return this.xRot;
    }
    
    public boolean isOnGround() {
        return this.onGround;
    }
}
