Use NetworkMovingEvent instead of SendPacketEvents in NoFall, NoSprint

This commit is contained in:
Charlotte Som 2022-03-12 02:45:49 +00:00
parent 04186c4d1e
commit 008b70c02c
4 changed files with 5 additions and 33 deletions

View file

@ -1,13 +0,0 @@
package codes.som.hibiscus.mixins;
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(PlayerMoveC2SPacket.class)
public interface MixinExtPlayerMoveC2SPacket {
@Accessor
@Mutable
void setOnGround(boolean onGround);
}

View file

@ -2,19 +2,11 @@ package codes.som.hibiscus.features.player
import codes.som.hibiscus.api.feature.Feature import codes.som.hibiscus.api.feature.Feature
import codes.som.hibiscus.api.feature.FeatureCategory import codes.som.hibiscus.api.feature.FeatureCategory
import codes.som.hibiscus.events.SendPacketEvent import codes.som.hibiscus.events.NetworkMovingEvent
import codes.som.hibiscus.mixins.MixinExtPlayerMoveC2SPacket
import codes.som.hibiscus.util.ext.requireExtension
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket
class NoFallDamage : Feature("No Fall Damage", FeatureCategory.PLAYER) { class NoFallDamage : Feature("No Fall Damage", FeatureCategory.PLAYER) {
init { init {
on { (packet): SendPacketEvent -> on<NetworkMovingEvent> { it.onGround = false }
if (packet is PlayerMoveC2SPacket) {
requireExtension<MixinExtPlayerMoveC2SPacket>(packet)
packet.setOnGround(true)
}
}
} }
override fun createFeatureCommand() = override fun createFeatureCommand() =

View file

@ -2,19 +2,13 @@ package codes.som.hibiscus.features.player
import codes.som.hibiscus.api.feature.Feature import codes.som.hibiscus.api.feature.Feature
import codes.som.hibiscus.api.feature.FeatureCategory import codes.som.hibiscus.api.feature.FeatureCategory
import codes.som.hibiscus.events.SendPacketEvent import codes.som.hibiscus.events.NetworkMovingEvent
import codes.som.hibiscus.player import codes.som.hibiscus.player
import net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket
class NoSprintingPacket : Feature("No Sprinting Packet", FeatureCategory.PLAYER) { class NoSprintingPacket : Feature("No Sprinting Packet", FeatureCategory.PLAYER) {
init { init {
on { event: SendPacketEvent -> on<NetworkMovingEvent>(cond = { !player.isTouchingWater }) {
val (packet) = event it.sprinting = false
if (packet is ClientCommandC2SPacket) {
if (packet.mode == ClientCommandC2SPacket.Mode.START_SPRINTING && !player.isTouchingWater) {
event.cancel()
}
}
} }
hiddenInOverlay = true hiddenInOverlay = true

View file

@ -15,7 +15,6 @@
"MixinExtEntity", "MixinExtEntity",
"MixinExtMinecraftClient", "MixinExtMinecraftClient",
"MixinExtPlayerInteractEntityC2SPacket", "MixinExtPlayerInteractEntityC2SPacket",
"MixinExtPlayerMoveC2SPacket",
"MixinExtUpdatePlayerAbilitiesC2SPacket", "MixinExtUpdatePlayerAbilitiesC2SPacket",
"MixinGameRenderer", "MixinGameRenderer",
"MixinKeyboard", "MixinKeyboard",