mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 19:05:02 -04:00
fluids: dynamic velocity multiplier
This commit is contained in:
parent
0d07ae8d42
commit
1cdc0b03bf
@ -615,7 +615,7 @@ class LocalPlayerEntity(
|
||||
get() = (onGround && fallDistance < PhysicsConstants.STEP_HEIGHT) && !connection.world.isSpaceEmpty(aabb + Vec3(0.0f, fallDistance - PhysicsConstants.STEP_HEIGHT, 0.0f))
|
||||
|
||||
|
||||
private fun updateFluidState(fluidType: ResourceLocation, velocityMultiplier: Float): Boolean {
|
||||
private fun updateFluidState(fluidType: ResourceLocation): Boolean {
|
||||
val aabb = aabb.shrink()
|
||||
|
||||
var height = 0.0f
|
||||
@ -624,13 +624,15 @@ class LocalPlayerEntity(
|
||||
val velocity = Vec3d.EMPTY
|
||||
var checks = 0
|
||||
|
||||
var velocityMultiplier = 1.0f
|
||||
|
||||
for ((blockPosition, blockState) in connection.world[aabb]) {
|
||||
if (blockState.block !is FluidBlock) {
|
||||
continue
|
||||
}
|
||||
|
||||
if (!connection.inTag(blockState.block.fluid, TagsS2CP.FLUID_TAG_RESOURCE_LOCATION, DefaultFluidTags.WATER_TAG)) { // ToDo: stillFluid
|
||||
|
||||
if (!connection.inTag(blockState.block.fluid, TagsS2CP.FLUID_TAG_RESOURCE_LOCATION, fluidType)) {
|
||||
continue
|
||||
}
|
||||
val fluidHeight = blockPosition.y + blockState.block.getFluidHeight(blockState)
|
||||
@ -652,6 +654,7 @@ class LocalPlayerEntity(
|
||||
if (fluid !is FlowableFluid) {
|
||||
continue
|
||||
}
|
||||
velocityMultiplier = fluid.getVelocityMultiplier(connection, blockState, blockPosition)
|
||||
val fluidVelocity = fluid.getVelocity(connection, blockState, blockPosition)
|
||||
|
||||
if (height < 0.4) {
|
||||
@ -686,7 +689,7 @@ class LocalPlayerEntity(
|
||||
return // ToDo
|
||||
}
|
||||
|
||||
if (updateFluidState(DefaultFluidTags.WATER_TAG, 0.014f)) {
|
||||
if (updateFluidState(DefaultFluidTags.WATER_TAG)) {
|
||||
// Log.log(LogMessageType.OTHER, LogLevels.VERBOSE){"In Water: Yes"}
|
||||
return
|
||||
// ToDo
|
||||
|
@ -21,13 +21,16 @@ import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
||||
import glm_.vec3.Vec3d
|
||||
import glm_.vec3.Vec3i
|
||||
|
||||
open class FlowableFluid(
|
||||
abstract class FlowableFluid(
|
||||
override val resourceLocation: ResourceLocation,
|
||||
registries: Registries,
|
||||
data: JsonObject,
|
||||
) : Fluid(resourceLocation, registries, data) {
|
||||
open val flowingTexture: ResourceLocation? = null
|
||||
|
||||
|
||||
abstract fun getVelocityMultiplier(connection: PlayConnection, blockState: BlockState, blockPosition: Vec3i): Float
|
||||
|
||||
fun getVelocity(connection: PlayConnection, blockState: BlockState, blockPosition: Vec3i): Vec3d {
|
||||
// ToDo
|
||||
return Vec3d.EMPTY
|
||||
|
@ -35,7 +35,6 @@ open class Fluid(
|
||||
private val bucketItemId = data["bucket"]?.asInt
|
||||
val dripParticle: ParticleType? = data["drip_particle_type"]?.asInt?.let { registries.particleTypeRegistry[it] }
|
||||
open val stillTexture: ResourceLocation? = null
|
||||
open val flowingTexture: ResourceLocation? = null
|
||||
var bucketItem: Item? = null
|
||||
private set
|
||||
|
||||
@ -51,7 +50,8 @@ open class Fluid(
|
||||
return other == this
|
||||
}
|
||||
|
||||
open fun matches(other: BlockState): Boolean {
|
||||
open fun matches(other: BlockState?): Boolean {
|
||||
other ?: return false
|
||||
if (other.block !is FluidBlock) {
|
||||
return false
|
||||
}
|
||||
|
@ -15,10 +15,14 @@ package de.bixilon.minosoft.data.registries.fluid.lava
|
||||
|
||||
import com.google.gson.JsonObject
|
||||
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||
import de.bixilon.minosoft.data.registries.blocks.BlockState
|
||||
import de.bixilon.minosoft.data.registries.fluid.FlowableFluid
|
||||
import de.bixilon.minosoft.data.registries.fluid.Fluid
|
||||
import de.bixilon.minosoft.data.registries.versions.Registries
|
||||
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
||||
import de.bixilon.minosoft.util.KUtil.asResourceLocation
|
||||
import de.bixilon.minosoft.util.KUtil.decide
|
||||
import glm_.vec3.Vec3i
|
||||
|
||||
class LavaFluid(
|
||||
resourceLocation: ResourceLocation,
|
||||
@ -28,6 +32,10 @@ class LavaFluid(
|
||||
override val stillTexture: ResourceLocation = "minecraft:block/lava_still".asResourceLocation()
|
||||
override val flowingTexture: ResourceLocation = "minecraft:block/lava_flow".asResourceLocation()
|
||||
|
||||
override fun getVelocityMultiplier(connection: PlayConnection, blockState: BlockState, blockPosition: Vec3i): Float {
|
||||
return (connection.world.dimension?.ultraWarm == true).decide(0.007f, 0.0023333333333333335f)
|
||||
}
|
||||
|
||||
override fun matches(other: Fluid): Boolean {
|
||||
return other::class.java.isAssignableFrom(LavaFluid::class.java)
|
||||
}
|
||||
|
@ -36,11 +36,16 @@ class WaterFluid(
|
||||
override val stillTexture: ResourceLocation = "minecraft:block/water_still".asResourceLocation()
|
||||
override val flowingTexture: ResourceLocation = "minecraft:block/water_flow".asResourceLocation()
|
||||
|
||||
override fun getVelocityMultiplier(connection: PlayConnection, blockState: BlockState, blockPosition: Vec3i): Float {
|
||||
return VELOCITY_MULTIPLIER
|
||||
}
|
||||
|
||||
override fun matches(other: Fluid): Boolean {
|
||||
return other::class.java.isAssignableFrom(WaterFluid::class.java)
|
||||
}
|
||||
|
||||
override fun matches(other: BlockState): Boolean {
|
||||
override fun matches(other: BlockState?): Boolean {
|
||||
other ?: return false
|
||||
if (other.properties[BlockProperties.WATERLOGGED] == true) {
|
||||
return true
|
||||
}
|
||||
@ -54,4 +59,8 @@ class WaterFluid(
|
||||
// ToDo
|
||||
connection.world += UnderwaterParticle(connection, blockPosition.toVec3d + { random.nextDouble() })
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val VELOCITY_MULTIPLIER = 0.014f
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import de.bixilon.minosoft.data.registries.biomes.Biome
|
||||
import de.bixilon.minosoft.data.registries.blocks.BlockState
|
||||
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties
|
||||
import de.bixilon.minosoft.data.registries.blocks.types.Block
|
||||
import de.bixilon.minosoft.data.registries.fluid.FlowableFluid
|
||||
import de.bixilon.minosoft.data.registries.fluid.Fluid
|
||||
import de.bixilon.minosoft.data.text.RGBColor
|
||||
import de.bixilon.minosoft.data.world.World
|
||||
@ -16,6 +17,7 @@ import de.bixilon.minosoft.gui.rendering.chunk.models.loading.BlockModelElement
|
||||
import de.bixilon.minosoft.gui.rendering.chunk.models.loading.BlockModelFace
|
||||
import de.bixilon.minosoft.gui.rendering.textures.Texture
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.plus
|
||||
import de.bixilon.minosoft.util.KUtil.nullCast
|
||||
import glm_.glm
|
||||
import glm_.vec2.Vec2
|
||||
import glm_.vec3.Vec3
|
||||
@ -59,7 +61,7 @@ class FluidRenderer(
|
||||
texture = stillTexture ?: return
|
||||
}
|
||||
val neighbourBlocks = context.neighbourBlocks
|
||||
if (isBlockSameFluid(neighbourBlocks[direction.ordinal]) || neighbourBlocks[direction.ordinal]?.getBlockRenderer(context.blockPosition + direction)?.faceBorderSizes?.let { it[direction.inverted.ordinal] != null } == true && direction != Directions.UP) {
|
||||
if (fluid.matches(neighbourBlocks[direction.ordinal]) || neighbourBlocks[direction.ordinal]?.getBlockRenderer(context.blockPosition + direction)?.faceBorderSizes?.let { it[direction.inverted.ordinal] != null } == true && direction != Directions.UP) {
|
||||
continue
|
||||
}
|
||||
val positionTemplate = BlockModelElement.FACE_POSITION_MAP_TEMPLATE[direction.ordinal]
|
||||
@ -142,7 +144,7 @@ class FluidRenderer(
|
||||
}
|
||||
|
||||
private fun calculateHeights(neighbourBlocks: Array<BlockState?>, blockState: BlockState, world: World, position: Vec3i): FloatArray {
|
||||
if (isBlockSameFluid(neighbourBlocks[Directions.UP.ordinal])) {
|
||||
if (fluid.matches(neighbourBlocks[Directions.UP.ordinal])) {
|
||||
return floatArrayOf(1f, 1f, 1f, 1f)
|
||||
}
|
||||
val height = getLevel(blockState)
|
||||
@ -156,7 +158,7 @@ class FluidRenderer(
|
||||
}
|
||||
|
||||
private fun handleDirectNeighbours(neighbourBlocks: Array<BlockState?>, direction: Directions, world: World, position: Vec3i, positions: MutableSet<Int>, heights: FloatArray) {
|
||||
if (isBlockSameFluid(neighbourBlocks[direction.ordinal])) {
|
||||
if (fluid.matches(neighbourBlocks[direction.ordinal])) {
|
||||
val neighbourLevel = getLevel(neighbourBlocks[direction.ordinal]!!)
|
||||
for (heightPosition in positions) {
|
||||
heights[heightPosition] = glm.max(heights[heightPosition], neighbourLevel)
|
||||
@ -164,7 +166,7 @@ class FluidRenderer(
|
||||
}
|
||||
for (altDirection in direction.sidesNextTo(direction)) {
|
||||
val bothDirections = setOf(direction, altDirection)
|
||||
if (isBlockSameFluid(world[position + direction + altDirection])) {
|
||||
if (fluid.matches(world[position + direction + altDirection])) {
|
||||
val neighbourLevel = getLevel(world[position + direction + altDirection]!!)
|
||||
for (heightPosition in HEIGHT_POSITIONS) {
|
||||
if (heightPosition.key.containsAll(bothDirections)) {
|
||||
@ -176,14 +178,14 @@ class FluidRenderer(
|
||||
}
|
||||
|
||||
private fun handleUpperBlocks(world: World, position: Vec3i, direction: Directions, positions: MutableSet<Int>, heights: FloatArray) {
|
||||
if (isBlockSameFluid(world[position + Directions.UP + direction])) {
|
||||
if (fluid.matches(world[position + Directions.UP + direction])) {
|
||||
for (heightPosition in positions) {
|
||||
heights[heightPosition] = 1.0f
|
||||
}
|
||||
}
|
||||
for (altDirection in direction.sidesNextTo(direction)) {
|
||||
val bothDirections = setOf(direction, altDirection)
|
||||
if (isBlockSameFluid(world[position + Directions.UP + direction + altDirection])) {
|
||||
if (fluid.matches(world[position + Directions.UP + direction + altDirection])) {
|
||||
for (heightPosition in HEIGHT_POSITIONS) {
|
||||
if (heightPosition.key.containsAll(bothDirections)) {
|
||||
heights[heightPosition.value] = 1.0f
|
||||
@ -210,22 +212,9 @@ class FluidRenderer(
|
||||
return 0.8125f
|
||||
}
|
||||
|
||||
private fun isBlockSameFluid(blockState: BlockState?): Boolean {
|
||||
if (blockState == null) {
|
||||
return false
|
||||
}
|
||||
if (blockState.properties[BlockProperties.WATERLOGGED] == true) { // ToDo: Lava
|
||||
return true
|
||||
}
|
||||
if (block == blockState.block) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
override fun resolveTextures(textures: MutableMap<ResourceLocation, Texture>) {
|
||||
stillTexture = fluid.stillTexture?.let { Texture.getResourceTextureIdentifier(it.namespace, it.path) }?.let { BlockLikeRenderer.resolveTexture(textures, it) }
|
||||
flowingTexture = fluid.flowingTexture?.let { Texture.getResourceTextureIdentifier(it.namespace, it.path) }?.let { BlockLikeRenderer.resolveTexture(textures, it) }
|
||||
flowingTexture = fluid.nullCast<FlowableFluid>()?.flowingTexture?.let { Texture.getResourceTextureIdentifier(it.namespace, it.path) }?.let { BlockLikeRenderer.resolveTexture(textures, it) }
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
Loading…
x
Reference in New Issue
Block a user