Class CubeDetector
java.lang.Object
org.cyclops.cyclopscore.block.multi.CubeDetector
- Direct Known Subclasses:
HollowCubeDetector
Detector of cubes in a world.
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static interface
static interface
Listener for detections.static interface
-
Constructor Summary
ConstructorDescriptionCubeDetector
(AllowedBlock[] allowedBlocks, List<? extends CubeDetector.IDetectionListener> listeners) Make a new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAllowedBlocks
(AllowedBlock[] allowedBlocks) addSizeValidator
(ISizeValidator sizeValidator) An optional size validator to add.protected boolean
coordinateRecursion
(net.minecraft.world.level.LevelReader world, int[][] dimensionEgdes, int[] accumulatedCoordinates, CubeDetector.BlockPosAction locationAction) Run theCubeDetector.BlockPosAction
for all the possible locations within this structure.protected boolean
coordinateRecursion
(net.minecraft.world.level.LevelReader world, int[][] dimensionEgdes, CubeDetector.BlockPosAction locationAction) Run theCubeDetector.BlockPosAction
for all the possible locations within this structure.detect
(net.minecraft.world.level.LevelReader world, net.minecraft.core.BlockPos startLocation, net.minecraft.core.BlockPos excludeLocation, boolean changeState) Detect a structure at the given start location.detect
(net.minecraft.world.level.LevelReader world, net.minecraft.core.BlockPos startLocation, net.minecraft.core.BlockPos excludeLocation, CubeDetector.IValidationAction action, boolean changeState) Detect a structure at the given start location.List<? extends CubeDetector.IDetectionListener>
protected boolean
isAir
(net.minecraft.world.level.LevelReader world, net.minecraft.core.BlockPos location) protected boolean
isEdge
(net.minecraft.world.level.LevelReader world, int[][] dimensionEgdes, net.minecraft.core.BlockPos location) protected net.minecraft.network.chat.Component
isValidLocation
(net.minecraft.world.level.LevelReader world, net.minecraft.core.BlockPos location, net.minecraft.core.BlockPos excludeLocation) protected net.minecraft.network.chat.Component
isValidLocation
(net.minecraft.world.level.LevelReader world, net.minecraft.core.BlockPos location, CubeDetector.IValidationAction action, net.minecraft.core.BlockPos excludeLocation) protected net.minecraft.core.BlockPos
navigateToBorder
(net.minecraft.world.level.LevelReader world, net.minecraft.core.BlockPos startLocation, int dimension, boolean max, net.minecraft.core.BlockPos excludeLocation) Find the border of valid/non-valid locations in one given dimension (both directions).protected net.minecraft.core.BlockPos
navigateToBorder
(net.minecraft.world.level.LevelReader world, net.minecraft.core.BlockPos startLocation, int dimension, int direction, net.minecraft.core.BlockPos excludeLocation) Find the border of valid/non-valid locations in one given dimension for just one direction.protected net.minecraft.core.BlockPos
navigateToCorner
(net.minecraft.world.level.LevelReader world, net.minecraft.core.BlockPos startLocation, int[] dimensions, boolean max, net.minecraft.core.BlockPos excludeLocation) Navigate to a corner from a given startlocation for the given dimensions.protected void
notifyListeners
(net.minecraft.world.level.LevelReader world, net.minecraft.core.BlockPos location, net.minecraft.core.Vec3i size, boolean valid, net.minecraft.core.BlockPos originCorner) protected void
postValidate
(net.minecraft.world.level.LevelReader world, net.minecraft.core.Vec3i size, int[][] dimensionEgdes, boolean valid, net.minecraft.core.BlockPos originCorner, net.minecraft.core.BlockPos excludeLocation) protected net.minecraft.network.chat.Component
validateAllowedBlockConditions
(net.minecraft.world.level.LevelReader world, net.minecraft.core.BlockPos location) Validate if the blockState at the given location conforms with theAllowedBlock
conditions.protected net.minecraft.network.chat.Component
validateDimensionEdges
(net.minecraft.world.level.LevelReader world, int[][] dimensionEgdes, boolean valid, CubeDetector.IValidationAction action, net.minecraft.core.BlockPos excludeLocation) This will validate if the given structure has full borders and is hollow at the middle.protected net.minecraft.network.chat.Component
validateLocationInStructure
(net.minecraft.world.level.LevelReader world, int[][] dimensionEgdes, net.minecraft.core.BlockPos location, CubeDetector.IValidationAction action, net.minecraft.core.BlockPos excludeLocation) Check if a given location is valid, taking into account the edges of the structure, so that we know which locations should be borders, and which ones should be air.
-
Constructor Details
-
CubeDetector
public CubeDetector(AllowedBlock[] allowedBlocks, List<? extends CubeDetector.IDetectionListener> listeners) Make a new instance.- Parameters:
allowedBlocks
- The blocks that are allowed in this cube.listeners
- Listeners for detections.
-
-
Method Details
-
getAllowedBlocks
- Returns:
- the allowed blocks
-
addAllowedBlocks
- Parameters:
allowedBlocks
- The allowed blocks
-
getSizeValidators
- Returns:
- the size validators
-
addSizeValidator
An optional size validator to add.- Parameters:
sizeValidator
- The validator object to check the size- Returns:
- this instance.
-
getListeners
- Returns:
- the listeners
-
notifyListeners
protected void notifyListeners(net.minecraft.world.level.LevelReader world, net.minecraft.core.BlockPos location, net.minecraft.core.Vec3i size, boolean valid, net.minecraft.core.BlockPos originCorner) -
isValidLocation
protected net.minecraft.network.chat.Component isValidLocation(net.minecraft.world.level.LevelReader world, net.minecraft.core.BlockPos location, CubeDetector.IValidationAction action, net.minecraft.core.BlockPos excludeLocation) -
isValidLocation
protected net.minecraft.network.chat.Component isValidLocation(net.minecraft.world.level.LevelReader world, net.minecraft.core.BlockPos location, net.minecraft.core.BlockPos excludeLocation) -
isAir
protected boolean isAir(net.minecraft.world.level.LevelReader world, net.minecraft.core.BlockPos location) -
isEdge
protected boolean isEdge(net.minecraft.world.level.LevelReader world, int[][] dimensionEgdes, net.minecraft.core.BlockPos location) -
validateLocationInStructure
protected net.minecraft.network.chat.Component validateLocationInStructure(net.minecraft.world.level.LevelReader world, int[][] dimensionEgdes, net.minecraft.core.BlockPos location, CubeDetector.IValidationAction action, net.minecraft.core.BlockPos excludeLocation) Check if a given location is valid, taking into account the edges of the structure, so that we know which locations should be borders, and which ones should be air.- Parameters:
world
- The world.dimensionEgdes
- The edges per dimension. [dimension][start=0 | stop=1]location
- The location to check.action
- The action to execute when a location has been validated.excludeLocation
- The location of the block that is being removed, used for invalidating, null for validating.- Returns:
- If the location was valid.
-
coordinateRecursion
protected boolean coordinateRecursion(net.minecraft.world.level.LevelReader world, int[][] dimensionEgdes, CubeDetector.BlockPosAction locationAction) Run theCubeDetector.BlockPosAction
for all the possible locations within this structure.- Parameters:
world
- The world.dimensionEgdes
- The edges per dimension. [dimension][start=0 | stop=1]locationAction
- The runnable that will be called for each location in the structure.- Returns:
- If the structure is valid for the given edges.
-
coordinateRecursion
protected boolean coordinateRecursion(net.minecraft.world.level.LevelReader world, int[][] dimensionEgdes, int[] accumulatedCoordinates, CubeDetector.BlockPosAction locationAction) Run theCubeDetector.BlockPosAction
for all the possible locations within this structure. When the accumulatedCoordinates size equals the desired amount of dimensions, this recursion will enter a leaf and check the conditions for that location.- Parameters:
world
- The world.dimensionEgdes
- The edges per dimension. [dimension][start=0 | stop=1]accumulatedCoordinates
- The accumulated coordinates up until now.locationAction
- The runnable that will be called for each location in the structure.- Returns:
- If the structure is valid for the given edges.
-
validateAllowedBlockConditions
protected net.minecraft.network.chat.Component validateAllowedBlockConditions(net.minecraft.world.level.LevelReader world, net.minecraft.core.BlockPos location) Validate if the blockState at the given location conforms with theAllowedBlock
conditions.- Parameters:
world
- The world.location
- The location.- Returns:
- Null if the size is valid, otherwise the error message.
-
validateDimensionEdges
protected net.minecraft.network.chat.Component validateDimensionEdges(net.minecraft.world.level.LevelReader world, int[][] dimensionEgdes, boolean valid, CubeDetector.IValidationAction action, net.minecraft.core.BlockPos excludeLocation) This will validate if the given structure has full borders and is hollow at the middle. To initiate the recursion, call this with an empty accumulatedCoordinates array, it will then simulate for loop for every dimension between the start and stop coordinate for that dimension. When the accumulatedCoordinates size equals the desired amount of dimensions, this recursion will enter a leaf and check the conditions for that location.- Parameters:
world
- The world.dimensionEgdes
- The edges per dimension. [dimension][start=0 | stop=1]valid
- True if the structure should be validated, false if it should be invalidated.action
- The action to execute when a location has been validated.excludeLocation
- The location of the block that is being removed, used for invalidating, null for validating.- Returns:
- Null the structure is valid for the given edges, the error otherwise.
-
postValidate
protected void postValidate(net.minecraft.world.level.LevelReader world, net.minecraft.core.Vec3i size, int[][] dimensionEgdes, boolean valid, net.minecraft.core.BlockPos originCorner, net.minecraft.core.BlockPos excludeLocation) -
detect
public DetectionResult detect(net.minecraft.world.level.LevelReader world, net.minecraft.core.BlockPos startLocation, net.minecraft.core.BlockPos excludeLocation, boolean changeState) Detect a structure at the given start location.- Parameters:
world
- The world to look in.startLocation
- The starting location.excludeLocation
- The location of the block that is being removed, used for invalidating, null for validating.changeState
- If the post-validate actions should be called, and thus potentially change the world blockState states.- Returns:
- The size of the found structure. Note that a size in a dimension here starts counting from 0, so a 1x1x1 structure (=1 blockState) will return a size of 0 in each dimension.
-
detect
public DetectionResult detect(net.minecraft.world.level.LevelReader world, net.minecraft.core.BlockPos startLocation, net.minecraft.core.BlockPos excludeLocation, CubeDetector.IValidationAction action, boolean changeState) Detect a structure at the given start location.- Parameters:
world
- The world to look in.startLocation
- The starting location.excludeLocation
- The location of the block that is being removed, used for invalidating, null for validating.action
- The action to execute when a location has been validated.changeState
- If the post-validate actions should be called, and thus potentially change the world blockState states.- Returns:
- The size of the found structure. Note that a size in a dimension here starts counting from 0, so a 1x1x1 structure (=1 blockState) will return a size of 0 in each dimension.
-