fluid models

This commit is contained in:
Bixilon 2022-12-13 13:08:41 +01:00
parent 7de2e4322a
commit bc9bead69c
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
10 changed files with 147 additions and 26 deletions

View File

@ -24,18 +24,13 @@ import de.bixilon.minosoft.data.registries.blocks.types.FluidBlock
import de.bixilon.minosoft.data.registries.blocks.types.FluidFilled
import de.bixilon.minosoft.data.registries.blocks.types.FluidHolder
import de.bixilon.minosoft.data.registries.registries.registry.RegistryItem
import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.AbstractTexture
import de.bixilon.minosoft.gui.rendering.tint.TintProvider
import de.bixilon.minosoft.gui.rendering.models.unbaked.fluid.FluidModel
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import java.util.*
import kotlin.math.abs
open class Fluid(override val resourceLocation: ResourceLocation) : RegistryItem() {
open val tintProvider: TintProvider? = null
open val stillTextureName: ResourceLocation? = null
open val flowingTextureName: ResourceLocation? = null
var stillTexture: AbstractTexture? = null
var flowingTexture: AbstractTexture? = null
open var model: FluidModel? = null
override fun toString(): String {
return resourceLocation.full
@ -85,4 +80,8 @@ open class Fluid(override val resourceLocation: ResourceLocation) : RegistryItem
}
return velocity
}
open fun createModel(): FluidModel? {
return null
}
}

View File

@ -29,19 +29,17 @@ import de.bixilon.minosoft.data.registries.fluid.fluids.Fluid
import de.bixilon.minosoft.data.registries.fluid.fluids.flowable.FlowableFluid
import de.bixilon.minosoft.data.registries.particle.ParticleType
import de.bixilon.minosoft.data.registries.registries.Registries
import de.bixilon.minosoft.gui.rendering.models.unbaked.fluid.fluids.LavaFluidModel
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.lava.LavaParticle
import de.bixilon.minosoft.gui.rendering.util.VecUtil.horizontal
import de.bixilon.minosoft.gui.rendering.util.VecUtil.plus
import de.bixilon.minosoft.gui.rendering.util.VecUtil.toVec3d
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.util.KUtil.minecraft
import de.bixilon.minosoft.util.KUtil.toResourceLocation
import java.util.*
open class LavaFluid(resourceLocation: ResourceLocation = this.resourceLocation) : FlowableFluid(resourceLocation) {
private val lavaParticleType: ParticleType = unsafeNull()
override val stillTextureName: ResourceLocation = "minecraft:block/lava_still".toResourceLocation()
override val flowingTextureName: ResourceLocation = "minecraft:block/lava_flow".toResourceLocation()
init {
this::lavaParticleType.inject(LavaParticle)
@ -91,6 +89,10 @@ open class LavaFluid(resourceLocation: ResourceLocation = this.resourceLocation)
}
}
override fun createModel(): LavaFluidModel {
return LavaFluidModel()
}
companion object : FluidFactory<LavaFluid>, MultiResourceLocationAble {
override val resourceLocation = minecraft("lava")
override val resourceLocations = setOf(minecraft("flowing_lava"))

View File

@ -28,22 +28,16 @@ import de.bixilon.minosoft.data.registries.fluid.FluidFactory
import de.bixilon.minosoft.data.registries.fluid.fluids.Fluid
import de.bixilon.minosoft.data.registries.fluid.fluids.flowable.FlowableFluid
import de.bixilon.minosoft.data.registries.registries.Registries
import de.bixilon.minosoft.gui.rendering.models.unbaked.fluid.fluids.WaterFluidModel
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.water.UnderwaterParticle
import de.bixilon.minosoft.gui.rendering.tint.TintProvider
import de.bixilon.minosoft.gui.rendering.tint.WaterTintProvider
import de.bixilon.minosoft.gui.rendering.util.VecUtil.plus
import de.bixilon.minosoft.gui.rendering.util.VecUtil.toVec3d
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.util.KUtil.minecraft
import de.bixilon.minosoft.util.KUtil.toResourceLocation
import java.util.*
import kotlin.math.min
class WaterFluid(resourceLocation: ResourceLocation = this.resourceLocation) : FlowableFluid(resourceLocation) {
override val stillTextureName: ResourceLocation = "minecraft:block/water_still".toResourceLocation()
override val flowingTextureName: ResourceLocation = "minecraft:block/water_flow".toResourceLocation()
override val tintProvider: TintProvider = WaterTintProvider
override fun getVelocityMultiplier(connection: PlayConnection, blockState: BlockState, blockPosition: Vec3i): Double {
return VELOCITY_MULTIPLIER
@ -124,6 +118,10 @@ class WaterFluid(resourceLocation: ResourceLocation = this.resourceLocation) : F
}
}
override fun createModel(): WaterFluidModel {
return WaterFluidModel()
}
companion object : FluidFactory<WaterFluid>, MultiResourceLocationAble {
override val resourceLocation = minecraft("water")
override val resourceLocations = setOf(minecraft("flowing_water"))

View File

@ -0,0 +1,20 @@
/*
* 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.gui.rendering.models.unbaked.fluid
import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.AbstractTexture
interface FlowableFluidModel : FluidModel {
val flowing: AbstractTexture?
}

View File

@ -0,0 +1,25 @@
/*
* 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.gui.rendering.models.unbaked.fluid
import de.bixilon.minosoft.gui.rendering.RenderWindow
import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.AbstractTexture
import de.bixilon.minosoft.gui.rendering.tint.TintProvider
interface FluidModel {
val tint: TintProvider? get() = null
val still: AbstractTexture?
fun load(context: RenderWindow)
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.gui.rendering.models.unbaked.fluid.fluids
import de.bixilon.minosoft.gui.rendering.RenderWindow
import de.bixilon.minosoft.gui.rendering.models.unbaked.fluid.FlowableFluidModel
import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.AbstractTexture
import de.bixilon.minosoft.gui.rendering.textures.TextureUtil.texture
import de.bixilon.minosoft.util.KUtil.minecraft
class LavaFluidModel : FlowableFluidModel {
override var still: AbstractTexture? = null
override var flowing: AbstractTexture? = null
override fun load(context: RenderWindow) {
still = context.textureManager.staticTextures.createTexture(STILL)
flowing = context.textureManager.staticTextures.createTexture(FLOWING)
}
companion object {
val STILL = minecraft("block/lava_still").texture()
val FLOWING = minecraft("block/lava_flow").texture()
}
}

View File

@ -0,0 +1,39 @@
/*
* 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.gui.rendering.models.unbaked.fluid.fluids
import de.bixilon.minosoft.gui.rendering.RenderWindow
import de.bixilon.minosoft.gui.rendering.models.unbaked.fluid.FlowableFluidModel
import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.AbstractTexture
import de.bixilon.minosoft.gui.rendering.textures.TextureUtil.texture
import de.bixilon.minosoft.gui.rendering.tint.TintProvider
import de.bixilon.minosoft.gui.rendering.tint.WaterTintProvider
import de.bixilon.minosoft.util.KUtil.minecraft
class WaterFluidModel : FlowableFluidModel {
override val tint: TintProvider = WaterTintProvider
override var still: AbstractTexture? = null
override var flowing: AbstractTexture? = null
override fun load(context: RenderWindow) {
still = context.textureManager.staticTextures.createTexture(STILL)
flowing = context.textureManager.staticTextures.createTexture(FLOWING)
}
companion object {
val STILL = minecraft("block/water_still").texture()
val FLOWING = minecraft("block/water_flow").texture()
}
}

View File

@ -61,7 +61,7 @@ class TintManager(private val connection: PlayConnection) {
}
fun getAverageBlockTint(chunk: Chunk, neighbours: Array<Chunk>, blockState: BlockState, fluid: Fluid, x: Int, y: Int, z: Int): IntArray? {
return getAverageBlockTint(chunk, neighbours, blockState, fluid.tintProvider ?: return null, x, y, z)
return getAverageBlockTint(chunk, neighbours, blockState, fluid.model?.tint ?: return null, x, y, z)
}
fun getBlockTint(blockState: BlockState, biome: Biome?, x: Int, y: Int, z: Int): IntArray? {
@ -90,7 +90,7 @@ class TintManager(private val connection: PlayConnection) {
fun getFluidTint(chunk: Chunk, fluid: Fluid, height: Float, x: Int, y: Int, z: Int): Int? {
val biome = chunk.getBiome(x and 0x0F, y, z and 0x0F)
return fluid.tintProvider?.getFluidTint(fluid, biome, height, x, y, z)
return fluid.model?.tint?.getFluidTint(fluid, biome, height, x, y, z)
}

View File

@ -29,7 +29,6 @@ import de.bixilon.minosoft.config.key.KeyBinding
import de.bixilon.minosoft.config.key.KeyCodes
import de.bixilon.minosoft.data.direction.Directions
import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.data.registries.fluid.fluids.flowable.FlowableFluid
import de.bixilon.minosoft.data.world.World
import de.bixilon.minosoft.data.world.chunk.Chunk
import de.bixilon.minosoft.data.world.chunk.ChunkSection
@ -44,7 +43,6 @@ import de.bixilon.minosoft.gui.rendering.system.base.RenderingCapabilities
import de.bixilon.minosoft.gui.rendering.system.base.phases.OpaqueDrawable
import de.bixilon.minosoft.gui.rendering.system.base.phases.TranslucentDrawable
import de.bixilon.minosoft.gui.rendering.system.base.phases.TransparentDrawable
import de.bixilon.minosoft.gui.rendering.textures.TextureUtil.texture
import de.bixilon.minosoft.gui.rendering.util.VecUtil.empty
import de.bixilon.minosoft.gui.rendering.util.VecUtil.inSectionHeight
import de.bixilon.minosoft.gui.rendering.util.VecUtil.of
@ -139,10 +137,12 @@ class WorldRenderer(
renderWindow.modelLoader.load(latch)
for (fluid in connection.registries.fluidRegistry) {
if (fluid is FlowableFluid) {
fluid.flowingTexture = renderWindow.textureManager.staticTextures.createTexture(fluid.flowingTextureName!!.texture())
if (fluid.model != null) {
continue
}
fluid.stillTexture = fluid.stillTextureName?.let { texture -> renderWindow.textureManager.staticTextures.createTexture(texture.texture()) }
val model = fluid.createModel() ?: continue
model.load(renderWindow)
fluid.model = model
}
}

View File

@ -19,6 +19,7 @@ import de.bixilon.kotlinglm.vec2.Vec2
import de.bixilon.kotlinglm.vec2.Vec2i
import de.bixilon.kotlinglm.vec3.Vec3
import de.bixilon.kotlinglm.vec3.Vec3i
import de.bixilon.kutil.cast.CastUtil.nullCast
import de.bixilon.minosoft.data.direction.Directions
import de.bixilon.minosoft.data.registries.blocks.BlockState
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties
@ -33,6 +34,7 @@ import de.bixilon.minosoft.data.world.positions.BlockPositionUtil.positionHash
import de.bixilon.minosoft.gui.rendering.RenderWindow
import de.bixilon.minosoft.gui.rendering.models.CullUtil.canCull
import de.bixilon.minosoft.gui.rendering.models.properties.FaceProperties
import de.bixilon.minosoft.gui.rendering.models.unbaked.fluid.FlowableFluidModel
import de.bixilon.minosoft.gui.rendering.system.base.texture.TextureTransparencies
import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.AbstractTexture
import de.bixilon.minosoft.gui.rendering.textures.TextureUtil.getMesh
@ -80,8 +82,9 @@ class FluidCullSectionPreparer(
blockState.properties[BlockProperties.WATERLOGGED] == true && water != null -> water
else -> continue
}
val stillTexture = fluid.stillTexture ?: continue
val flowingTexture = fluid.flowingTexture ?: continue
val model = fluid.model ?: continue
val stillTexture = model.still ?: continue
val flowingTexture = model.nullCast<FlowableFluidModel>()?.flowing ?: continue // TODO: Non flowable fluids?
val height = fluid.getHeight(blockState)
position = Vec3i(offsetX + x, offsetY + y, offsetZ + z)