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
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);
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With