Skip to content

Commit

Permalink
Fixed client bug where the attack grace period does not work
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandra-Myers committed Aug 27, 2023
1 parent b7c9473 commit f578083
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/main/java/net/atlas/combatify/mixin/MinecraftMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.atlas.combatify.Combatify;
import net.atlas.combatify.extensions.*;
import net.minecraft.client.Minecraft;
import net.minecraft.client.MouseHandler;
import net.minecraft.client.Options;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.multiplayer.ClientLevel;
Expand Down Expand Up @@ -82,6 +83,10 @@ public abstract class MinecraftMixin implements IMinecraft {
@Shadow
public abstract void startUseItem();

@Shadow
@Final
public MouseHandler mouseHandler;

@Inject(method = "tick", at = @At(value = "TAIL"))
public void injectSomething(CallbackInfo ci) {
assert player != null;
Expand Down Expand Up @@ -239,12 +244,15 @@ public EntityHitResult rayTraceEntity(Player player, float partialTicks, double

@Inject(method = "continueAttack", at = @At(value = "HEAD"), cancellable = true)
private void continueAttack(boolean bl, CallbackInfo ci) {
assert hitResult != null;
redirectResult(hitResult);
boolean bl1 = this.screen == null && (this.options.keyAttack.isDown() || this.retainAttack) && this.mouseHandler.isMouseGrabbed();
if (missTime <= 0) {
assert this.player != null;
if (!this.player.isUsingItem()) {
if (bl && this.hitResult != null && this.hitResult.getType() == HitResult.Type.BLOCK) {
if (bl1 && this.hitResult != null && this.hitResult.getType() == HitResult.Type.BLOCK) {
this.retainAttack = false;
} else if (bl && ((PlayerExtensions) this.player).isAttackAvailable(-1.0F) && ((IOptions) options).autoAttack().get() && Combatify.CONFIG.autoAttackAllowed()) {
} else if (bl1 && ((PlayerExtensions) this.player).isAttackAvailable(-1.0F) && (((IOptions) options).autoAttack().get() && Combatify.CONFIG.autoAttackAllowed()) || this.retainAttack) {
this.startAttack();
ci.cancel();
}
Expand Down

0 comments on commit f578083

Please sign in to comment.