mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 11:54:59 -04:00
dimension properties: fix crash when dimension has exactly one section
+ rename some properties + test
This commit is contained in:
parent
344ad83055
commit
72dfeb7557
@ -34,23 +34,23 @@ data class DimensionProperties(
|
|||||||
// val bedWorks: Boolean = true,
|
// val bedWorks: Boolean = true,
|
||||||
val effects: DimensionEffects = OverworldEffects,
|
val effects: DimensionEffects = OverworldEffects,
|
||||||
// val hasRaids: Boolean = true,
|
// val hasRaids: Boolean = true,
|
||||||
val logicalHeight: Int = DEFAULT_HEIGHT,
|
// val logicalHeight: Int = DEFAULT_HEIGHT,
|
||||||
// val coordinateScale: Double = 0.0,
|
// val coordinateScale: Double = 0.0,
|
||||||
val minY: Int = 0,
|
val minY: Int = 0,
|
||||||
// val hasCeiling: Boolean = false,
|
// val hasCeiling: Boolean = false,
|
||||||
val ultraWarm: Boolean = false,
|
val ultraWarm: Boolean = false,
|
||||||
val dataHeight: Int = DEFAULT_HEIGHT,
|
val height: Int = DEFAULT_HEIGHT,
|
||||||
val supports3DBiomes: Boolean = true,
|
val supports3DBiomes: Boolean = true,
|
||||||
) {
|
) {
|
||||||
val maxY = dataHeight + minY - 1
|
val maxY = height + minY - 1
|
||||||
val sections = dataHeight / ProtocolDefinition.SECTION_HEIGHT_Y
|
val sections = height / ProtocolDefinition.SECTION_HEIGHT_Y
|
||||||
val minSection = minY shr 4
|
val minSection = minY shr 4
|
||||||
val maxSection = (minSection + sections - 1)
|
val maxSection = (minSection + sections - 1)
|
||||||
|
|
||||||
val brightness = FloatArray(16)
|
val brightness = FloatArray(16)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
check(maxSection > minSection) { "Upper section can not be lower that the lower section ($minSection > $maxSection)" }
|
check(maxSection >= minSection) { "Upper section can not be lower that the lower section ($minSection > $maxSection)" }
|
||||||
check(minSection in ProtocolDefinition.CHUNK_MIN_SECTION..ProtocolDefinition.CHUNK_MAX_SECTION) { "Minimum section out of bounds: $minSection" }
|
check(minSection in ProtocolDefinition.CHUNK_MIN_SECTION..ProtocolDefinition.CHUNK_MAX_SECTION) { "Minimum section out of bounds: $minSection" }
|
||||||
check(maxSection in ProtocolDefinition.CHUNK_MIN_SECTION..ProtocolDefinition.CHUNK_MAX_SECTION) { "Maximum section out of bounds: $minSection" }
|
check(maxSection in ProtocolDefinition.CHUNK_MIN_SECTION..ProtocolDefinition.CHUNK_MAX_SECTION) { "Maximum section out of bounds: $minSection" }
|
||||||
|
|
||||||
@ -76,12 +76,12 @@ data class DimensionProperties(
|
|||||||
//bedWorks = data["bed_works"]?.toBoolean() ?: false,
|
//bedWorks = data["bed_works"]?.toBoolean() ?: false,
|
||||||
effects = data["effects"].nullCast<String>()?.let { DefaultDimensionEffects[it.toResourceLocation()] } ?: OverworldEffects,
|
effects = data["effects"].nullCast<String>()?.let { DefaultDimensionEffects[it.toResourceLocation()] } ?: OverworldEffects,
|
||||||
//hasRaids = data["has_raids"]?.toBoolean() ?: false,
|
//hasRaids = data["has_raids"]?.toBoolean() ?: false,
|
||||||
logicalHeight = data["logical_height"]?.toInt() ?: DEFAULT_MAX_Y,
|
// logicalHeight = data["logical_height"]?.toInt() ?: DEFAULT_MAX_Y,
|
||||||
//coordinateScale = data["coordinate_scale"].nullCast() ?: 0.0,
|
//coordinateScale = data["coordinate_scale"].nullCast() ?: 0.0,
|
||||||
minY = data["min_y"]?.toInt() ?: 0,
|
minY = data["min_y"]?.toInt() ?: 0,
|
||||||
//hasCeiling = data["has_ceiling"]?.toBoolean() ?: false,
|
//hasCeiling = data["has_ceiling"]?.toBoolean() ?: false,
|
||||||
ultraWarm = data["ultrawarm"]?.toBoolean() ?: false,
|
ultraWarm = data["ultrawarm"]?.toBoolean() ?: false,
|
||||||
dataHeight = data["height"]?.toInt() ?: DEFAULT_MAX_Y,
|
height = data["height"]?.toInt() ?: DEFAULT_MAX_Y,
|
||||||
supports3DBiomes = data["supports_3d_biomes"]?.toBoolean() ?: true,
|
supports3DBiomes = data["supports_3d_biomes"]?.toBoolean() ?: true,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ object OverworldEffects : DimensionEffects {
|
|||||||
|
|
||||||
override val clouds: Boolean get() = true
|
override val clouds: Boolean get() = true
|
||||||
override fun getCloudHeight(connection: PlayConnection): IntRange {
|
override fun getCloudHeight(connection: PlayConnection): IntRange {
|
||||||
val height = connection.world.dimension?.dataHeight ?: DimensionProperties.DEFAULT_HEIGHT
|
val height = connection.world.dimension?.height ?: DimensionProperties.DEFAULT_HEIGHT
|
||||||
if (height > DimensionProperties.DEFAULT_HEIGHT) {
|
if (height > DimensionProperties.DEFAULT_HEIGHT) {
|
||||||
return 192..196
|
return 192..196
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.bixilon.minosoft.data.registries.dimension
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
|
||||||
|
class DimensionPropertiesTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun create1SectionHigh() {
|
||||||
|
val minY = 0
|
||||||
|
val height = 16
|
||||||
|
val properties = DimensionProperties(minY = minY, height = height)
|
||||||
|
assertEquals(1, properties.sections)
|
||||||
|
assertEquals(0, properties.maxSection)
|
||||||
|
assertEquals(15, properties.maxY)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun negativeY() {
|
||||||
|
val minY = -16
|
||||||
|
val height = 32
|
||||||
|
val properties = DimensionProperties(minY = minY, height = height)
|
||||||
|
assertEquals(2, properties.sections)
|
||||||
|
assertEquals(0, properties.maxSection)
|
||||||
|
assertEquals(15, properties.maxY)
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user