Skip to content

Commit 8d1a72d

Browse files
authored
fix(PlayerTrap): account epsilon when calculating player hitbox size (#193)
1 parent 303a989 commit 8d1a72d

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/main/kotlin/com/lambda/module/modules/combat/PlayerTrap.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import com.lambda.task.RootTask.run
3030
import com.lambda.task.Task
3131
import com.lambda.task.tasks.BuildTask.Companion.build
3232
import com.lambda.util.BlockUtils.blockState
33+
import com.lambda.util.extension.shrinkByEpsilon
3334
import com.lambda.util.item.ItemUtils.block
3435
import com.lambda.util.math.flooredBlockPos
3536
import com.lambda.util.player.SlotUtils.hotbarAndStorage
@@ -88,8 +89,8 @@ object PlayerTrap : Module(
8889
}
8990

9091
fun SafeContext.getTrapPositions(player: PlayerEntity): Set<BlockPos> {
91-
val min = player.boundingBox.minPos.flooredBlockPos.add(-1, -1, -1)
92-
val max = player.boundingBox.maxPos.flooredBlockPos.add(1, 1, 1)
92+
val min = player.boundingBox.shrinkByEpsilon().minPos.flooredBlockPos.add(-1, -1, -1)
93+
val max = player.boundingBox.shrinkByEpsilon().maxPos.flooredBlockPos.add(1, 1, 1)
9394

9495
return buildSet {
9596
(min.x + 1..<max.x).forEach { x ->

src/main/kotlin/com/lambda/util/extension/Box.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,7 @@ import net.minecraft.util.math.Vec3d
2323
val Box.min get() = Vec3d(minX, minY, minZ)
2424
val Box.max get() = Vec3d(maxX, maxY, maxZ)
2525

26+
fun Box.shrinkByEpsilon(): Box = expand(-1e-7)
27+
2628
operator fun Box.contains(boundingBox: Box) = this.intersects(boundingBox)
2729
operator fun DoubleArray.component6() = this[5]

0 commit comments

Comments
 (0)