Skip to content

Commit a63fea2

Browse files
committed
- added unsafe cancels option
- BreakManager is now like other managers in the sense that you need to keep posting requests to keep a block breaking. - improved double break logic
1 parent 62fd5c2 commit a63fea2

File tree

8 files changed

+254
-173
lines changed

8 files changed

+254
-173
lines changed

common/src/main/java/com/lambda/mixin/MinecraftClientMixin.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,9 @@ public class MinecraftClientMixin {
4444
@Shadow
4545
@Nullable
4646
public Screen currentScreen;
47-
48-
@Shadow @Nullable public HitResult crosshairTarget;
49-
50-
@Shadow @Nullable public ClientPlayerEntity player;
47+
@Shadow
48+
@Nullable
49+
public HitResult crosshairTarget;
5150

5251
@Inject(method = "tick", at = @At("HEAD"))
5352
void onTickPre(CallbackInfo ci) {
@@ -100,9 +99,9 @@ private void onScreenRemove(@Nullable Screen screen, CallbackInfo ci) {
10099

101100
@Redirect(method = "doAttack()Z", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;swingHand(Lnet/minecraft/util/Hand;)V"))
102101
private void redirectHandSwing(ClientPlayerEntity instance, Hand hand) {
103-
if (this.crosshairTarget == null || this.player != null) return;
102+
if (this.crosshairTarget == null) return;
104103
if (this.crosshairTarget.getType() != HitResult.Type.BLOCK || PacketMine.INSTANCE.isDisabled()) {
105-
this.player.swingHand(hand);
104+
instance.swingHand(hand);
106105
}
107106
}
108107

common/src/main/java/com/lambda/mixin/entity/ClientPlayerEntityMixin.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import net.minecraft.client.network.ClientPlayerEntity;
2929
import net.minecraft.entity.MovementType;
3030
import net.minecraft.entity.damage.DamageSource;
31-
import net.minecraft.util.Hand;
3231
import net.minecraft.util.math.Vec3d;
3332
import org.spongepowered.asm.mixin.Mixin;
3433
import org.spongepowered.asm.mixin.Shadow;
@@ -120,11 +119,6 @@ float fixHeldItemPitch(ClientPlayerEntity instance) {
120119
return Objects.requireNonNullElse(RotationManager.getHandPitch(), instance.getPitch());
121120
}
122121

123-
@Inject(method = "swingHand", at = @At("HEAD"), cancellable = true)
124-
void onSwingHandPre(Hand hand, CallbackInfo ci) {
125-
if (EventFlow.post(new PlayerEvent.SwingHand(hand)).isCanceled()) ci.cancel();
126-
}
127-
128122
@Inject(method = "damage", at = @At("HEAD"), cancellable = true)
129123
public void damage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir) {
130124
if (EventFlow.post(new PlayerEvent.Damage(source, amount)).isCanceled()) {

common/src/main/kotlin/com/lambda/config/groups/BreakSettings.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class BreakSettings(
2828
vis: () -> Boolean = { true }
2929
) : BreakConfig(priority) {
3030
override val breakMode by c.setting("Break Mode", BreakMode.Vanilla) { vis() }
31+
override val unsafeCancels by c.setting("Unsafe Cancels", true, "Allows cancelling block breaking even if the server might continue breaking sever side, potentially causing unexpected state changes") { vis() }
3132
override val breakThreshold by c.setting("Break Threshold", 1.0f, 0.1f..1.0f, 0.02f, "The break amount at which the block is considered broken") { vis() }
3233
override val doubleBreak by c.setting("Double Break", false, "Allows breaking two blocks at once") { vis() }
3334
override val breakDelay by c.setting("Break Delay", 5, 0..5, 1, "The delay between breaking blocks", " ticks") { vis() }

common/src/main/kotlin/com/lambda/interaction/construction/context/BreakContext.kt

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,7 @@ import com.lambda.interaction.construction.verify.TargetState
2525
import com.lambda.interaction.request.rotation.RotationRequest
2626
import com.lambda.util.world.raycast.RayCastUtils.distanceTo
2727
import net.minecraft.block.BlockState
28-
import net.minecraft.block.Blocks
2928
import net.minecraft.block.FallingBlock
30-
import net.minecraft.client.network.ClientPlayerInteractionManager
31-
import net.minecraft.client.world.ClientWorld
32-
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket
33-
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket.Action
3429
import net.minecraft.util.hit.BlockHitResult
3530
import net.minecraft.util.math.BlockPos
3631
import net.minecraft.util.math.Direction
@@ -81,23 +76,4 @@ data class BreakContext(
8176
withState(checkedState, expectedPos, baseColor, DirectionMask.ALL.exclude(result.side))
8277
withState(checkedState, expectedPos, sideColor, result.side)
8378
}
84-
85-
fun startBreakPacket(world: ClientWorld, interaction: ClientPlayerInteractionManager) =
86-
breakPacket(Action.START_DESTROY_BLOCK, world, interaction)
87-
88-
fun stopBreakPacket(world: ClientWorld, interaction: ClientPlayerInteractionManager) =
89-
breakPacket(Action.STOP_DESTROY_BLOCK, world, interaction)
90-
91-
fun abortBreakPacket(world: ClientWorld, interaction: ClientPlayerInteractionManager) =
92-
breakPacket(Action.ABORT_DESTROY_BLOCK, world, interaction)
93-
94-
private fun breakPacket(action: Action, world: ClientWorld, interaction: ClientPlayerInteractionManager) =
95-
interaction.sendSequencedPacket(world) { sequence: Int ->
96-
PlayerActionC2SPacket(
97-
action,
98-
expectedPos,
99-
result.side,
100-
sequence
101-
)
102-
}
10379
}

common/src/main/kotlin/com/lambda/interaction/request/breaking/BreakConfig.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ abstract class BreakConfig(
2626
priority: Priority = 0
2727
) : RequestConfig<BreakRequest>(priority) {
2828
abstract val breakMode: BreakMode
29+
abstract val unsafeCancels: Boolean
2930
abstract val breakThreshold: Float
3031
abstract val doubleBreak: Boolean
3132
abstract val breakDelay: Int

0 commit comments

Comments
 (0)