hibiscus/src/main/kotlin/codes/som/hibiscus/features/movement/Flight.kt

87 lines
2.7 KiB
Kotlin
Raw Normal View History

package codes.som.hibiscus.features.movement
import codes.som.hibiscus.api.feature.Feature
import codes.som.hibiscus.api.feature.FeatureCategory
import codes.som.hibiscus.events.NetworkMovingEvent
import codes.som.hibiscus.events.PlayerTickEvent
import codes.som.hibiscus.events.SendPacketEvent
import codes.som.hibiscus.mc
import codes.som.hibiscus.mixins.MixinExtUpdatePlayerAbilitiesC2SPacket
import codes.som.hibiscus.player
import codes.som.hibiscus.util.ext.requireExtension
import codes.som.hibiscus.world
import net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket
import net.minecraft.network.packet.c2s.play.UpdatePlayerAbilitiesC2SPacket
import net.minecraft.util.shape.VoxelShape
class Flight : Feature("Flight", FeatureCategory.MOVEMENT) {
private var flyKickCounter = 0
private var lockY = 0.0
init {
on { _: PlayerTickEvent ->
player.abilities.flying = true
}
2022-02-03 20:47:25 +00:00
val spoofAbilityPackets by values.bool("Spoof Outgoing Ability Packets", true)
2022-02-04 11:49:58 +00:00
val vanillaKickBypass by values.bool("Vanilla Kick Bypass", true)
on { event: SendPacketEvent ->
val (packet) = event
2022-02-03 20:47:25 +00:00
if (!spoofAbilityPackets)
return@on
if (packet is UpdatePlayerAbilitiesC2SPacket) {
requireExtension<MixinExtUpdatePlayerAbilitiesC2SPacket>(packet)
packet.setFlying(player.abilities.allowFlying)
}
if (packet is ClientCommandC2SPacket) {
if (packet.mode == ClientCommandC2SPacket.Mode.PRESS_SHIFT_KEY) {
event.cancel()
}
}
}
on { event: NetworkMovingEvent ->
if (!vanillaKickBypass)
return@on
flyKickCounter++
if (flyKickCounter >= 16) {
if (flyKickCounter == 16)
lockY = event.y - 0.03126
2022-02-04 11:49:58 +00:00
val playerNotColliding = world.getBlockCollisions(
null, player.boundingBox
.offset(0.0, lockY - player.y, 0.0)
.expand(0.0625)
.stretch(0.0, -0.55, 0.0)
).all(VoxelShape::isEmpty)
if (playerNotColliding)
event.y = lockY
}
if (flyKickCounter >= 24)
flyKickCounter = 0
}
}
override fun onEnable() {
if (mc.player != null)
lockY = player.y - 0.03126
}
override fun onDisable() {
player.abilities.flying = false
}
2022-02-03 22:02:35 +00:00
override fun createFeatureCommand() =
super.createFeatureCommand().apply {
alias("fly")
}
}