Skip to content

Commit

Permalink
Fix attack indicator on Cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
tr7zw committed Sep 6, 2023
1 parent 6e2a9c3 commit fb39ee7
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Shared/src/main/java/dev/tr7zw/exordium/mixin/CrosshairMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
import dev.tr7zw.exordium.ExordiumModBase;
import dev.tr7zw.exordium.access.VanillaBufferAccess.CrosshairOverlayAccess;
import dev.tr7zw.exordium.util.BufferedComponent;
import net.minecraft.client.AttackIndicatorStatus;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.world.entity.LivingEntity;

@Mixin(Gui.class)
public class CrosshairMixin implements CrosshairOverlayAccess {
Expand All @@ -23,6 +25,8 @@ public class CrosshairMixin implements CrosshairOverlayAccess {
private boolean wasRenderingF3 = false;
private float lastPitch = 0;
private float lastYaw = 0;
private float lastCooldown = 0;
private boolean lastHighlight = false;

private BufferedComponent crosshairBufferedComponent = new BufferedComponent(true,
() -> ExordiumModBase.instance.config.debugScreenSettings) {
Expand All @@ -36,6 +40,19 @@ public boolean needsRender() {
return lastPitch != minecraft.getCameraEntity().getXRot()
|| lastYaw != minecraft.getCameraEntity().getYRot();
}
if (minecraft.options.attackIndicator().get() == AttackIndicatorStatus.CROSSHAIR) {
float cooldown = minecraft.player.getAttackStrengthScale(0.0F);
if(lastCooldown != cooldown) {
return true;
}
boolean flag = false;
if (minecraft.crosshairPickEntity != null
&& minecraft.crosshairPickEntity instanceof LivingEntity && cooldown >= 1.0F) {
flag = minecraft.player.getCurrentItemAttackStrengthDelay() > 5.0F;
flag &= minecraft.crosshairPickEntity.isAlive();
}
return flag != lastHighlight;
}
return false;
}

Expand All @@ -44,6 +61,14 @@ public void captureState() {
wasRenderingF3 = minecraft.options.renderDebug;
lastPitch = minecraft.getCameraEntity().getXRot();
lastYaw = minecraft.getCameraEntity().getYRot();
lastCooldown = minecraft.player.getAttackStrengthScale(0.0F);
boolean flag = false;
if (minecraft.crosshairPickEntity != null
&& minecraft.crosshairPickEntity instanceof LivingEntity && lastCooldown >= 1.0F) {
flag = minecraft.player.getCurrentItemAttackStrengthDelay() > 5.0F;
flag &= minecraft.crosshairPickEntity.isAlive();
}
lastHighlight = flag;
}
};

Expand Down

0 comments on commit fb39ee7

Please sign in to comment.