From 15323b2e4d7d6d6c3a9679648cc610a0e6a8a1df Mon Sep 17 00:00:00 2001 From: videogame hacker Date: Sun, 13 Mar 2022 01:50:20 +0000 Subject: [PATCH] Add Speed Mine, Timer, tweaks to Flight & NoFall --- .../MixinClientPlayerInteractionManager.java | 50 +++++++++++++++++++ .../mixins/MixinExtMinecraftClient.java | 4 ++ .../mixins/MixinExtRenderTickCounter.java | 16 ++++++ .../hibiscus/mixins/MixinPlayerEntity.java | 25 ++++++++++ .../som/hibiscus/commands/CommandRegistry.kt | 1 + .../codes/som/hibiscus/commands/Timer.kt | 19 +++++++ .../codes/som/hibiscus/events/PlayerEvents.kt | 5 ++ .../som/hibiscus/features/FeaturesRegistry.kt | 2 + .../som/hibiscus/features/movement/Flight.kt | 31 ++++++------ .../hibiscus/features/player/NoFallDamage.kt | 2 +- .../som/hibiscus/features/player/SpeedMine.kt | 24 +++++++++ src/main/resources/hibiscus.mixins.json | 3 ++ 12 files changed, 167 insertions(+), 15 deletions(-) create mode 100644 src/main/java/codes/som/hibiscus/mixins/MixinClientPlayerInteractionManager.java create mode 100644 src/main/java/codes/som/hibiscus/mixins/MixinExtRenderTickCounter.java create mode 100644 src/main/java/codes/som/hibiscus/mixins/MixinPlayerEntity.java create mode 100644 src/main/kotlin/codes/som/hibiscus/commands/Timer.kt create mode 100644 src/main/kotlin/codes/som/hibiscus/features/player/SpeedMine.kt diff --git a/src/main/java/codes/som/hibiscus/mixins/MixinClientPlayerInteractionManager.java b/src/main/java/codes/som/hibiscus/mixins/MixinClientPlayerInteractionManager.java new file mode 100644 index 0000000..d8b4cf9 --- /dev/null +++ b/src/main/java/codes/som/hibiscus/mixins/MixinClientPlayerInteractionManager.java @@ -0,0 +1,50 @@ +package codes.som.hibiscus.mixins; + +import codes.som.hibiscus.Hibiscus; +import codes.som.hibiscus.events.PlayerBlockBreakCheckItemEvent; +import codes.som.hibiscus.events.PlayerBlockBreakCooldownEvent; +import codes.som.hibiscus.events.PlayerBlockBreakProgressEvent; +import net.minecraft.block.BlockState; +import net.minecraft.client.network.ClientPlayerInteractionManager; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.world.BlockView; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(ClientPlayerInteractionManager.class) +public abstract class MixinClientPlayerInteractionManager { + @Shadow + private int blockBreakingCooldown; + + @Shadow + private BlockPos currentBreakingPos; + + @Inject(method = "updateBlockBreakingProgress", at = @At("HEAD")) + private void blockBreakingCooldownHook(BlockPos pos, Direction direction, CallbackInfoReturnable cir) { + var event = new PlayerBlockBreakCooldownEvent(pos, this.blockBreakingCooldown); + Hibiscus.bus().fire(event); + this.blockBreakingCooldown = event.getCooldown(); + } + + @Redirect(method = "updateBlockBreakingProgress", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;calcBlockBreakingDelta(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;)F")) + private float blockBreakingProgressHook(BlockState instance, PlayerEntity player, BlockView world, BlockPos pos) { + float origProgress = instance.calcBlockBreakingDelta(player, world, pos); + var event = new PlayerBlockBreakProgressEvent(pos, origProgress); + Hibiscus.bus().fire(event); + return event.getProgress(); + } + + @Inject(method = "isCurrentlyBreaking", at = @At("RETURN"), cancellable = true) + private void onGetIsCurrentlyBreaking(BlockPos pos, CallbackInfoReturnable cir) { + var event = new PlayerBlockBreakCheckItemEvent(pos); + Hibiscus.bus().fire(event); + if (event.isCancelled()) + cir.setReturnValue(pos.equals(this.currentBreakingPos)); + } +} diff --git a/src/main/java/codes/som/hibiscus/mixins/MixinExtMinecraftClient.java b/src/main/java/codes/som/hibiscus/mixins/MixinExtMinecraftClient.java index f8e82ac..f6efcf4 100644 --- a/src/main/java/codes/som/hibiscus/mixins/MixinExtMinecraftClient.java +++ b/src/main/java/codes/som/hibiscus/mixins/MixinExtMinecraftClient.java @@ -1,6 +1,7 @@ package codes.som.hibiscus.mixins; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.render.RenderTickCounter; import net.minecraft.client.util.Session; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mutable; @@ -11,4 +12,7 @@ public interface MixinExtMinecraftClient { @Accessor @Mutable void setSession(Session session); + + @Accessor + RenderTickCounter getRenderTickCounter(); } diff --git a/src/main/java/codes/som/hibiscus/mixins/MixinExtRenderTickCounter.java b/src/main/java/codes/som/hibiscus/mixins/MixinExtRenderTickCounter.java new file mode 100644 index 0000000..f769afa --- /dev/null +++ b/src/main/java/codes/som/hibiscus/mixins/MixinExtRenderTickCounter.java @@ -0,0 +1,16 @@ +package codes.som.hibiscus.mixins; + +import net.minecraft.client.render.RenderTickCounter; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(RenderTickCounter.class) +public interface MixinExtRenderTickCounter { + @Accessor + @Mutable + void setTickTime(float tickTime); + + @Accessor + float getTickTime(); +} diff --git a/src/main/java/codes/som/hibiscus/mixins/MixinPlayerEntity.java b/src/main/java/codes/som/hibiscus/mixins/MixinPlayerEntity.java new file mode 100644 index 0000000..2bf07c7 --- /dev/null +++ b/src/main/java/codes/som/hibiscus/mixins/MixinPlayerEntity.java @@ -0,0 +1,25 @@ +package codes.som.hibiscus.mixins; + +import codes.som.hibiscus.Hibiscus; +import codes.som.hibiscus.features.player.NoFallDamage; +import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.entity.player.PlayerEntity; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(PlayerEntity.class) +public abstract class MixinPlayerEntity { + @Redirect(method = "getBlockBreakingSpeed", at = @At(value = "FIELD", target = "Lnet/minecraft/entity/player/PlayerEntity;onGround:Z")) + private boolean getOnGround(PlayerEntity player) { + if (player instanceof ClientPlayerEntity) { + try { + if (Hibiscus.INSTANCE.getFeatures().getFeature(NoFallDamage.class).getEnabled()) + return true; + } catch (Exception ignored) { + } + } + + return player.isOnGround(); + } +} diff --git a/src/main/kotlin/codes/som/hibiscus/commands/CommandRegistry.kt b/src/main/kotlin/codes/som/hibiscus/commands/CommandRegistry.kt index b4e9b17..64e3c3d 100644 --- a/src/main/kotlin/codes/som/hibiscus/commands/CommandRegistry.kt +++ b/src/main/kotlin/codes/som/hibiscus/commands/CommandRegistry.kt @@ -7,6 +7,7 @@ fun allCommandClasses(): Array<() -> Command> = arrayOf( ::Reload, ::Vclip, ::Gamma, + ::Timer, ) class CommandRegistry : CommandManager() { diff --git a/src/main/kotlin/codes/som/hibiscus/commands/Timer.kt b/src/main/kotlin/codes/som/hibiscus/commands/Timer.kt new file mode 100644 index 0000000..f404e88 --- /dev/null +++ b/src/main/kotlin/codes/som/hibiscus/commands/Timer.kt @@ -0,0 +1,19 @@ +package codes.som.hibiscus.commands + +import codes.som.hibiscus.api.command.Command +import codes.som.hibiscus.mc +import codes.som.hibiscus.mixins.MixinExtMinecraftClient +import codes.som.hibiscus.mixins.MixinExtRenderTickCounter +import codes.som.hibiscus.util.ext.requireExtension + +class Timer : Command("timer") { + init { + branch { n: Float -> + val renderTickCounter = (mc as MixinExtMinecraftClient).renderTickCounter + requireExtension(renderTickCounter) + renderTickCounter.tickTime = 1000F / (20F * n) + + Unit + } + } +} diff --git a/src/main/kotlin/codes/som/hibiscus/events/PlayerEvents.kt b/src/main/kotlin/codes/som/hibiscus/events/PlayerEvents.kt index 065ed01..7edb399 100644 --- a/src/main/kotlin/codes/som/hibiscus/events/PlayerEvents.kt +++ b/src/main/kotlin/codes/som/hibiscus/events/PlayerEvents.kt @@ -3,9 +3,14 @@ package codes.som.hibiscus.events import codes.som.hibiscus.api.event.Cancellable import codes.som.hibiscus.api.event.Event import net.minecraft.entity.MovementType +import net.minecraft.util.math.BlockPos object PlayerPreTickEvent : Event object PlayerTickEvent : Event class SendChatEvent(val message: String) : Cancellable(), Event data class MovePlayerEvent(var x: Double, var y: Double, var z: Double, val movementType: MovementType) : Event object PlayerInputTickEvent : Event + +data class PlayerBlockBreakCooldownEvent(val pos: BlockPos, var cooldown: Int) : Event +data class PlayerBlockBreakProgressEvent(val pos: BlockPos, var progress: Float) : Event +class PlayerBlockBreakCheckItemEvent(val pos: BlockPos) : Cancellable(), Event diff --git a/src/main/kotlin/codes/som/hibiscus/features/FeaturesRegistry.kt b/src/main/kotlin/codes/som/hibiscus/features/FeaturesRegistry.kt index 7dcdad8..deebe25 100644 --- a/src/main/kotlin/codes/som/hibiscus/features/FeaturesRegistry.kt +++ b/src/main/kotlin/codes/som/hibiscus/features/FeaturesRegistry.kt @@ -10,6 +10,7 @@ import codes.som.hibiscus.features.overlay.Overlay import codes.som.hibiscus.features.player.NoFallDamage import codes.som.hibiscus.features.player.NoSprintingPacket import codes.som.hibiscus.features.player.Nuker +import codes.som.hibiscus.features.player.SpeedMine import codes.som.hibiscus.features.visual.Freecam import codes.som.hibiscus.features.visual.Fullbright import codes.som.hibiscus.features.visual.NoFog @@ -31,6 +32,7 @@ fun FEATURE_CONSTRUCTORS(): Array<() -> Feature> = arrayOf( ::Nuker, ::Fullbright, ::NoFog, + ::SpeedMine, ) class FeaturesRegistry : Resettable { diff --git a/src/main/kotlin/codes/som/hibiscus/features/movement/Flight.kt b/src/main/kotlin/codes/som/hibiscus/features/movement/Flight.kt index 2d23e65..539a680 100644 --- a/src/main/kotlin/codes/som/hibiscus/features/movement/Flight.kt +++ b/src/main/kotlin/codes/som/hibiscus/features/movement/Flight.kt @@ -71,7 +71,7 @@ class Flight : Feature("Flight", FeatureCategory.MOVEMENT) { calcMoveVec(getMoveInputVecFromPlayerInput(player.input), player.yaw) .normalize() .multiply(speed.toDouble() * (10.0 - 1 / 8)) - .multiply(1.0, 0.5, 1.0) + .multiply(1.0, if (vanillaKickBypass && flyKickCounter >= 16) 0.0 else 0.5, 1.0) } else { Vec3d.ZERO } @@ -102,25 +102,28 @@ class Flight : Feature("Flight", FeatureCategory.MOVEMENT) { } on(cond = { vanillaKickBypass }) { event: NetworkMovingEvent -> - flyKickCounter++ + 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 (flyKickCounter >= 16) { - if (flyKickCounter == 16) - lockY = event.y - 0.0625 + if (playerNotColliding) { + flyKickCounter++ - 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 (flyKickCounter >= 16) { + if (flyKickCounter == 16) + lockY = event.y - 0.0625 - if (playerNotColliding) event.y = lockY - } + } - if (flyKickCounter >= 24) + if (flyKickCounter >= 24) + flyKickCounter = 0 + } else { flyKickCounter = 0 + } } } diff --git a/src/main/kotlin/codes/som/hibiscus/features/player/NoFallDamage.kt b/src/main/kotlin/codes/som/hibiscus/features/player/NoFallDamage.kt index 804a199..de95e2b 100644 --- a/src/main/kotlin/codes/som/hibiscus/features/player/NoFallDamage.kt +++ b/src/main/kotlin/codes/som/hibiscus/features/player/NoFallDamage.kt @@ -6,7 +6,7 @@ import codes.som.hibiscus.events.NetworkMovingEvent class NoFallDamage : Feature("No Fall Damage", FeatureCategory.PLAYER) { init { - on { it.onGround = false } + on { it.onGround = true } } override fun createFeatureCommand() = diff --git a/src/main/kotlin/codes/som/hibiscus/features/player/SpeedMine.kt b/src/main/kotlin/codes/som/hibiscus/features/player/SpeedMine.kt new file mode 100644 index 0000000..6ae20dc --- /dev/null +++ b/src/main/kotlin/codes/som/hibiscus/features/player/SpeedMine.kt @@ -0,0 +1,24 @@ +package codes.som.hibiscus.features.player + +import codes.som.hibiscus.api.feature.Feature +import codes.som.hibiscus.api.feature.FeatureCategory +import codes.som.hibiscus.events.PlayerBlockBreakCheckItemEvent +import codes.som.hibiscus.events.PlayerBlockBreakCooldownEvent +import codes.som.hibiscus.events.PlayerBlockBreakProgressEvent + +class SpeedMine : Feature("Speed Mine", FeatureCategory.PLAYER) { + init { + on { event: PlayerBlockBreakCooldownEvent -> + event.cooldown = 0 + } + + on { event: PlayerBlockBreakProgressEvent -> + if (event.progress >= 0.7F) + event.progress = 1.0F + } + + on { event: PlayerBlockBreakCheckItemEvent -> event.cancel() } + + enabled = true + } +} diff --git a/src/main/resources/hibiscus.mixins.json b/src/main/resources/hibiscus.mixins.json index d1e9ff3..0f353ba 100644 --- a/src/main/resources/hibiscus.mixins.json +++ b/src/main/resources/hibiscus.mixins.json @@ -9,16 +9,19 @@ "MixinBackgroundRenderer", "MixinClientConnection", "MixinClientPlayerEntity", + "MixinClientPlayerInteractionManager", "MixinClientPlayNetworkHandler", "MixinDebugHud", "MixinExtClientPlayerEntity", "MixinExtEntity", "MixinExtMinecraftClient", "MixinExtPlayerInteractEntityC2SPacket", + "MixinExtRenderTickCounter", "MixinExtUpdatePlayerAbilitiesC2SPacket", "MixinGameRenderer", "MixinKeyboard", "MixinMinecraftClient", + "MixinPlayerEntity", "MixinRenderSectionManager", "MixinWorldRenderer", "netmoving.MixinClientPlayerEntity",