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 bpg, final BlockPos fu) {
        this.pos = fu;
        this.blockState = bpg.getBlockState(fu);
    }
    
    @Override
    public void read(final FriendlyByteBuf mg) throws IOException {
        this.pos = mg.readBlockPos();
        this.blockState = Block.BLOCK_STATE_REGISTRY.byId(mg.readVarInt());
    }
    
    @Override
    public void write(final FriendlyByteBuf mg) throws IOException {
        mg.writeBlockPos(this.pos);
        mg.writeVarInt(Block.getId(this.blockState));
    }
    
    @Override
    public void handle(final ClientGamePacketListener nl) {
        nl.handleBlockUpdate(this);
    }
    
    public BlockState getBlockState() {
        return this.blockState;
    }
    
    public BlockPos getPos() {
        return this.pos;
    }
}
