mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 03:15:35 -04:00
use packet biomes
This commit is contained in:
parent
def072e36f
commit
d079184e6e
@ -13,7 +13,7 @@
|
||||
package de.bixilon.minosoft.data.registries.biomes
|
||||
|
||||
import de.bixilon.kotlinglm.func.common.clamp
|
||||
import de.bixilon.kutil.cast.CastUtil.nullCast
|
||||
import de.bixilon.kutil.json.JsonUtil.toJsonObject
|
||||
import de.bixilon.kutil.primitive.FloatUtil.toFloat
|
||||
import de.bixilon.kutil.primitive.IntUtil.toInt
|
||||
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||
@ -21,26 +21,21 @@ import de.bixilon.minosoft.data.registries.registries.Registries
|
||||
import de.bixilon.minosoft.data.registries.registries.registry.RegistryItem
|
||||
import de.bixilon.minosoft.data.registries.registries.registry.codec.ResourceLocationCodec
|
||||
import de.bixilon.minosoft.data.text.formatting.color.RGBColor
|
||||
import de.bixilon.minosoft.data.text.formatting.color.RGBColor.Companion.asRGBColor
|
||||
import de.bixilon.minosoft.gui.rendering.RenderConstants
|
||||
import de.bixilon.minosoft.gui.rendering.tint.TintManager
|
||||
import de.bixilon.minosoft.gui.rendering.tint.TintManager.Companion.jsonTint
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
||||
import java.util.*
|
||||
|
||||
data class Biome(
|
||||
override val resourceLocation: ResourceLocation,
|
||||
val depth: Float,
|
||||
val scale: Float,
|
||||
val temperature: Float,
|
||||
val downfall: Float,
|
||||
val skyColor: RGBColor?,
|
||||
val waterColor: RGBColor?,
|
||||
val waterFogColor: RGBColor?,
|
||||
val category: BiomeCategory,
|
||||
val category: BiomeCategory?,
|
||||
val precipitation: BiomePrecipitation,
|
||||
val skyColor: RGBColor,
|
||||
val descriptionId: String?,
|
||||
val grassColorModifier: GrassColorModifiers = GrassColorModifiers.NONE,
|
||||
) : RegistryItem() {
|
||||
val grassColorModifier = GrassColorModifiers.BIOME_MAP[resourceLocation] ?: GrassColorModifiers.NONE
|
||||
val temperatureColorMapCoordinate = getColorMapCoordinate(temperature)
|
||||
val downfallColorMapCoordinate = getColorMapCoordinate(downfall * temperature)
|
||||
val colorMapPixelIndex = downfallColorMapCoordinate shl 8 or temperatureColorMapCoordinate
|
||||
@ -62,23 +57,21 @@ data class Biome(
|
||||
|
||||
override fun deserialize(registries: Registries?, resourceLocation: ResourceLocation, data: Map<String, Any>): Biome {
|
||||
check(registries != null) { "Registries is null!" }
|
||||
val effects = data["effects"].toJsonObject() // nbt data
|
||||
val skyColor = (data["sky_color"] ?: effects?.get("sky_color"))?.jsonTint()
|
||||
val waterColor = (data["water_color"] ?: effects?.get("water_color"))?.jsonTint()
|
||||
val waterFogColor = (data["water_fog_color"] ?: effects?.get("water_fog_color"))?.jsonTint()
|
||||
|
||||
return Biome(
|
||||
resourceLocation = resourceLocation,
|
||||
depth = data["depth"]?.toFloat() ?: 0.0f,
|
||||
scale = data["scale"]?.toFloat() ?: 0.0f,
|
||||
temperature = data["temperature"]?.toFloat() ?: 0.0f,
|
||||
downfall = data["downfall"]?.toFloat() ?: 0.0f,
|
||||
waterColor = TintManager.getJsonColor(data["water_color"]?.toInt() ?: 0),
|
||||
waterFogColor = TintManager.getJsonColor(data["water_fog_color"]?.toInt() ?: 0),
|
||||
skyColor = skyColor,
|
||||
waterColor = waterColor,
|
||||
waterFogColor = waterFogColor,
|
||||
category = registries.biomeCategoryRegistry[data["category"]?.toInt() ?: -1] ?: DEFAULT_CATEGORY,
|
||||
precipitation = registries.biomePrecipitationRegistry[data["precipitation"]?.toInt() ?: -1] ?: DEFAULT_PRECIPITATION,
|
||||
skyColor = data["sky_color"]?.toInt()?.asRGBColor() ?: RenderConstants.GRASS_FAILOVER_COLOR,
|
||||
descriptionId = data["water_fog_color"].nullCast(),
|
||||
grassColorModifier = data["grass_color_modifier"].nullCast<String>()?.uppercase(Locale.getDefault())?.let { GrassColorModifiers.valueOf(it) } ?: when (resourceLocation) {
|
||||
ResourceLocation("minecraft:swamp"), ResourceLocation("minecraft:swamp_hills") -> GrassColorModifiers.SWAMP
|
||||
ResourceLocation("minecraft:dark_forest"), ResourceLocation("minecraft:dark_forest_hills") -> GrassColorModifiers.DARK_FOREST
|
||||
else -> GrassColorModifiers.NONE
|
||||
}
|
||||
// precipitation = registries.biomePrecipitationRegistry[data["precipitation"]?.toInt() ?: -1] ?: DEFAULT_PRECIPITATION, TODO
|
||||
precipitation = DEFAULT_PRECIPITATION,
|
||||
)
|
||||
}
|
||||
|
||||
@ -87,10 +80,4 @@ data class Biome(
|
||||
|
||||
}
|
||||
|
||||
enum class GrassColorModifiers {
|
||||
NONE,
|
||||
DARK_FOREST,
|
||||
SWAMP,
|
||||
;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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.biomes
|
||||
|
||||
import de.bixilon.minosoft.util.KUtil.minecraft
|
||||
|
||||
object DefaultBiomes {
|
||||
val SWAMP = minecraft("swamp")
|
||||
val SWAMP_HILLS = minecraft("swamp_hills")
|
||||
|
||||
val DARK_FOREST = minecraft("dark_forest")
|
||||
val DARK_FOREST_HILLS = minecraft("dark_forest_hills")
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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.biomes
|
||||
|
||||
import de.bixilon.kutil.enums.EnumUtil
|
||||
import de.bixilon.kutil.enums.ValuesEnum
|
||||
|
||||
enum class GrassColorModifiers {
|
||||
NONE,
|
||||
DARK_FOREST,
|
||||
SWAMP,
|
||||
;
|
||||
|
||||
companion object : ValuesEnum<GrassColorModifiers> {
|
||||
override val VALUES = values()
|
||||
override val NAME_MAP = EnumUtil.getEnumValues(VALUES)
|
||||
|
||||
val BIOME_MAP = mapOf(
|
||||
DefaultBiomes.SWAMP to SWAMP,
|
||||
DefaultBiomes.SWAMP_HILLS to SWAMP,
|
||||
|
||||
DefaultBiomes.DARK_FOREST to DARK_FOREST,
|
||||
DefaultBiomes.DARK_FOREST_HILLS to DARK_FOREST,
|
||||
)
|
||||
}
|
||||
}
|
@ -303,7 +303,7 @@ class Registries {
|
||||
}
|
||||
|
||||
companion object {
|
||||
val IGNORED_REGISTRIES = setOf("minecraft:worldgen/biome".toResourceLocation())
|
||||
val IGNORED_REGISTRIES: Set<ResourceLocation> = setOf()
|
||||
private val PARENTABLE_FIELDS: List<Field>
|
||||
private val PARENTABLE_SET_PARENT_METHOD = Parentable::class.java.getDeclaredMethod("setParent", Any::class.java)
|
||||
private val TYPE_MAP: Map<Class<*>, Field>
|
||||
|
@ -20,6 +20,7 @@ object RegistryFixer : ResourceLocationFixer {
|
||||
private val RENAMES: Map<ResourceLocation, ResourceLocation> = mapOf(
|
||||
"dimension" to "dimension_type",
|
||||
"motive" to "motif",
|
||||
"worldgen/biome" to "biome",
|
||||
).asResourceLocationMap()
|
||||
|
||||
override fun _fix(resourceLocation: ResourceLocation): ResourceLocation {
|
||||
|
@ -16,6 +16,7 @@ package de.bixilon.minosoft.gui.rendering.tint
|
||||
import de.bixilon.minosoft.assets.AssetsManager
|
||||
import de.bixilon.minosoft.assets.util.FileUtil.readRGBArray
|
||||
import de.bixilon.minosoft.data.registries.biomes.Biome
|
||||
import de.bixilon.minosoft.data.registries.biomes.GrassColorModifiers
|
||||
import de.bixilon.minosoft.data.registries.blocks.BlockState
|
||||
import de.bixilon.minosoft.data.text.formatting.color.Colors
|
||||
import de.bixilon.minosoft.gui.rendering.textures.TextureUtil.texture
|
||||
@ -51,9 +52,9 @@ class GrassTintCalculator : TintProvider {
|
||||
val color = getColor(biome.colorMapPixelIndex)
|
||||
|
||||
return when (biome.grassColorModifier) {
|
||||
Biome.GrassColorModifiers.NONE -> color
|
||||
Biome.GrassColorModifiers.SWAMP -> 0x6A7039 // ToDo: Biome noise is applied here
|
||||
Biome.GrassColorModifiers.DARK_FOREST -> (color and 0xFEFEFE) + 0x28340A shr 1
|
||||
GrassColorModifiers.NONE -> color
|
||||
GrassColorModifiers.SWAMP -> 0x6A7039 // ToDo: Biome noise is applied here
|
||||
GrassColorModifiers.DARK_FOREST -> (color and 0xFEFEFE) + 0x28340A shr 1
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
package de.bixilon.minosoft.gui.rendering.tint
|
||||
|
||||
import de.bixilon.kotlinglm.vec3.Vec3i
|
||||
import de.bixilon.kutil.primitive.IntUtil.toInt
|
||||
import de.bixilon.minosoft.assets.AssetsManager
|
||||
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||
import de.bixilon.minosoft.data.registries.biomes.Biome
|
||||
@ -117,5 +118,10 @@ class TintManager(private val connection: PlayConnection) {
|
||||
}
|
||||
return color.asRGBColor()
|
||||
}
|
||||
|
||||
fun Any?.jsonTint(): RGBColor? {
|
||||
val rgb = this?.toInt() ?: return null
|
||||
return getJsonColor(rgb)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user