Skip to content

Commit ea9309f

Browse files
committed
fix(GroundProximityComputer): add back the actually necessary raycast
1 parent 0a8c74e commit ea9309f

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

‎src/main/kotlin/ru/octol1ttle/flightassistant/impl/computer/safety/GroundProximityComputer.kt‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package ru.octol1ttle.flightassistant.impl.computer.safety
22

33
import kotlin.math.abs
44
import kotlin.math.max
5+
import net.minecraft.core.Direction
56
import net.minecraft.network.chat.Component
67
import net.minecraft.resources.ResourceLocation
78
import net.minecraft.world.entity.Entity
@@ -81,12 +82,11 @@ class GroundProximityComputer(computers: ComputerBus) : Computer(computers) {
8182
)
8283
}
8384

84-
private fun raycast(offset: Vec3): BlockHitResult {
85-
return computers.data.level.clip(ClipContext(computers.data.position, computers.data.position.add(offset), ClipContext.Block.COLLIDER, ClipContext.Fluid.ANY, computers.data.player))
85+
private fun raycast(offset: Vec3, startPos: Vec3 = computers.data.position): BlockHitResult {
86+
return computers.data.level.clip(ClipContext(startPos, computers.data.position.add(offset), ClipContext.Block.COLLIDER, ClipContext.Fluid.ANY, computers.data.player))
8687
}
8788

8889
private fun computeGroundY(): Double? {
89-
// TODO: The raycast was not unnecessary... fluids are ignored by collision checks
9090
if (!computers.chunk.isCurrentLoaded || computers.data.player.noPhysics) {
9191
return groundY
9292
}
@@ -105,12 +105,19 @@ class GroundProximityComputer(computers: ComputerBus) : Computer(computers) {
105105
}
106106
val wantedDelta = Vec3(0.0, minY - playerBoundingBox.minY, 0.0)
107107
val allowedDelta = Entity.collideBoundingBox(computers.data.player, wantedDelta, playerBoundingBox, computers.data.level, emptyList())
108+
val collisionY = playerBoundingBox.minY + allowedDelta.y
109+
110+
// Fluids are ignored by collision checks, but not raycasts.
111+
val raycast = raycast(wantedDelta, computers.data.position.with(Direction.Axis.Y, playerBoundingBox.minY))
112+
if (raycast.type == HitResult.Type.BLOCK) {
113+
return max(raycast.location.y, collisionY)
114+
}
108115

109116
if (wantedDelta.y == allowedDelta.y) {
110117
return null
111118
}
112119

113-
return playerBoundingBox.minY + allowedDelta.y
120+
return collisionY
114121
}
115122

116123
private fun computeIsRecoveryUnsafe(): Boolean {

0 commit comments

Comments
 (0)