package net.minecraft.network.protocol.game;

import net.minecraft.network.PacketListener;
import java.io.IOException;
import net.minecraft.world.level.block.Block;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.core.BlockPos;
import net.minecraft.network.protocol.Packet;

public class ClientboundBlockUpdatePacket implements Packet<ClientGamePacketListener> {
    private BlockPos pos;
    private BlockState blockState;
    
    public ClientboundBlockUpdatePacket() {
    }
    
    public ClientboundBlockUpdatePacket(final BlockGetter bjg, final BlockPos fk) {
        this.pos = fk;
        this.blockState = bjg.getBlockState(fk);
    }
    
    @Override
    public void read(final FriendlyByteBuf kv) throws IOException {
        this.pos = kv.readBlockPos();
        this.blockState = Block.BLOCK_STATE_REGISTRY.byId(kv.readVarInt());
    }
    
    @Override
    public void write(final FriendlyByteBuf kv) throws IOException {
        kv.writeBlockPos(this.pos);
        kv.writeVarInt(Block.getId(this.blockState));
    }
    
    @Override
    public void handle(final ClientGamePacketListener lw) {
        lw.handleBlockUpdate(this);
    }
    
    public BlockState getBlockState() {
        return this.blockState;
    }
    
    public BlockPos getPos() {
        return this.pos;
    }
}
