mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 10:55:01 -04:00
improve fluid pushing, proper aabb::blockPositions
This commit is contained in:
parent
02f458cff5
commit
9ebaeb6eb0
@ -14,7 +14,6 @@
|
||||
package de.bixilon.minosoft.data.physics
|
||||
|
||||
import de.bixilon.minosoft.data.Axes
|
||||
import de.bixilon.minosoft.data.direction.Directions
|
||||
import de.bixilon.minosoft.data.player.LocalPlayerEntity
|
||||
import de.bixilon.minosoft.gui.rendering.chunk.VoxelShape
|
||||
import de.bixilon.minosoft.gui.rendering.chunk.models.AABB
|
||||
@ -33,7 +32,7 @@ class CollisionDetector(val connection: PlayConnection) {
|
||||
|
||||
private fun getCollisionsToCheck(deltaPosition: Vec3d, aabb: AABB, ignoreUnloadedChunks: Boolean = true): VoxelShape {
|
||||
// also look at blocks further down to also cover blocks with a higher than normal hitbox (for example fences)
|
||||
val blockPositions = (aabb extend deltaPosition extend Directions.DOWN grow COLLISION_BOX_MARGIN).blockPositions.toMutableList()
|
||||
val blockPositions = (aabb extend deltaPosition grow 1.0 + COLLISION_BOX_MARGIN).blockPositions.toMutableList()
|
||||
|
||||
// check if already in block
|
||||
if (!connection.world.isSpaceEmpty(aabb)) {
|
||||
|
@ -60,6 +60,9 @@ import de.bixilon.minosoft.util.KUtil.decide
|
||||
import de.bixilon.minosoft.util.KUtil.nullCast
|
||||
import de.bixilon.minosoft.util.KUtil.synchronizedMapOf
|
||||
import de.bixilon.minosoft.util.MMath
|
||||
import de.bixilon.minosoft.util.logging.Log
|
||||
import de.bixilon.minosoft.util.logging.LogLevels
|
||||
import de.bixilon.minosoft.util.logging.LogMessageType
|
||||
import glm_.func.cos
|
||||
import glm_.func.rad
|
||||
import glm_.func.sin
|
||||
|
@ -70,6 +70,6 @@ abstract class FlowableFluid(
|
||||
|
||||
// ToDo: Falling fluid
|
||||
|
||||
return velocity.normalize() * -1.0
|
||||
return velocity.normalize()
|
||||
}
|
||||
}
|
||||
|
@ -62,11 +62,7 @@ open class Fluid(
|
||||
}
|
||||
|
||||
fun getHeight(blockState: BlockState): Float {
|
||||
val fluidLevel = blockState.properties[BlockProperties.FLUID_LEVEL]?.unsafeCast<Int>() ?: 0
|
||||
if (fluidLevel == 0) {
|
||||
return 1.0f
|
||||
}
|
||||
return fluidLevel / 9.0f
|
||||
return (8 - ((blockState.properties[BlockProperties.FLUID_LEVEL]?.unsafeCast<Int>()) ?: 8)) / 9.0f
|
||||
}
|
||||
|
||||
open fun randomTick(connection: PlayConnection, blockState: BlockState, blockPosition: Vec3i, random: Random) {}
|
||||
|
@ -185,7 +185,7 @@ class World(
|
||||
}
|
||||
|
||||
operator fun get(aabb: AABB): Map<Vec3i, BlockState> {
|
||||
var ret: MutableMap<Vec3i, BlockState> = mutableMapOf()
|
||||
val ret: MutableMap<Vec3i, BlockState> = mutableMapOf()
|
||||
for (position in aabb.blockPositions) {
|
||||
this[position]?.let { ret[position] = it }
|
||||
}
|
||||
|
@ -7,9 +7,9 @@ import de.bixilon.minosoft.gui.rendering.util.VecUtil.EMPTY
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.ONE
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.get
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.toVec3
|
||||
import de.bixilon.minosoft.util.MMath.ceil
|
||||
import de.bixilon.minosoft.util.MMath.floor
|
||||
import glm_.Java.Companion.glm
|
||||
import glm_.func.common.ceil
|
||||
import glm_.func.common.floor
|
||||
import glm_.vec3.Vec3
|
||||
import glm_.vec3.Vec3d
|
||||
import glm_.vec3.Vec3i
|
||||
@ -222,7 +222,7 @@ class AABB(
|
||||
get() = AABB(Vec3.EMPTY, Vec3.EMPTY)
|
||||
|
||||
private fun getRange(min: Double, max: Double): IntRange {
|
||||
return IntRange(min.floor.toInt(), max.ceil.toInt())
|
||||
return IntRange(min.floor, max.ceil - 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
package de.bixilon.minosoft.util
|
||||
|
||||
import de.bixilon.minosoft.util.KUtil.decide
|
||||
import glm_.vec2.Vec2i
|
||||
import kotlin.math.floor
|
||||
|
||||
@ -93,10 +94,21 @@ object MMath {
|
||||
}
|
||||
|
||||
val Boolean.positiveNegative: Int
|
||||
get() =
|
||||
if (this) {
|
||||
1
|
||||
} else {
|
||||
-1
|
||||
}
|
||||
get() = if (this) {
|
||||
1
|
||||
} else {
|
||||
-1
|
||||
}
|
||||
|
||||
val Double.floor: Int
|
||||
get() {
|
||||
val int = this.toInt()
|
||||
return (this < int).decide(int - 1, int)
|
||||
}
|
||||
|
||||
val Double.ceil: Int
|
||||
get() {
|
||||
val int = this.toInt()
|
||||
return (this > int).decide(int + 1, int)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user