Skip to content

Commit

Permalink
Improved documentation & made some small improvements to appendShapes…
Browse files Browse the repository at this point in the history
… and appendShapesTo function
  • Loading branch information
Mystery2099 committed Nov 2, 2023
1 parent cff1cad commit cb1599a
Showing 1 changed file with 72 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,29 @@ import net.minecraft.util.function.BooleanBiFunction
import net.minecraft.util.shape.VoxelShape
import net.minecraft.util.shape.VoxelShapes

/**
* A utility object for working with VoxelShapes in Minecraft game development.
*
* This object provides various functions for creating, combining, and modifying VoxelShapes,
* which are used to represent the collision and shape of objects in the game world.
*/
object VoxelAssembly {

/**
* Create a cuboid shape using any type of number
* @param minX
* @param minY
* @param minZ
* @param maxX
* @param maxY
* @param maxZ
* Creates a cuboid shape using the provided minimum and maximum coordinates.
*
* Each param should be between 0 and 16
* @param minX The minimum X-coordinate of the cuboid.
* @param minY The minimum Y-coordinate of the cuboid.
* @param minZ The minimum Z-coordinate of the cuboid.
* @param maxX The maximum X-coordinate of the cuboid.
* @param maxY The maximum Y-coordinate of the cuboid.
* @param maxZ The maximum Z-coordinate of the cuboid.
*
* @return A VoxelShape representing the cuboid shape.
*
* @see Block.createCuboidShape
**/
*/
fun createCuboidShape(
minX: Number,
minY: Number,
Expand All @@ -34,68 +45,88 @@ object VoxelAssembly {
)

/**
* Combines 2 the receiver and [otherShape].
* @param otherShape The [VoxelShape] to be unified with the receiver.
* @receiver [VoxelShape]
* Combines the receiver VoxelShape with another VoxelShape using the union operation.
*
* @param otherShape The VoxelShape to be unified with the receiver.
*
* @return A new VoxelShape representing the union of the two input shapes.
*
* @see VoxelShapes.union
* @see plus
* */
*/
infix fun VoxelShape.and(otherShape: VoxelShape): VoxelShape = VoxelShapes.union(this, otherShape)

/**
* Allows the use of + and += to combine [VoxelShape]s
* @param otherShape
* Allows the use of the '+' and '+=' operators to combine VoxelShapes.
*
* @param otherShape The VoxelShape to be combined with the receiver using the union operation.
*
* @return A new VoxelShape representing the union of the two input shapes.
*
* @see VoxelShapes.union
* @see and
* */
*/
infix operator fun VoxelShape.plus(otherShape: VoxelShape): VoxelShape = this and otherShape

/**
* Combines a single [VoxelShape] with all the given [VoxelShape]s
* Combines a single VoxelShape with a list of other VoxelShapes using the [VoxelAssembly.union] operation.
*
* @param otherShapes A list of VoxelShapes to be unified with the receiver.
*
* @return A new VoxelShape representing the union of all input shapes.
*
* @see union
* */
*/
fun VoxelShape.UnifyWith(vararg otherShapes: VoxelShape): VoxelShape = union(this, *otherShapes)


/**
* Combines a list of shape using the given function.
* @param function
* @param voxelShapes
* @return
* Combines a list of VoxelShapes using the provided boolean function.
*
* @param function The boolean function used for combining VoxelShapes.
* @param voxelShapes A list of VoxelShapes to be combined.
*
* @return A new VoxelShape resulting from the combination of the input shapes.
*
* @see VoxelShapes.combine
* */
*/
fun combine(function: BooleanBiFunction, vararg voxelShapes: VoxelShape): VoxelShape {
return voxelShapes.reduce { a, b -> VoxelShapes.combine(a, b, function) }
}

/**
* Unifies or combines the given list of [voxelShapes].
* @param voxelShapes A list of [VoxelShape] which should be unified.
* @return the unified [voxelShapes]
* Unifies or combines a list of VoxelShapes into a single VoxelShape.
*
* @param voxelShapes A list of VoxelShapes to be unified.
*
* @return A new VoxelShape representing the union of all input shapes.
*
* @see VoxelShapes.union
* */
*/
fun union(vararg voxelShapes: VoxelShape): VoxelShape = voxelShapes.reduce(VoxelShapes::union)

/**
* Stores the given [shape] in a new [VoxelShapeModifier] instance
* which can then be used to cleanly combine shapes conditionally.
* @return the new [shape] after being modified using [configure].
* @param shape The [VoxelShape] which should be stored in [configure] to be modified.
* @param configure The function used to modify [shape] and return the modified [VoxelShape]
* Stores the given VoxelShape in a new VoxelShapeModifier instance, which can be used to cleanly combine shapes conditionally.
*
* @param shape The VoxelShape to be stored in the VoxelShapeModifier for modification.
* @param configure The function used to modify the shape and return the modified VoxelShape.
*
* @see appendShapes
**/
fun appendShapesTo(shape: VoxelShape, configure: VoxelShapeModifier.() -> VoxelShape): VoxelShape {
return configure(VoxelShapeModifier(shape))
*/
fun appendShapesTo(shape: VoxelShape, configure: VoxelShapeModifier.() -> Unit): VoxelShape {
val builder = VoxelShapeModifier(shape)
builder.configure()
return builder.storedShape
}

/**
* The [VoxelShape] version of [appendShapesTo].
* Stores the receiver in a new [VoxelShapeModifier] instance which can then be used to cleanly and conditionally combine [VoxelShape]s.
* @return The modified version of the receiver.
* @param configurer The function which will be used to modify the receiver
* The VoxelShape version of appendShapesTo, allowing the receiver to be modified using a VoxelShapeModifier.
*
* @param configurer The function used to modify the receiver VoxelShape.
*
* @see appendShapes
* */
infix fun VoxelShape.appendShapes(configurer: VoxelShapeModifier.() -> VoxelShape): VoxelShape {
*/
infix fun VoxelShape.appendShapes(configurer: VoxelShapeModifier.() -> Unit): VoxelShape {
return appendShapesTo(this, configurer)
}

}

0 comments on commit cb1599a

Please sign in to comment.