Improve code style
This commit is contained in:
@@ -9,15 +9,12 @@ import org.bukkit.Material
|
||||
import org.bukkit.entity.EntityType
|
||||
|
||||
private fun circleEdgeLocations(radius: Number) = HashSet<SimpleLocation2D>().apply {
|
||||
|
||||
val currentRadius = radius.toDouble()
|
||||
|
||||
var d = -currentRadius
|
||||
var x = currentRadius
|
||||
var y = 0
|
||||
|
||||
while (y <= x) {
|
||||
|
||||
addSimpleLoc2D(x, y)
|
||||
addSimpleLoc2D(x, -y)
|
||||
addSimpleLoc2D(-x, y)
|
||||
@@ -34,9 +31,7 @@ private fun circleEdgeLocations(radius: Number) = HashSet<SimpleLocation2D>().ap
|
||||
d += -2 * x + 2
|
||||
x--
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun MutableSet<SimpleLocation2D>.addSimpleLoc2D(first: Number, second: Number) {
|
||||
@@ -44,11 +39,8 @@ private fun MutableSet<SimpleLocation2D>.addSimpleLoc2D(first: Number, second: N
|
||||
}
|
||||
|
||||
abstract class Circle(val radius: Number) {
|
||||
|
||||
protected abstract val data: StructureData
|
||||
|
||||
val fillLocations by lazy {
|
||||
|
||||
var currentRadius = radius.toDouble()
|
||||
|
||||
HashSet<SimpleLocation2D>().apply {
|
||||
@@ -70,17 +62,12 @@ abstract class Circle(val radius: Number) {
|
||||
currentRadius--
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
val edgeLocations by lazy {
|
||||
circleEdgeLocations(radius)
|
||||
}
|
||||
|
||||
val filledStructure by lazy { structure(true) }
|
||||
|
||||
val edgeStructure by lazy { structure(false) }
|
||||
|
||||
fun structure(filled: Boolean) = Structure(
|
||||
HashSet<SingleStructureData>().apply {
|
||||
val locations = if (filled) fillLocations else edgeLocations
|
||||
@@ -88,7 +75,6 @@ abstract class Circle(val radius: Number) {
|
||||
this += SingleStructureData(SimpleLocation3D(it.x, 0, it.y), data)
|
||||
}
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
class MaterialCircle(radius: Number, material: Material) : Circle(radius) {
|
||||
|
@@ -19,35 +19,31 @@ interface StructureData {
|
||||
|
||||
class SingleStructureData(
|
||||
val location: SimpleLocation3D,
|
||||
val structureData: StructureData
|
||||
val structureData: StructureData,
|
||||
)
|
||||
|
||||
data class Structure(
|
||||
val structureData: Set<SingleStructureData>
|
||||
val structureData: Set<SingleStructureData>,
|
||||
) {
|
||||
constructor(vararg structureDataSets: Set<SingleStructureData>)
|
||||
: this(structureDataSets.flatMapTo(HashSet()) { it })
|
||||
}
|
||||
|
||||
/*
|
||||
* Structure data implementations.
|
||||
*/
|
||||
|
||||
data class StructureDataMaterial(
|
||||
val material: Material
|
||||
val material: Material,
|
||||
) : StructureData {
|
||||
|
||||
override fun createAt(loc: Location) {
|
||||
loc.block.type = material
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
data class StructureDataBlock(
|
||||
val material: Material,
|
||||
val blockData: BlockData
|
||||
val blockData: BlockData,
|
||||
) : StructureData {
|
||||
|
||||
constructor(block: Block) : this(block.type, block.blockData)
|
||||
|
||||
override fun createAt(loc: Location) {
|
||||
@@ -56,30 +52,25 @@ data class StructureDataBlock(
|
||||
it.blockData = blockData
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@NMS_General
|
||||
data class StructureDataEntity(
|
||||
val entityType: EntityType,
|
||||
val nbtData: NBTData
|
||||
val nbtData: NBTData,
|
||||
) : StructureData {
|
||||
|
||||
constructor(entity: Entity) : this(entity.type, entity.nbtData)
|
||||
constructor(entityType: EntityType) : this(entityType, NBTData())
|
||||
|
||||
override fun createAt(loc: Location) {
|
||||
loc.spawnCleanEntity(entityType)?.nbtData = nbtData
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
data class StructureDataParticle(
|
||||
val particle: KSpigotParticle
|
||||
val particle: KSpigotParticle,
|
||||
) : StructureData {
|
||||
|
||||
override fun createAt(loc: Location) {
|
||||
particle.spawnAt(loc)
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user