mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 03:15:35 -04:00
Kutil: improve Any to Int converting
This commit is contained in:
parent
6553f8ad2b
commit
d4779f0f89
@ -21,6 +21,7 @@ import de.bixilon.minosoft.data.registries.AABB
|
||||
import de.bixilon.minosoft.data.world.OcclusionUpdateCallback
|
||||
import de.bixilon.minosoft.data.world.chunk.Chunk
|
||||
import de.bixilon.minosoft.data.world.chunk.ChunkNeighbours
|
||||
import de.bixilon.minosoft.data.world.positions.InChunkSectionPosition
|
||||
import de.bixilon.minosoft.gui.rendering.RenderConstants
|
||||
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
||||
import de.bixilon.minosoft.gui.rendering.camera.Camera
|
||||
@ -140,7 +141,7 @@ class WorldVisibilityGraph(
|
||||
return frustum.containsAABB(aabb)
|
||||
}
|
||||
|
||||
fun isSectionVisible(chunkPosition: Vec2i, sectionHeight: Int, minPosition: Vec3i = DEFAULT_MIN_POSITION, maxPosition: Vec3i = ProtocolDefinition.CHUNK_SECTION_SIZE, checkChunk: Boolean = true): Boolean {
|
||||
fun isSectionVisible(chunkPosition: Vec2i, sectionHeight: Int, minPosition: InChunkSectionPosition = DEFAULT_MIN_POSITION, maxPosition: InChunkSectionPosition = ProtocolDefinition.CHUNK_SECTION_SIZE, checkChunk: Boolean = true): Boolean {
|
||||
if (checkChunk && !isChunkVisible(chunkPosition)) {
|
||||
return false
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ object KUtil {
|
||||
return when (this) {
|
||||
is String -> ResourceLocation(this)
|
||||
is ResourceLocation -> this
|
||||
else -> TODO("Don't know how to turn $this into a resource location!")
|
||||
else -> throw IllegalArgumentException("Don't know how to turn $this into a resource location!")
|
||||
}
|
||||
}
|
||||
|
||||
@ -217,6 +217,17 @@ object KUtil {
|
||||
return null
|
||||
}
|
||||
|
||||
private inline fun String.checkInt(): Int? {
|
||||
var first = true
|
||||
for (point in codePoints()) {
|
||||
if (point < '0'.code || point > '9'.code || (first && point == '-'.code)) {
|
||||
return null
|
||||
}
|
||||
first = false
|
||||
}
|
||||
return this.toInt()
|
||||
}
|
||||
|
||||
fun Any?.autoType(): Any? {
|
||||
if (this == null) {
|
||||
return null
|
||||
@ -233,10 +244,7 @@ object KUtil {
|
||||
return false
|
||||
}
|
||||
|
||||
// ToDo: Optimize
|
||||
if (string.matches("\\d+".toRegex())) {
|
||||
return string.toInt()
|
||||
}
|
||||
string.checkInt()?.let { return it }
|
||||
|
||||
return string
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user