Interface Spawner
- All Known Implementing Classes:
NoSpawner, PrefabSpawner
Spawners work in two phases:
test(World, Vector3ic, Random)is called (potentially many times per tick) to probe candidate positions. Returntrueif the position is acceptable. Implementations may cache the result of any expensive selection made here (such as choosing a prefab or rotation) as fields, sinceonComplete(Vector3ic, WorldEvent)will be called with the same position that last returnedtrue.onComplete(Vector3ic, WorldEvent)is called exactly once per stage completion, after all spawners have accepted the position. Write any context entries (e.g.PrefabPasteContext) here so that subsequent actions can reference them.
Multiple spawners can be registered on a single LocationCondition; all of them must
return true from test(World, Vector3ic, Random) for a position to be accepted.
The static helpers findSurface(int, int, int, int, int, ChunkStore), getBlockId(int, int, int, ChunkStore), and getFluidId(int, int, int, ChunkStore) are
provided for common terrain lookups.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceAsset-side factory for aSpawner.static enumRepresents the result of a spawner test operation. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic intfindSurface(int x, int startY, int z, int clearance, int searchRadius, ChunkStore store) Scans outward fromstartYfor the nearest Y that is itself solid and hasclearanceopen blocks above it.static intgetBlockId(int x, int y, int z, ChunkStore store) Returns the block type ID at the given world position, orBlockType.UNKNOWN_IDif the chunk section is not loaded.static intgetFluidId(int x, int y, int z, ChunkStore store) Returns the fluid ID at the given world position, orFluid.EMPTY_IDif the chunk section is not loaded or contains no fluid.booleanonComplete(org.joml.Vector3ic position, WorldEvent event) Called once when the owning stage completes, with the position that last returnedtruefromtest(World, Vector3ic, Random).Tests whetherpositionis a valid placement site and records any state needed byonComplete(Vector3ic, WorldEvent).
-
Field Details
-
EMPTY_ARRAY
-
INVALID_HEIGHT
static final int INVALID_HEIGHT- See Also:
-
-
Method Details
-
test
Spawner.Result test(@Nonnull World world, @Nonnull org.joml.Vector3ic position, @Nonnull Random random) Tests whetherpositionis a valid placement site and records any state needed byonComplete(Vector3ic, WorldEvent).This may be called up to several times per tick with different positions, so keep it cheap. If the test involves selecting from a random set (e.g. choosing a prefab), store the selection as a field rather than regenerating it in
onComplete(Vector3ic, WorldEvent).Check terrain validity using the static helpers on this interface. Reject the position (return
false) if any required chunk is unloaded, i.e. iffindSurface(int, int, int, int, int, ChunkStore)returnsINVALID_HEIGHT.- Parameters:
world- the world the position is inposition- the candidate block position, with Y already set to the nearest qualifying surfacerandom- a random source for any stochastic validation logic- Returns:
trueif the position is acceptable
-
onComplete
Called once when the owning stage completes, with the position that last returnedtruefromtest(World, Vector3ic, Random). Write any context values that downstream actions will need into the event context here.- Parameters:
position- the accepted block positionevent- the running world event whose context should be populated- Returns:
falseif the spawner cannot produce a valid result, treating the stage as failed
-
findSurface
static int findSurface(int x, int startY, int z, int clearance, int searchRadius, @Nonnull ChunkStore store) Scans outward fromstartYfor the nearest Y that is itself solid and hasclearanceopen blocks above it.Callers don't need to assume there is only one surface layer. An outdoor top, a cave floor, or any other layer are all just "the nearest qualifying surface" to whatever search origin is given.
- Parameters:
x- world x-coordinatestartY- the search origin, e.g. a candidate's own Y or an already-accepted nearby position's Yz- world z-coordinateclearance- the number of open blocks required above the surfacesearchRadius- the maximum number of blocks to search in either direction fromstartYstore- the chunk store to query- Returns:
- the nearest qualifying surface Y, or
INVALID_HEIGHTif none is found or the chunk is not loaded
-
getBlockId
Returns the block type ID at the given world position, orBlockType.UNKNOWN_IDif the chunk section is not loaded.- Parameters:
x- world x-coordinatey- world y-coordinatez- world z-coordinatestore- the chunk store to query- Returns:
- the block type ID, or
BlockType.UNKNOWN_ID
-
getFluidId
Returns the fluid ID at the given world position, orFluid.EMPTY_IDif the chunk section is not loaded or contains no fluid.- Parameters:
x- world x-coordinatey- world y-coordinatez- world z-coordinatestore- the chunk store to query- Returns:
- the fluid ID, or
Fluid.EMPTY_ID
-