collisions: remove current block if stuck in block

This commit is contained in:
Bixilon 2021-06-13 18:32:17 +02:00
parent 301d3da729
commit 5d926aa623
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
2 changed files with 14 additions and 1 deletions

View File

@ -20,6 +20,7 @@ import de.bixilon.minosoft.gui.rendering.chunk.VoxelShape
import de.bixilon.minosoft.gui.rendering.chunk.models.AABB import de.bixilon.minosoft.gui.rendering.chunk.models.AABB
import de.bixilon.minosoft.gui.rendering.util.VecUtil.EMPTY import de.bixilon.minosoft.gui.rendering.util.VecUtil.EMPTY
import de.bixilon.minosoft.gui.rendering.util.VecUtil.chunkPosition import de.bixilon.minosoft.gui.rendering.util.VecUtil.chunkPosition
import de.bixilon.minosoft.gui.rendering.util.VecUtil.floor
import de.bixilon.minosoft.gui.rendering.util.VecUtil.inChunkPosition import de.bixilon.minosoft.gui.rendering.util.VecUtil.inChunkPosition
import de.bixilon.minosoft.protocol.network.connection.PlayConnection import de.bixilon.minosoft.protocol.network.connection.PlayConnection
import glm_.vec3.Vec3 import glm_.vec3.Vec3
@ -31,7 +32,13 @@ class CollisionDetector(val connection: PlayConnection) {
private fun getCollisionsToCheck(deltaPosition: Vec3d, aabb: AABB, ignoreUnloadedChunks: Boolean = true): VoxelShape { 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) // 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 val blockPositions = (aabb extend deltaPosition extend Directions.DOWN grow COLLISION_BOX_MARGIN).blockPositions.toMutableList()
// check if already in block
if (!connection.world.isSpaceEmpty(aabb)) {
blockPositions.remove(aabb.min.floor)
}
val result = VoxelShape() val result = VoxelShape()
for (blockPosition in blockPositions) { for (blockPosition in blockPositions) {
val chunk = connection.world[blockPosition.chunkPosition] val chunk = connection.world[blockPosition.chunkPosition]

View File

@ -73,6 +73,12 @@ class VoxelShape(private val aabbs: MutableList<AABB> = mutableListOf()) : Itera
} }
} }
fun remove(voxelShape: VoxelShape) {
for (newAABB in voxelShape.aabbs) {
aabbs.remove(newAABB)
}
}
fun computeOffset(other: AABB, offset: Double, axis: Axes): Double { fun computeOffset(other: AABB, offset: Double, axis: Axes): Double {
var result = offset var result = offset
for (aabb in aabbs) { for (aabb in aabbs) {