Skip to content

Commit

Permalink
Added a BlockPlacerCallback to feature & structure to allow plugins t…
Browse files Browse the repository at this point in the history
…o intercept place method
  • Loading branch information
nmacl committed Oct 5, 2024
1 parent 41c571c commit 72fcf9e
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,35 @@ public interface Feature extends DefaultedRegistryValue {
DataView toContainer();

/**
* Places the feature at given position and world
*
* @param world The world
* @param pos The position
*
* @return true when the feature was successfully placed
*/
boolean place(ServerWorld world, Vector3i pos);
* Functional interface to handle block placement during feature generation.
*/
@FunctionalInterface
interface BlockPlacerCallback {
/**
* Called when a block is being placed during feature generation.
* @param location The location of the block being placed
* @param block The block being placed
* @return True to allow the block placement, false to skip the block.
*/
boolean onBlockPlace(ServerLocation location, Block block);
}

/**
* Places the feature at given location
*
* @param location The location
*
* @return true when the feature was successfully placed
*/
boolean place(ServerLocation location);
/**
* Places the feature at the given position in the world, using the provided callback for block placement.
* @param world The world where the feature will be placed
* @param pos The position where the feature will be placed
* @param callback The callback for handling block placement.
* @return true if the feature was successfully placed
*/
boolean place(ServerWorld world, Vector3i pos, BlockPlacerCallback callback);


/**
* Places the feature at the given location, using the provided callback for block placement.
* @param location The location where the feature will be placed
* @param callback The callback for handling block placement.
* @return true if the feature was successfully placed
*/
boolean place(ServerLocation location, BlockPlacerCallback callback);

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,37 @@
public interface Structure extends DefaultedRegistryValue {

/**
* Places the structure at given position and world
*
* @param world The world
* @param pos The position
*
* @return true when the feature was successfully placed
*/
boolean place(ServerWorld world, Vector3i pos);
* Functional interface to handle block placement during structure generation.
*/
@FunctionalInterface
interface BlockPlacerCallback {
/**
* Called when a block is being placed during structure generation.
* @param location The location of the block being placed
* @param block The block being placed
* @return True to allow the block placement, false to skip the block.
*/
boolean onBlockPlace(ServerLocation location, Block block);
}


/**
* Places the structure at given location
*
* @param location The location
*
* @return true when the feature was successfully placed
*/
boolean place(ServerLocation location);
* Places the structure at given position and world using a callback for each block placed.
* @param world The world
* @param pos The position
* @param callback The callback for handling block placement.
* @return true if the structure was successfully placed
*/
boolean place(ServerWorld world, Vector3i pos, BlockPlacerCallback callback);


/**
* Places the structure at given location using a callback for each block placed.
* @param location The location
* @param callback The callback for handling block placement.
* @return true if the structure was successfully placed
*/
boolean place(ServerLocation location, BlockPlacerCallback callback);

/**
* Returns the biomes the structure is allowed in.
Expand Down

0 comments on commit 72fcf9e

Please sign in to comment.