MadMax CryptoMax Posted January 30, 2025 Report Posted January 30, 2025 (edited) Hey guys, I'm making a mode that can be used like prospecting pick but I want to find out a ore block position in the world when one is found. I can get the block but the block class itself doesn't have its position and every method/function I checked on BlockAccessor and other classes require BlockPos as argument. I'm after something like BlockPos GetBlockPos(Block block) or BlockPos GetBlockPos(int blockId) , I couldn't find anything like that. Any help will be very much appreciated. Thanks for the help. MadMax Edited January 30, 2025 by MadMax CryptoMax
BearWrestler Posted March 6, 2025 Report Posted March 6, 2025 (edited) Try IBlockAccessor.SearchBlocks(). You pass it two BlockPos that delimitate the corners of the cube of blocks it should search. It also takes as argument a delegate (method or lambda) that will get called with the Block and BlockPos for every single block encountered. That's where you can abort the search if you found what you want by returning false, or tell it to keep going by returning true. Note that the bigger the region to search, the more costly it will be (obviously). You'll notice the game rarely searches an area bigger than 8x8x8 blocks, to avoid freezing the main thread for too long. If you have a very large area to search, doing it progressively on a worker thread would probably be a good idea... but I don't think the game provides ready-made thread-safe algorithms to iterate over blocks (although it would be worth looking at the particle code which works in an async manner), so that means copy-pasting some of the game's decompiled code and rolling your own, dealing with missing chunks, locking and unpacking chunks, etc, yourself. Edited March 6, 2025 by BearWrestler
Recommended Posts