Confirmedusers, Bureaucrats, editor, Administrators
1,779
edits
Line 29: | Line 29: | ||
a) If you want an entity to find a certain, not extremely common block, use the [https://github.com/anegostudios/vsessentialsmod/blob/master/Systems/POIRegistry.cs POI Registry]. This registry lets block entities register a point of interest that entities can search through very efficiently. They are also partitioned into chunk column buckets to additionally reduce the search space. For a code sample, check out the [https://github.com/anegostudios/vssurvivalmod/blob/master/BlockEntity/BEBerryBush.cs berry bush block entity]<br> | a) If you want an entity to find a certain, not extremely common block, use the [https://github.com/anegostudios/vsessentialsmod/blob/master/Systems/POIRegistry.cs POI Registry]. This registry lets block entities register a point of interest that entities can search through very efficiently. They are also partitioned into chunk column buckets to additionally reduce the search space. For a code sample, check out the [https://github.com/anegostudios/vssurvivalmod/blob/master/BlockEntity/BEBerryBush.cs berry bush block entity]<br> | ||
b) For regular full chunk scans, I recommend a separate background thread that loads the chunk and access the raw block data via <code>chunk.Blocks</code>. It's an array indexed with <code>(y * chunksize + z) * chunksize + x</code>, where the xyz are local coordinate from 0 to chunkize-1<br> | b) For regular full chunk scans, I recommend a separate background thread that loads the chunk and access the raw block data via <code>chunk.Blocks</code>. It's an array indexed with <code>(y * chunksize + z) * chunksize + x</code>, where the xyz are local coordinate from 0 to chunkize-1<br> | ||
c) For rare area scans, there is | c) For rare area scans, there is <code>api.World.GetBlockAccessorPrefetch()</code>. This block accessor lets you pre-load an area and then rather efficiently iterate through each block in given area | ||
</li> | </li> | ||
</ul> | </ul> |