From 0ae5c87b6c7cd6292fb31ccd5852aaa25b0f352c Mon Sep 17 00:00:00 2001 From: adryd Date: Wed, 21 Feb 2024 20:46:22 -0500 Subject: [PATCH 1/3] civbreak --- .../ClientPlayerInteractionManagerMixin.java | 85 ++++++++++++++++++- .../tangerine/mixin/ClientWorldAccessor.java | 12 +++ .../tangerine/modules/misc/CivBreakModule.kt | 6 ++ src/main/resources/tangerine.mixins.json | 1 + 4 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 src/main/java/pm/n2/tangerine/mixin/ClientWorldAccessor.java create mode 100644 src/main/kotlin/pm/n2/tangerine/modules/misc/CivBreakModule.kt diff --git a/src/main/java/pm/n2/tangerine/mixin/ClientPlayerInteractionManagerMixin.java b/src/main/java/pm/n2/tangerine/mixin/ClientPlayerInteractionManagerMixin.java index a2c08da..de09c35 100644 --- a/src/main/java/pm/n2/tangerine/mixin/ClientPlayerInteractionManagerMixin.java +++ b/src/main/java/pm/n2/tangerine/mixin/ClientPlayerInteractionManagerMixin.java @@ -1,16 +1,22 @@ package pm.n2.tangerine.mixin; +import net.minecraft.block.BlockState; +import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.client.network.ClientPlayerInteractionManager; +import net.minecraft.client.network.PendingUpdateManager; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket; +import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket; import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; +import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Constant; import org.spongepowered.asm.mixin.injection.Inject; @@ -18,17 +24,29 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import pm.n2.tangerine.modules.combat.CritsModule; +import pm.n2.tangerine.modules.misc.CivBreakModule; import pm.n2.tangerine.modules.misc.FastBreakModule; @Mixin(ClientPlayerInteractionManager.class) -public class ClientPlayerInteractionManagerMixin { +public abstract class ClientPlayerInteractionManagerMixin { @Shadow @Final private ClientPlayNetworkHandler networkHandler; + @Shadow + @Final + private MinecraftClient client; + @Shadow private int blockBreakingCooldown; + @Shadow + public abstract boolean breakBlock(BlockPos pos); + + @Unique + @Nullable + BlockPos lastBlockBreak; + @Inject(method = "attackEntity", at = @At("HEAD")) public void tangerine$crits(PlayerEntity player, Entity target, CallbackInfo ci) { if (CritsModule.INSTANCE.getEnabled().getValue()) { @@ -69,4 +87,69 @@ private void updateBlockBreakingProgress(BlockPos pos, Direction direction, Call return 1.0F; } } + + @Inject( + method = "attackBlock", + at = + @At( + value = "INVOKE", + target = + "Lnet/minecraft/client/tutorial/TutorialManager;onBlockBreaking(Lnet/minecraft/client/world/ClientWorld;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;F)V", + ordinal = 1), + cancellable = true) + private void setBlockBreakSpeed(BlockPos pos, Direction direction, CallbackInfoReturnable cir) { + assert this.client.world != null; + assert this.client.player != null; + if (civBreak(pos, direction, cir)) { + return; + } + if (FastBreakModule.INSTANCE.getEnabled().getValue()) { + BlockState blockState = this.client.world.getBlockState(pos); + if (blockState.calcBlockBreakingDelta(this.client.player, this.client.player.getWorld(), pos) >= 0.7F) { + this.breakBlock(pos); + try (PendingUpdateManager pendingUpdateManager = ((ClientWorldAccessor) this.client.world) + .invokeGetPendingUpdateManager() + .incrementSequence()) { + this.networkHandler.sendPacket(new PlayerActionC2SPacket( + PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, + pos, + direction, + pendingUpdateManager.getSequence())); + pendingUpdateManager.incrementSequence(); + this.networkHandler.sendPacket(new PlayerActionC2SPacket( + PlayerActionC2SPacket.Action.STOP_DESTROY_BLOCK, + pos, + direction, + pendingUpdateManager.getSequence())); + } + cir.setReturnValue(true); + } + } + } + + @Unique + private boolean civBreak(BlockPos pos, Direction direction, CallbackInfoReturnable cir) { + assert this.client.world != null; + if (CivBreakModule.INSTANCE.getEnabled().getValue() && this.lastBlockBreak != null && this.lastBlockBreak.equals(pos)) { + try (PendingUpdateManager pendingUpdateManager = ((ClientWorldAccessor) this.client.world) + .invokeGetPendingUpdateManager() + .incrementSequence()) { + this.networkHandler.sendPacket(new PlayerActionC2SPacket( + PlayerActionC2SPacket.Action.STOP_DESTROY_BLOCK, + pos, + direction, + pendingUpdateManager.getSequence())); + } + this.breakBlock(pos); + cir.setReturnValue(true); + return true; + } else { + this.lastBlockBreak = null; + } + return false; + } + @Inject(method = "breakBlock", at = @At("HEAD")) + private void updateLastBrokenBlock(BlockPos pos, CallbackInfoReturnable cir) { + this.lastBlockBreak = pos; + } } diff --git a/src/main/java/pm/n2/tangerine/mixin/ClientWorldAccessor.java b/src/main/java/pm/n2/tangerine/mixin/ClientWorldAccessor.java new file mode 100644 index 0000000..5ec336b --- /dev/null +++ b/src/main/java/pm/n2/tangerine/mixin/ClientWorldAccessor.java @@ -0,0 +1,12 @@ +package pm.n2.tangerine.mixin; + +import net.minecraft.client.network.PendingUpdateManager; +import net.minecraft.client.world.ClientWorld; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +@Mixin(ClientWorld.class) +public interface ClientWorldAccessor { + @Invoker + PendingUpdateManager invokeGetPendingUpdateManager(); +} diff --git a/src/main/kotlin/pm/n2/tangerine/modules/misc/CivBreakModule.kt b/src/main/kotlin/pm/n2/tangerine/modules/misc/CivBreakModule.kt new file mode 100644 index 0000000..ab5df95 --- /dev/null +++ b/src/main/kotlin/pm/n2/tangerine/modules/misc/CivBreakModule.kt @@ -0,0 +1,6 @@ +package pm.n2.tangerine.modules.misc + +import pm.n2.tangerine.modules.Module +import pm.n2.tangerine.modules.ModuleCategory + +object CivBreakModule : Module("civbreak", ModuleCategory.MISC) diff --git a/src/main/resources/tangerine.mixins.json b/src/main/resources/tangerine.mixins.json index db9ec5e..8cc7d3d 100644 --- a/src/main/resources/tangerine.mixins.json +++ b/src/main/resources/tangerine.mixins.json @@ -12,6 +12,7 @@ "ClientPlayerEntityMixin", "ClientPlayerInteractionManagerMixin", "ClientPlayNetworkHandlerMixin", + "ClientWorldAccessor", "EntityMixin", "FluidBlockMixin", "InputMixin", From 1971b26cd00e3319be7428eb8a5d8b5884c0f7a1 Mon Sep 17 00:00:00 2001 From: adryd Date: Wed, 21 Feb 2024 20:50:05 -0500 Subject: [PATCH 2/3] GIT ADD --- src/main/kotlin/pm/n2/tangerine/managers/ModuleManager.kt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/pm/n2/tangerine/managers/ModuleManager.kt b/src/main/kotlin/pm/n2/tangerine/managers/ModuleManager.kt index a94e8da..b165e45 100644 --- a/src/main/kotlin/pm/n2/tangerine/managers/ModuleManager.kt +++ b/src/main/kotlin/pm/n2/tangerine/managers/ModuleManager.kt @@ -8,10 +8,7 @@ import pm.n2.tangerine.modules.Module import pm.n2.tangerine.modules.ModuleCategory import pm.n2.tangerine.modules.combat.CritsModule import pm.n2.tangerine.modules.combat.KillAuraModule -import pm.n2.tangerine.modules.misc.FastBreakModule -import pm.n2.tangerine.modules.misc.GUIModule -import pm.n2.tangerine.modules.misc.ModuleListModule -import pm.n2.tangerine.modules.misc.PacketLoggerModule +import pm.n2.tangerine.modules.misc.* import pm.n2.tangerine.modules.movement.* import pm.n2.tangerine.modules.player.AntiHungerModule import pm.n2.tangerine.modules.visuals.BlockESPModule @@ -35,6 +32,7 @@ object ModuleManager : Manager { ModuleListModule, GUIModule, FastBreakModule, + CivBreakModule, PacketLoggerModule, BoatFlyModule, From 6d025d3167690cdcca164e4d9e2217f7f4ff5c9e Mon Sep 17 00:00:00 2001 From: adryd Date: Wed, 21 Feb 2024 21:00:26 -0500 Subject: [PATCH 3/3] civbreak: lang entry --- src/main/resources/assets/tangerine/lang/en_us.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/resources/assets/tangerine/lang/en_us.json b/src/main/resources/assets/tangerine/lang/en_us.json index 328b553..2dee301 100644 --- a/src/main/resources/assets/tangerine/lang/en_us.json +++ b/src/main/resources/assets/tangerine/lang/en_us.json @@ -110,6 +110,8 @@ "tangerine.config.tracers.others_color": "Other entities color", "tangerine.module.fastbreak.name": "Fast break", "tangerine.module.fastbreak.description": "Speeds up block breaking", + "tangerine.module.civbreak.name": "Civbreak", + "tangerine.module.civbreak.description": "Instant mine the block in the exact position you last mined", "tangerine.module.gui.name": "GUI settings", "tangerine.module.gui.description": "Configure the Tangerine GUI", "tangerine.config.gui.unifont": "Use Unifont",