Skip to content

Commit

Permalink
Merge branch 'main' of github.com:n2pm/tangerine
Browse files Browse the repository at this point in the history
  • Loading branch information
NotNite committed Feb 24, 2024
2 parents 7610954 + 6d025d3 commit 7aa79b7
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,34 +1,52 @@
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;
import org.spongepowered.asm.mixin.injection.ModifyConstant;
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()) {
Expand Down Expand Up @@ -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<Boolean> 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<Boolean> 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<Boolean> cir) {
this.lastBlockBreak = pos;
}
}
12 changes: 12 additions & 0 deletions src/main/java/pm/n2/tangerine/mixin/ClientWorldAccessor.java
Original file line number Diff line number Diff line change
@@ -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();
}
6 changes: 2 additions & 4 deletions src/main/kotlin/pm/n2/tangerine/managers/ModuleManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,6 +32,7 @@ object ModuleManager : Manager {
ModuleListModule,
GUIModule,
FastBreakModule,
CivBreakModule,
PacketLoggerModule,

BoatFlyModule,
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions src/main/resources/assets/tangerine/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/tangerine.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"ClientPlayerEntityMixin",
"ClientPlayerInteractionManagerMixin",
"ClientPlayNetworkHandlerMixin",
"ClientWorldAccessor",
"EntityMixin",
"FluidBlockMixin",
"InputMixin",
Expand Down

0 comments on commit 7aa79b7

Please sign in to comment.