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.global.LightningBolt;
import net.minecraft.world.entity.Entity;
import net.minecraft.network.protocol.Packet;

public class ClientboundAddGlobalEntityPacket implements Packet<ClientGamePacketListener> {
    private int id;
    private double x;
    private double y;
    private double z;
    private int type;
    
    public ClientboundAddGlobalEntityPacket() {
    }
    
    public ClientboundAddGlobalEntityPacket(final Entity akq) {
        this.id = akq.getId();
        this.x = akq.getX();
        this.y = akq.getY();
        this.z = akq.getZ();
        if (akq instanceof LightningBolt) {
            this.type = 1;
        }
    }
    
    @Override
    public void read(final FriendlyByteBuf kv) throws IOException {
        this.id = kv.readVarInt();
        this.type = kv.readByte();
        this.x = kv.readDouble();
        this.y = kv.readDouble();
        this.z = kv.readDouble();
    }
    
    @Override
    public void write(final FriendlyByteBuf kv) throws IOException {
        kv.writeVarInt(this.id);
        kv.writeByte(this.type);
        kv.writeDouble(this.x);
        kv.writeDouble(this.y);
        kv.writeDouble(this.z);
    }
    
    @Override
    public void handle(final ClientGamePacketListener lw) {
        lw.handleAddGlobalEntity(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 int getType() {
        return this.type;
    }
}
