From f1a87aac253ec4a15db31799f900cb59c3a4809a Mon Sep 17 00:00:00 2001 From: Bixilon Date: Tue, 1 Nov 2022 20:04:11 +0100 Subject: [PATCH] SkyProperties --- .../dimension/DimensionProperties.kt | 8 +++- .../sky/properties/DefaultSkyProperties.kt | 22 ++++++++++ .../sky/properties/EndSkyProperties.kt | 38 +++++++++++++++++ .../sky/properties/NetherSkyProperties.kt | 35 ++++++++++++++++ .../sky/properties/OverworldSkyProperties.kt | 41 +++++++++++++++++++ .../rendering/sky/properties/SkyProperties.kt | 34 +++++++++++++++ .../minosoft/util/ResourceLocationMap.kt | 41 +++++++++++++++++++ 7 files changed, 217 insertions(+), 2 deletions(-) create mode 100644 src/main/java/de/bixilon/minosoft/gui/rendering/sky/properties/DefaultSkyProperties.kt create mode 100644 src/main/java/de/bixilon/minosoft/gui/rendering/sky/properties/EndSkyProperties.kt create mode 100644 src/main/java/de/bixilon/minosoft/gui/rendering/sky/properties/NetherSkyProperties.kt create mode 100644 src/main/java/de/bixilon/minosoft/gui/rendering/sky/properties/OverworldSkyProperties.kt create mode 100644 src/main/java/de/bixilon/minosoft/gui/rendering/sky/properties/SkyProperties.kt create mode 100644 src/main/java/de/bixilon/minosoft/util/ResourceLocationMap.kt 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 538252c22..ccdc0f496 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 @@ -19,7 +19,11 @@ import de.bixilon.kutil.primitive.BooleanUtil.toBoolean import de.bixilon.kutil.primitive.FloatUtil.toFloat import de.bixilon.kutil.primitive.IntUtil.toInt import de.bixilon.minosoft.data.registries.ResourceLocation +import de.bixilon.minosoft.gui.rendering.sky.properties.DefaultSkyProperties +import de.bixilon.minosoft.gui.rendering.sky.properties.OverworldSkyProperties +import de.bixilon.minosoft.gui.rendering.sky.properties.SkyProperties import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition +import de.bixilon.minosoft.util.KUtil.toResourceLocation import de.bixilon.minosoft.util.nbt.tag.NBTUtil.get data class DimensionProperties( @@ -30,7 +34,7 @@ data class DimensionProperties( val respawnAnchorWorks: Boolean = false, val hasSkyLight: Boolean = true, val bedWorks: Boolean = true, - val skyProperties: ResourceLocation = ResourceLocation("overworld"), + val skyProperties: SkyProperties = OverworldSkyProperties, val hasRaids: Boolean = true, val logicalHeight: Int = DEFAULT_HEIGHT, val coordinateScale: Double = 0.0, @@ -79,7 +83,7 @@ data class DimensionProperties( respawnAnchorWorks = data["respawn_anchor_works"]?.toBoolean() ?: false, hasSkyLight = data["has_skylight", "has_sky_light"]?.toBoolean() ?: false, bedWorks = data["bed_works"]?.toBoolean() ?: false, - skyProperties = ResourceLocation(data["effects"].nullCast() ?: "overworld"), + skyProperties = data["effects"].nullCast()?.let { DefaultSkyProperties[it.toResourceLocation()] } ?: OverworldSkyProperties, hasRaids = data["has_raids"]?.toBoolean() ?: false, logicalHeight = data["logical_height"]?.toInt() ?: DEFAULT_MAX_Y, coordinateScale = data["coordinate_scale"].nullCast() ?: 0.0, diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/sky/properties/DefaultSkyProperties.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/sky/properties/DefaultSkyProperties.kt new file mode 100644 index 000000000..c24d38fc5 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/sky/properties/DefaultSkyProperties.kt @@ -0,0 +1,22 @@ +/* + * 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.gui.rendering.sky.properties + +import de.bixilon.minosoft.util.ResourceLocationMap + +object DefaultSkyProperties : ResourceLocationMap( + OverworldSkyProperties, + NetherSkyProperties, + EndSkyProperties, +) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/sky/properties/EndSkyProperties.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/sky/properties/EndSkyProperties.kt new file mode 100644 index 000000000..5e5115670 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/sky/properties/EndSkyProperties.kt @@ -0,0 +1,38 @@ +/* + * 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.gui.rendering.sky.properties + +import de.bixilon.kutil.exception.Broken +import de.bixilon.minosoft.data.registries.ResourceLocation +import de.bixilon.minosoft.gui.rendering.textures.TextureUtil.texture +import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection +import de.bixilon.minosoft.util.KUtil.minecraft + +object EndSkyProperties : SkyProperties { + override val resourceLocation = minecraft("the_end") + + override val daylightCycle: Boolean get() = false + override val fixedTexture: ResourceLocation = minecraft("environment/end_sky").texture() + + override val sun: Boolean get() = false + override val moon: Boolean get() = false + override val stars: Boolean get() = false + + override val clouds: Boolean get() = false + override fun getCloudHeight(connection: PlayConnection): IntRange = Broken() + + override val fullbright: Boolean get() = true + + override val fog: Boolean get() = false +} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/sky/properties/NetherSkyProperties.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/sky/properties/NetherSkyProperties.kt new file mode 100644 index 000000000..d81c44f70 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/sky/properties/NetherSkyProperties.kt @@ -0,0 +1,35 @@ +/* + * 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.gui.rendering.sky.properties + +import de.bixilon.kutil.exception.Broken +import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection +import de.bixilon.minosoft.util.KUtil.minecraft + +object NetherSkyProperties : SkyProperties { + override val resourceLocation = minecraft("the_nether") + + override val daylightCycle: Boolean get() = false + + override val sun: Boolean get() = false + override val moon: Boolean get() = false + override val stars: Boolean get() = false + + override val clouds: Boolean get() = false + override fun getCloudHeight(connection: PlayConnection): IntRange = Broken() + + override val fullbright: Boolean get() = true + + override val fog: Boolean get() = true +} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/sky/properties/OverworldSkyProperties.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/sky/properties/OverworldSkyProperties.kt new file mode 100644 index 000000000..84d11989e --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/sky/properties/OverworldSkyProperties.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.gui.rendering.sky.properties + +import de.bixilon.minosoft.data.registries.dimension.DimensionProperties +import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection +import de.bixilon.minosoft.util.KUtil.minecraft + +object OverworldSkyProperties : SkyProperties { + override val resourceLocation = minecraft("overworld") + + override val daylightCycle: Boolean get() = true + + override val sun: Boolean get() = true + override val moon: Boolean get() = true + override val stars: Boolean get() = true + + override val clouds: Boolean get() = true + override fun getCloudHeight(connection: PlayConnection): IntRange { + val height = connection.world.dimension?.dataHeight ?: DimensionProperties.DEFAULT_HEIGHT + if (height > DimensionProperties.DEFAULT_HEIGHT) { + return 192..196 + } + return 128..132 + } + + override val fullbright: Boolean get() = false + + override val fog: Boolean get() = true +} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/sky/properties/SkyProperties.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/sky/properties/SkyProperties.kt new file mode 100644 index 000000000..332e72bb4 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/sky/properties/SkyProperties.kt @@ -0,0 +1,34 @@ +/* + * 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.gui.rendering.sky.properties + +import de.bixilon.minosoft.data.registries.ResourceLocation +import de.bixilon.minosoft.data.registries.ResourceLocationAble +import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection + +interface SkyProperties : ResourceLocationAble { + val daylightCycle: Boolean + val fixedTexture: ResourceLocation? get() = null + + val sun: Boolean + val moon: Boolean + val stars: Boolean + + val clouds: Boolean + fun getCloudHeight(connection: PlayConnection): IntRange + + val fullbright: Boolean get() = false + + val fog: Boolean +} diff --git a/src/main/java/de/bixilon/minosoft/util/ResourceLocationMap.kt b/src/main/java/de/bixilon/minosoft/util/ResourceLocationMap.kt new file mode 100644 index 000000000..753e08891 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/util/ResourceLocationMap.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.util + +import de.bixilon.minosoft.data.registries.MultiResourceLocationAble +import de.bixilon.minosoft.data.registries.ResourceLocation +import de.bixilon.minosoft.data.registries.ResourceLocationAble + +open class ResourceLocationMap(vararg entries: T) : Iterable { + private val entries: MutableMap = mutableMapOf() + + init { + for (factory in entries) { + this.entries[factory.resourceLocation] = factory + if (factory is MultiResourceLocationAble) { + for (resourceLocation in factory.ALIASES) { + this.entries[resourceLocation] = factory + } + } + } + } + + operator fun get(resourceLocation: ResourceLocation): T? { + return this.entries[resourceLocation] + } + + override fun iterator(): Iterator { + return this.entries.values.iterator() + } +}