@@ -32,6 +32,16 @@ class GroundProximityComputer(computers: ComputerBus) : Computer(computers), Fli
3232 var obstacleImpactStatus: Status = Status .SAFE
3333 private set
3434
35+ private var anyBlocksAbove = false
36+ val safeThreshold: Double
37+ get() = if (anyBlocksAbove) 7.5 else 10.0
38+ val cautionThreshold: Double
39+ get() = if (anyBlocksAbove) 7.5 else 10.0
40+ val warningThreshold: Double
41+ get() = if (anyBlocksAbove) 7.5 else 10.0
42+ val recoverThreshold: Double
43+ get() = if (anyBlocksAbove) 7.5 else 10.0
44+
3545 var groundY: Double? = null
3646 val groundOrVoidY: Double
3747 get() = if (groundY == null || groundY == Double .MAX_VALUE ) computers.data.voidY.toDouble()
@@ -54,19 +64,15 @@ class GroundProximityComputer(computers: ComputerBus) : Computer(computers), Fli
5464 return
5565 }
5666
57- val anyBlocksAbove: Boolean = data.level.getHeight(Heightmap .Types .MOTION_BLOCKING , data.player.blockX, data.player.blockZ) > data.player.y
58- val clearThreshold: Double = if (anyBlocksAbove) 7.5 else 10.0
59- val cautionThreshold: Double = if (anyBlocksAbove) 3.0 else 7.5
60- val warningThreshold: Double = if (anyBlocksAbove) 1.5 else 3.0
61- val recoverThreshold = 0.75
67+ anyBlocksAbove = data.level.getHeight(Heightmap .Types .MOTION_BLOCKING , data.player.blockX, data.player.blockZ) > data.player.y
6268
6369 groundImpactTime = computeGroundImpactTime(data).throwIfNotInRange(0.0 .. Double .MAX_VALUE )
6470 groundImpactStatus =
6571 if (data.fallDistanceSafe) {
6672 Status .SAFE
6773 } else if (groundImpactStatus == Status .SAFE && (data.velocityPerSecond.y > - 10 || groundImpactTime > cautionThreshold)) {
6874 Status .SAFE
69- } else if (data.velocityPerSecond.y > - 8.5 || groundImpactTime > clearThreshold ) {
75+ } else if (data.velocityPerSecond.y > - 8.5 || groundImpactTime > safeThreshold ) {
7076 Status .SAFE
7177 } else if (groundImpactStatus >= Status .CAUTION && groundImpactTime > warningThreshold) {
7278 Status .CAUTION
@@ -76,15 +82,15 @@ class GroundProximityComputer(computers: ComputerBus) : Computer(computers), Fli
7682 Status .RECOVER
7783 }
7884
79- obstacleImpactTime = computeObstacleImpactTime(data, clearThreshold ).throwIfNotInRange(0.0 .. Double .MAX_VALUE )
85+ obstacleImpactTime = computeObstacleImpactTime(data, safeThreshold ).throwIfNotInRange(0.0 .. Double .MAX_VALUE )
8086
8187 val damageOnCollision: Double = data.velocity.horizontalDistance() * 10 - 3
8288 obstacleImpactStatus =
8389 if (data.isInvulnerableTo(data.player.damageSources().flyIntoWall())) {
8490 Status .SAFE
8591 } else if (obstacleImpactStatus == Status .SAFE && (damageOnCollision < data.player.health * 0.5f || obstacleImpactTime > groundImpactTime * 1.1f || obstacleImpactTime > cautionThreshold)) {
8692 Status .SAFE
87- } else if (damageOnCollision < data.player.health * 0.25f || obstacleImpactTime > groundImpactTime * 1.2f || obstacleImpactTime > clearThreshold ) {
93+ } else if (damageOnCollision < data.player.health * 0.25f || obstacleImpactTime > groundImpactTime * 1.2f || obstacleImpactTime > safeThreshold ) {
8894 Status .SAFE
8995 } else if (obstacleImpactStatus >= Status .CAUTION && obstacleImpactTime > warningThreshold) {
9096 Status .CAUTION
@@ -120,20 +126,24 @@ class GroundProximityComputer(computers: ComputerBus) : Computer(computers), Fli
120126
121127 private fun computeObstacleImpactTime (data : AirDataComputer , lookAheadTime : Double ): Double {
122128 val end: Vec3 = data.position.add(data.forwardVelocityPerSecond.multiply(lookAheadTime, 0.0 , lookAheadTime))
123- val result: BlockHitResult = data.level.clip(
129+ return computeObstacleImpactTime(end, computers.data.forwardVelocityPerSecond)
130+ }
131+
132+ fun computeObstacleImpactTime (raycastEnd : Vec3 , velocity : Vec3 ): Double {
133+ val result: BlockHitResult = computers.data.level.clip(
124134 ClipContext (
125- data.position,
126- end ,
135+ computers. data.position,
136+ raycastEnd ,
127137 ClipContext .Block .COLLIDER ,
128138 ClipContext .Fluid .ANY ,
129- data.player
139+ computers. data.player
130140 )
131141 )
132142 if (result.type != HitResult .Type .BLOCK ) {
133143 return Double .MAX_VALUE
134144 }
135145
136- return data.position.distanceTo(result.location) / data.forwardVelocityPerSecond .length()
146+ return computers. data.position.distanceTo(result.location) / velocity .length()
137147 }
138148
139149 override fun <Response > handleQuery (query : ComputerQuery <Response >) {
@@ -195,6 +205,7 @@ class GroundProximityComputer(computers: ComputerBus) : Computer(computers), Fli
195205 groundImpactStatus = Status .SAFE
196206 obstacleImpactTime = Double .MAX_VALUE
197207 obstacleImpactStatus = Status .SAFE
208+ anyBlocksAbove = false
198209 groundY = null
199210 }
200211
0 commit comments