Add a vclip command
This commit is contained in:
parent
f64139b600
commit
b88928d58a
2 changed files with 42 additions and 0 deletions
|
@ -5,6 +5,7 @@ import codes.som.hibiscus.api.command.CommandManager
|
|||
|
||||
fun allCommandClasses(): Array<() -> Command> = arrayOf(
|
||||
::Reload,
|
||||
::Vclip,
|
||||
)
|
||||
|
||||
class CommandRegistry : CommandManager() {
|
||||
|
|
41
src/main/kotlin/codes/som/hibiscus/commands/Vclip.kt
Normal file
41
src/main/kotlin/codes/som/hibiscus/commands/Vclip.kt
Normal file
|
@ -0,0 +1,41 @@
|
|||
package codes.som.hibiscus.commands
|
||||
|
||||
import codes.som.hibiscus.api.command.Command
|
||||
import codes.som.hibiscus.player
|
||||
import codes.som.hibiscus.world
|
||||
|
||||
class Vclip : Command("vclip") {
|
||||
init {
|
||||
branch { y: Double ->
|
||||
player.updatePosition(player.x, player.y + y, player.z)
|
||||
}
|
||||
|
||||
branch("up") {
|
||||
val collisionTests = (2..10).map { n ->
|
||||
world.getBlockCollisions(null, player.boundingBox.offset(0.0, n.toDouble(), 0.0)).all { it.isEmpty }
|
||||
}
|
||||
|
||||
if (collisionTests.all { it }) {
|
||||
player.updatePosition(player.x, player.y + 10, player.z)
|
||||
} else {
|
||||
val n = collisionTests.indexOf(true)
|
||||
if (n != -1)
|
||||
player.updatePosition(player.x, player.y + n + 2, player.z)
|
||||
}
|
||||
}
|
||||
|
||||
branch("down") {
|
||||
val collisionTests = (2..10).map { n ->
|
||||
world.getBlockCollisions(null, player.boundingBox.offset(0.0, -n.toDouble(), 0.0)).all { it.isEmpty }
|
||||
}
|
||||
|
||||
if (collisionTests.all { it }) {
|
||||
player.updatePosition(player.x, player.y - 10, player.z)
|
||||
} else {
|
||||
val n = collisionTests.indexOf(true)
|
||||
if (n != -1)
|
||||
player.updatePosition(player.x, player.y - n - 2, player.z)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue