Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minecraft Forge 1.16 Get Blockdamage Progress

I can't figure out how to read the blockbreak progress in minecraft forge version 1.16. I know the function DestroyBlockProgress and the variant with hashmaps, but I can't find out how this works.

A little tip or an example would help me a lot

like image 960
Skylander Avatar asked Aug 11 '26 12:08

Skylander


1 Answers

You can access these maps using the MinecraftForge.EVENT_BUS and subscribing to the appropriate event (e.g., BlockBreakEvent). Iterate through the HashMap<BlockPos, BlockState> to find the block you're interested in. If the block is found, use the HashMap<BlockPos, Integer> to retrieve its progress value. This value typically ranges from 0 to 10, with 0 indicating the beginning of the destruction and 10 indicating the block is fully destroyed.

public class BlockBreakProgressListener {
    @SubscribeEvent
    public void onBlockBreak(BlockBreakEvent event) {
        BlockPos pos = event.getPos();
        PlayerEntity player = event.getPlayer();

        if (MinecraftForge.EVENT_BUS.post(new DestroyBlockProgressEvent.Start(player, pos, event.getState()))) {
            int progress = MinecraftForge.EVENT_BUS.post(new DestroyBlockProgressEvent.Update(player, pos, event.getState(), 5));
            System.out.println(progress);
        }
    }
}
like image 176
Tapan Khokhariya Avatar answered Aug 14 '26 10:08

Tapan Khokhariya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!