Skip to content

Commit

Permalink
BlockBounce code improvements. (CCBlueX#624)
Browse files Browse the repository at this point in the history
* Cleaned up and improved BlockBounce module code.

* Removed useless imports.
  • Loading branch information
mems01 authored Aug 12, 2021
1 parent 56158d0 commit 8a06ae6
Showing 1 changed file with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ import net.ccbluex.liquidbounce.event.PlayerJumpEvent
import net.ccbluex.liquidbounce.event.handler
import net.ccbluex.liquidbounce.features.module.Category
import net.ccbluex.liquidbounce.features.module.Module
import net.ccbluex.liquidbounce.utils.block.getBlock
import net.ccbluex.liquidbounce.utils.block.getState
import net.ccbluex.liquidbounce.utils.block.isBlockAtPosition
import net.minecraft.block.BedBlock
import net.minecraft.block.Block
import net.minecraft.block.HoneyBlock
import net.minecraft.block.SlimeBlock

Expand All @@ -40,15 +38,15 @@ object ModuleBlockBounce : Module("BlockBounce", Category.MOVEMENT) {
private val motion by float("Motion", 0.42f, 0.2f..2f)

val jumpHandler = handler<PlayerJumpEvent> { event ->
val bouncingBlock = player.blockPos.down().getBlock() ?: return@handler
val block = player.blockPos.getState()?.block ?: return@handler

if (bouncingBlock is SlimeBlock || isBouncingBlock(block)) {
if (standingOnBouncyBlock()) {
event.motion += motion
}
}

private fun isBouncingBlock(block: Block): Boolean {
return block is BedBlock || block is HoneyBlock
fun standingOnBouncyBlock(): Boolean {
val boundingBox = player.boundingBox
val detectionBox = boundingBox.withMinY(boundingBox.minY - 0.01)

return isBlockAtPosition(detectionBox) { it is SlimeBlock || it is BedBlock || it is HoneyBlock }
}
}

0 comments on commit 8a06ae6

Please sign in to comment.