The API is split in 2 :
- the World which is async
- the World.sync which is sync
The characteristics of the async world is that it will always return something when getting a block, but as a promise. To achieve this it may load columns from anvil files or other storage. On the other hand the sync world will not always return blocks and may return null, but it will return the block directly with no promise.
The set operations have similar characteristics : the async world will always set the blocks and return a promise, whereas the sync world will not always set the blocks, but do the action now and not return a promise.
The 2 world are linked and stay in sync together.
The async world may be more natural for servers (although the sync world can also be used there) The sync world makes more sense for clients as there is not necessarily somewhere to load more data from (but in some cases this may be incorrect too, think multi player clients)
Create a world instance, takes an optional generateChunk(chunkX, chunkZ)
function that will get called when a chunk at
chunkX
and chunkZ
need to be generated. Takes a second optional arguments : storageProvider
containing the regions.
If provided, prismarine-world will first try to load the map from these regions, and then try to generate the world if
the chunk isn't saved. savingInterval
default to 50ms.
Fires when a block updates. Both oldBlock
and newBlock
provided for
comparison.
Note that oldBlock
may be null
.
Fires for a specific point. Both oldBlock
and newBlock
provided for
comparison.
Note that oldBlock
may be null
.
Fires when a chunk has updated. point
is the coordinates to the corner
of the chunk with the smallest x, y, and z values.
Initialize the world with a given blocks cube. Useful to load quickly a schematic.
iniFunc
is a function(x,y,z) that returns a prismarine-blocklength
,width
andheight
are the size to iterate oniniPos
is the position where to start the iteration
Returns a promise containing an array of {chunkX,chunkZ}
Raycast in the world.
from
- Vec3, position to raycast fromdirection
- Vec3, direction of the ray, must be normalizedrange
- max distance to raycastmatcher
- optional function with a block parameter, return true if the raycast should stop at this block, false otherwise
Return all loaded columns
Unload column from memory
All the following methods are async and return a promise.
Set chunk
at chunkX
and chunkZ
Return the column at chunkX
and chunkZ
Get the block state at pos
Get the block type at pos
Get the block data (metadata) at pos
Get the block light at pos
Get the block sky light at pos
Get the block biome id at pos
Set the block state stateId
at pos
Set the block type id
at pos
Set the block data
(metadata) at pos
Set the block light
at pos
Set the block sky light
at pos
Set the block biome
id at pos
Returns a promise that is resolved when all saving is done.
Build a sync world, will delegate all the saving work to the async one
It exposes the same methods as World but all methods are sync.
Iterators are used to iterate over blocks. Use cases include finding specific blocks quickly and computing a ray cast.
2D rectangular spiral iterator, useful to iterate on columns that are centered on bot position
return null or the next position (Vec3)
start is a Vec3
return null or the next position (Vec3)
pos and dir are Vec3
RaycastIterator iterates along a ray starting at pos
in dir
direction.
It steps exactly 1 block at a time, returning the block coordinates and the face by which the ray entered the block.
return null or the next position (Vec3)
pos
is Vec3
maxDistance
is number
Iterates outwards along x and z axis in a cubic spiral. First position returned is the starting position. Every step is 1 step away form the previous and next point.
return null or the next position (Vec3)
Number of points the iterator will return.