diff --git a/src/main/java/de/bixilon/minosoft/data/registries/dimension/DimensionProperties.kt b/src/main/java/de/bixilon/minosoft/data/registries/dimension/DimensionProperties.kt index 23915b904..c46e51ab0 100644 --- a/src/main/java/de/bixilon/minosoft/data/registries/dimension/DimensionProperties.kt +++ b/src/main/java/de/bixilon/minosoft/data/registries/dimension/DimensionProperties.kt @@ -34,23 +34,23 @@ data class DimensionProperties( // val bedWorks: Boolean = true, val effects: DimensionEffects = OverworldEffects, // val hasRaids: Boolean = true, - val logicalHeight: Int = DEFAULT_HEIGHT, + // val logicalHeight: Int = DEFAULT_HEIGHT, // val coordinateScale: Double = 0.0, val minY: Int = 0, // val hasCeiling: Boolean = false, val ultraWarm: Boolean = false, - val dataHeight: Int = DEFAULT_HEIGHT, + val height: Int = DEFAULT_HEIGHT, val supports3DBiomes: Boolean = true, ) { - val maxY = dataHeight + minY - 1 - val sections = dataHeight / ProtocolDefinition.SECTION_HEIGHT_Y + val maxY = height + minY - 1 + val sections = height / ProtocolDefinition.SECTION_HEIGHT_Y val minSection = minY shr 4 val maxSection = (minSection + sections - 1) val brightness = FloatArray(16) 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(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, effects = data["effects"].nullCast()?.let { DefaultDimensionEffects[it.toResourceLocation()] } ?: OverworldEffects, //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, minY = data["min_y"]?.toInt() ?: 0, //hasCeiling = data["has_ceiling"]?.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, ) } diff --git a/src/main/java/de/bixilon/minosoft/data/registries/dimension/effects/OverworldEffects.kt b/src/main/java/de/bixilon/minosoft/data/registries/dimension/effects/OverworldEffects.kt index eb93a7096..faf75d361 100644 --- a/src/main/java/de/bixilon/minosoft/data/registries/dimension/effects/OverworldEffects.kt +++ b/src/main/java/de/bixilon/minosoft/data/registries/dimension/effects/OverworldEffects.kt @@ -30,7 +30,7 @@ object OverworldEffects : DimensionEffects { override val clouds: Boolean get() = true 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) { return 192..196 } diff --git a/src/test/java/de/bixilon/minosoft/data/registries/dimension/DimensionPropertiesTest.kt b/src/test/java/de/bixilon/minosoft/data/registries/dimension/DimensionPropertiesTest.kt new file mode 100644 index 000000000..655f01efb --- /dev/null +++ b/src/test/java/de/bixilon/minosoft/data/registries/dimension/DimensionPropertiesTest.kt @@ -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 . + * + * 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) + } +}