From b88928d58af82abdb280022308e388a5226dfb47 Mon Sep 17 00:00:00 2001 From: videogame hacker Date: Mon, 14 Feb 2022 03:16:15 +0000 Subject: [PATCH] Add a vclip command --- .../som/hibiscus/commands/CommandRegistry.kt | 1 + .../codes/som/hibiscus/commands/Vclip.kt | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 src/main/kotlin/codes/som/hibiscus/commands/Vclip.kt diff --git a/src/main/kotlin/codes/som/hibiscus/commands/CommandRegistry.kt b/src/main/kotlin/codes/som/hibiscus/commands/CommandRegistry.kt index 16e706d..8065d9b 100644 --- a/src/main/kotlin/codes/som/hibiscus/commands/CommandRegistry.kt +++ b/src/main/kotlin/codes/som/hibiscus/commands/CommandRegistry.kt @@ -5,6 +5,7 @@ import codes.som.hibiscus.api.command.CommandManager fun allCommandClasses(): Array<() -> Command> = arrayOf( ::Reload, + ::Vclip, ) class CommandRegistry : CommandManager() { diff --git a/src/main/kotlin/codes/som/hibiscus/commands/Vclip.kt b/src/main/kotlin/codes/som/hibiscus/commands/Vclip.kt new file mode 100644 index 0000000..409794b --- /dev/null +++ b/src/main/kotlin/codes/som/hibiscus/commands/Vclip.kt @@ -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) + } + } + } +}