mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-19 04:15:14 -04:00
fix fluid height calculation
* (and improve performance minimal) * handle waterlogged properly if block is not implemented
This commit is contained in:
parent
47ccaa0613
commit
f253c71f7a
@ -88,9 +88,6 @@ data class BlockState(
|
||||
out.append(block.resourceLocation.toString())
|
||||
out.append(" (")
|
||||
if (properties.isNotEmpty()) {
|
||||
if (out.isNotEmpty()) {
|
||||
out.append(", ")
|
||||
}
|
||||
out.append("properties=")
|
||||
out.append(properties)
|
||||
}
|
||||
|
@ -15,8 +15,8 @@ package de.bixilon.minosoft.data.registries.fluid
|
||||
import de.bixilon.kotlinglm.vec3.Vec3d
|
||||
import de.bixilon.kotlinglm.vec3.Vec3i
|
||||
import de.bixilon.kutil.cast.CastUtil.nullCast
|
||||
import de.bixilon.kutil.cast.CastUtil.unsafeCast
|
||||
import de.bixilon.kutil.cast.CastUtil.unsafeNull
|
||||
import de.bixilon.kutil.primitive.IntUtil.toInt
|
||||
import de.bixilon.minosoft.data.entities.entities.Entity
|
||||
import de.bixilon.minosoft.data.entities.entities.player.local.LocalPlayerEntity
|
||||
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||
@ -73,11 +73,14 @@ open class Fluid(
|
||||
return matches(other.block.fluid)
|
||||
}
|
||||
|
||||
fun getHeight(blockState: BlockState): Float {
|
||||
if (blockState.block is FluidFillable && blockState.block.fluid == this) {
|
||||
return 0.9f
|
||||
open fun getHeight(blockState: BlockState): Float {
|
||||
val level = blockState.properties[BlockProperties.FLUID_LEVEL]?.toInt()
|
||||
if (level == null) {
|
||||
if (blockState.block is FluidFillable && blockState.block.fluid == this) {
|
||||
return 0.9f
|
||||
}
|
||||
throw IllegalArgumentException("Can not get height of non fluid: $blockState")
|
||||
}
|
||||
val level = blockState.properties[BlockProperties.FLUID_LEVEL]?.unsafeCast<Int>() ?: 8
|
||||
if (level < 0 || level >= 8) {
|
||||
return 0.9f
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import de.bixilon.kotlinglm.vec3.Vec3d
|
||||
import de.bixilon.kotlinglm.vec3.Vec3i
|
||||
import de.bixilon.kutil.cast.CastUtil.unsafeNull
|
||||
import de.bixilon.kutil.primitive.BooleanUtil.decide
|
||||
import de.bixilon.kutil.primitive.BooleanUtil.toBoolean
|
||||
import de.bixilon.kutil.random.RandomUtil.chance
|
||||
import de.bixilon.minosoft.data.entities.entities.player.local.LocalPlayerEntity
|
||||
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||
@ -74,6 +75,11 @@ class WaterFluid(
|
||||
return super.matches(other)
|
||||
}
|
||||
|
||||
override fun getHeight(blockState: BlockState): Float {
|
||||
val waterlogged = blockState.properties[BlockProperties.WATERLOGGED]?.toBoolean() ?: return super.getHeight(blockState)
|
||||
return if (waterlogged) 0.9f else 0.0f
|
||||
}
|
||||
|
||||
override fun travel(entity: LocalPlayerEntity, sidewaysSpeed: Float, forwardSpeed: Float, gravity: Double, falling: Boolean) {
|
||||
val y = entity.position.y
|
||||
var speedMultiplier = entity.isSprinting.decide(0.9, 0.8)
|
||||
|
@ -260,25 +260,22 @@ class FluidCullSectionPreparer(
|
||||
var totalHeight = 0.0f
|
||||
var count = 0
|
||||
|
||||
val neighbours = providedChunk.neighbours ?: Broken("neighbours == null")
|
||||
|
||||
for (side in 0 until 4) {
|
||||
val blockPosition = position + Vec3i(-(side and 0x01), 0, -(side shr 1 and 0x01))
|
||||
val chunkPositionOffset = blockPosition.chunkPosition - providedChunkPosition
|
||||
val offset = blockPosition.chunkPosition - providedChunkPosition
|
||||
val chunk = when {
|
||||
chunkPositionOffset.x == 0 && chunkPositionOffset.y == 0 -> providedChunk // most likely, doing this one first
|
||||
chunkPositionOffset.x == -1 && chunkPositionOffset.y == -1 -> providedChunk.neighbours?.get(0)
|
||||
chunkPositionOffset.x == -1 && chunkPositionOffset.y == 0 -> providedChunk.neighbours?.get(1)
|
||||
chunkPositionOffset.x == -1 && chunkPositionOffset.y == 1 -> providedChunk.neighbours?.get(2)
|
||||
chunkPositionOffset.x == 0 && chunkPositionOffset.y == -1 -> providedChunk.neighbours?.get(3)
|
||||
chunkPositionOffset.x == 0 && chunkPositionOffset.y == 1 -> providedChunk.neighbours?.get(4)
|
||||
chunkPositionOffset.x == 1 && chunkPositionOffset.y == -1 -> providedChunk.neighbours?.get(5)
|
||||
chunkPositionOffset.x == 1 && chunkPositionOffset.y == 0 -> providedChunk.neighbours?.get(6)
|
||||
chunkPositionOffset.x == 1 && chunkPositionOffset.y == 1 -> providedChunk.neighbours?.get(7)
|
||||
else -> Broken("Can not get neighbour chunk from offset $chunkPositionOffset")
|
||||
}
|
||||
|
||||
if (chunk == null) {
|
||||
count++
|
||||
continue
|
||||
offset.x == 0 && offset.y == 0 -> providedChunk // most likely, doing this one first
|
||||
offset.x == -1 && offset.y == -1 -> neighbours[0]
|
||||
offset.x == -1 && offset.y == 0 -> neighbours[1]
|
||||
offset.x == -1 && offset.y == 1 -> neighbours[2]
|
||||
offset.x == 0 && offset.y == -1 -> neighbours[3]
|
||||
offset.x == 0 && offset.y == 1 -> neighbours[4]
|
||||
offset.x == 1 && offset.y == -1 -> neighbours[5]
|
||||
offset.x == 1 && offset.y == 0 -> neighbours[6]
|
||||
offset.x == 1 && offset.y == 1 -> neighbours[7]
|
||||
else -> Broken("Can not get neighbour chunk from offset $offset")
|
||||
}
|
||||
|
||||
val inChunkPosition = blockPosition.inChunkPosition
|
||||
|
Loading…
x
Reference in New Issue
Block a user