Regions¶
Region¶
Generally, a region is an area between a min and a max Location.
The Region companion object provides several utility functions for creating regions, such as:
Region.surrounding(block, radius)Region.inFrontOf(tileEntity, ...)- and more
Visualization¶
To display the outline of this region with particles, you can use the VisualRegion object:
// to show the region:
VisualRegion.showRegion(player, regionUUID, region)
// to hide the region
VisualRegion.hideRegion(player, regionUUID)
// to toggle on / off
VisualRegion.toggleView(player, regionUUID, region)
If you want a "Visualize Region" button in your GUI, you can use the VisualizeRegionItem:
Dynamic Region¶
A DynamicRegion is a type of region intended for use in tile-entities: Using a MutableProvider<Int> for the size, the region can be dynamically resized. It provides several gui-components to inspect, modify, and visualize the region.
Using TileEntity#storedRegion, we can create a DynamicRegion:
class ExampleTileEntity(block: Block, blockState: NovaBlockState, data: Compound) : TileEntity(block, blockState, data) {
private val region = storedRegion(
"region",
minSize = provider(1), // (1)!
maxSize = provider(10), // (2)!
defaultSize = 5, // (3)!
createRegion = { size -> Region.surrounding(block, size) } // (4)!
)
override val menu = TileEntityMenu.cachedWindow {
upperGui by gui(
"v . . . . . . . .",
". . + . d . - . .",
". . . . . . . . ."
) {
'+' by region.increaseSizeItem
'-' by region.decreaseSizeItem
'd' by region.displaySizeItem
'v' by region.visualizeRegionItem
}
}
}
- The minimum size of the region.
- The maximum size of the region.
- The default size of the region when it is created. After that, the size can be changed and changes will be saved.
- A lambda that creates the desired region based on the configured size. This is invoked every time the size is changed.