Skip to content
This repository was archived by the owner on Nov 28, 2025. It is now read-only.

Commit 6c84c32

Browse files
committed
add secondary key to freelook
1 parent b62f827 commit 6c84c32

File tree

18 files changed

+423
-247
lines changed

18 files changed

+423
-247
lines changed

1.16_combat-6/src/main/java/io/github/axolotlclient/mixin/CameraMixin.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ public abstract class CameraMixin {
4949
private void axolotlclient$perspectiveUpdatePitchYaw(BlockView area, Entity focusedEntity, boolean thirdPerson,
5050
boolean inverseView, float tickDelta, CallbackInfo ci) {
5151
this.pitch = Freelook.getInstance().pitch(pitch)
52-
* (inverseView && Freelook.getInstance().enabled.get() && Freelook.getInstance().active ? -1 : 1);
52+
* (inverseView && Freelook.getInstance().enabled.get() && Freelook.getInstance().isActive() ? -1 : 1);
5353
this.yaw = Freelook.getInstance().yaw(yaw)
54-
+ (inverseView && Freelook.getInstance().enabled.get() && Freelook.getInstance().active ? 180 : 0);
54+
+ (inverseView && Freelook.getInstance().enabled.get() && Freelook.getInstance().isActive() ? 180 : 0);
5555
}
5656

5757
@ModifyArgs(method = "update", at = @At(value = "INVOKE", target = "net/minecraft/client/render/Camera.setRotation(FF)V", ordinal = 0))
@@ -62,7 +62,7 @@ public abstract class CameraMixin {
6262

6363
@ModifyArg(method = "update", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/Camera;moveBy(DDD)V", ordinal = 0), index = 0)
6464
private double axolotlclient$correctDistance(double x) {
65-
if (Freelook.getInstance().enabled.get() && Freelook.getInstance().active
65+
if (Freelook.getInstance().enabled.get() && Freelook.getInstance().isActive()
6666
&& MinecraftClient.getInstance().options.getPerspective().isFrontView()) {
6767
return -clipToSpace(4);
6868
}

1.16_combat-6/src/main/java/io/github/axolotlclient/modules/freelook/Freelook.java

Lines changed: 49 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
package io.github.axolotlclient.modules.freelook;
2424

25+
import java.util.ArrayDeque;
26+
import java.util.Deque;
27+
2528
import io.github.axolotlclient.AxolotlClient;
2629
import io.github.axolotlclient.AxolotlClientConfig.api.options.OptionCategory;
2730
import io.github.axolotlclient.AxolotlClientConfig.impl.options.BooleanOption;
@@ -39,69 +42,76 @@
3942

4043
public class Freelook extends AbstractModule {
4144

42-
private static final Freelook Instance = new Freelook();
43-
private static KeyBinding KEY = new KeyBinding("key.freelook", GLFW.GLFW_KEY_V, "category.axolotlclient");
45+
private static final Freelook INSTANCE = new Freelook();
46+
private static final KeyBinding KEY = new KeyBinding("key.freelook", GLFW.GLFW_KEY_V, "category.axolotlclient");
47+
private static final KeyBinding KEY_ALT = new KeyBinding("key.freelook.alt", GLFW.GLFW_KEY_UNKNOWN, "category.axolotlclient");
4448
public final ForceableBooleanOption enabled = new ForceableBooleanOption("enabled", false);
4549
private final MinecraftClient client = MinecraftClient.getInstance();
4650
private final OptionCategory category = OptionCategory.create("freelook");
4751
private final StringArrayOption mode = new StringArrayOption("mode",
4852
new String[]{"snap_perspective", "freelook"},
4953
"freelook", value -> FeatureDisabler.update());
54+
private final BooleanOption invert = new BooleanOption("invert", false);
5055
private final EnumOption<Perspective> perspective = new EnumOption<>("perspective", Perspective.class,
5156
Perspective.THIRD_PERSON_BACK);
52-
private final BooleanOption invert = new BooleanOption("invert", false);
5357
private final BooleanOption toggle = new BooleanOption("toggle", false);
54-
public boolean active;
58+
private final EnumOption<Perspective> perspectiveAlt = new EnumOption<>("perspective.alt", Perspective.class,
59+
Perspective.THIRD_PERSON_FRONT);
60+
private final BooleanOption toggleAlt = new BooleanOption("toggle.alt", false);
61+
private final WrappedValue active = new WrappedValue(), activeAlt = new WrappedValue();
5562
private float yaw, pitch;
56-
private Perspective previousPerspective;
63+
private final Deque<Perspective> previousPerspectives = new ArrayDeque<>();
5764

5865
public static Freelook getInstance() {
59-
return Instance;
66+
return INSTANCE;
6067
}
6168

6269
@Override
6370
public void init() {
6471
KeyBindingHelper.registerKeyBinding(KEY);
72+
KeyBindingHelper.registerKeyBinding(KEY_ALT);
6573
category.add(enabled, mode, perspective, invert, toggle);
74+
category.add(perspectiveAlt, toggleAlt);
6675
AxolotlClient.CONFIG.addCategory(category);
6776
}
6877

6978
@Override
7079
public void tick() {
71-
if (!enabled.get())
72-
return;
80+
if (!enabled.get() || client.currentScreen != null) return;
81+
tickSet(toggle, KEY, perspective, active);
82+
tickSet(toggleAlt, KEY_ALT, perspectiveAlt, activeAlt);
83+
}
7384

85+
private void tickSet(BooleanOption toggle, KeyBinding key, EnumOption<Perspective> perspective, WrappedValue active) {
7486
if (toggle.get()) {
75-
if (KEY.wasPressed()) {
76-
if (active) {
77-
stop();
87+
if (key.wasPressed()) {
88+
if (active.val) {
89+
stop(active);
7890
} else {
79-
start();
91+
start(perspective.get(), active);
8092
}
8193
}
8294
} else {
83-
if (KEY.isPressed()) {
84-
if (!active) {
85-
start();
95+
if (key.isPressed()) {
96+
if (!active.val) {
97+
start(perspective.get(), active);
8698
}
87-
} else if (active) {
88-
stop();
99+
} else if (active.val) {
100+
stop(active);
89101
}
90102
}
91103
}
92104

93-
private void stop() {
94-
active = false;
105+
private void stop(WrappedValue active) {
106+
active.val = false;
95107
client.worldRenderer.scheduleTerrainUpdate();
96-
setPerspective(previousPerspective);
108+
setPerspective(previousPerspectives.pop());
97109
}
98110

99-
private void start() {
100-
active = true;
101-
102-
103-
previousPerspective = client.options.getPerspective();
104-
setPerspective(perspective.get());
111+
private void start(Perspective perspective, WrappedValue active) {
112+
previousPerspectives.push(client.options.getPerspective());
113+
active.val = true;
114+
setPerspective(perspective);
105115

106116
Entity camera = client.getCameraEntity();
107117

@@ -119,7 +129,7 @@ private void setPerspective(Perspective perspective) {
119129
}
120130

121131
public boolean consumeRotation(double dx, double dy) {
122-
if (!active || !enabled.get() || !mode.get().equals("freelook"))
132+
if (!(active.val || activeAlt.val) || !enabled.get() || !mode.get().equals("freelook"))
123133
return false;
124134

125135
if (!invert.get())
@@ -129,8 +139,8 @@ public boolean consumeRotation(double dx, double dy) {
129139
|| MinecraftClient.getInstance().options.getPerspective().isFirstPerson())
130140
dy *= -1;
131141

132-
yaw += dx * 0.15F;
133-
pitch += dy * 0.15F;
142+
yaw += (float) (dx * 0.15F);
143+
pitch += (float) (dy * 0.15F);
134144

135145
if (pitch > 90) {
136146
pitch = 90;
@@ -143,14 +153,14 @@ public boolean consumeRotation(double dx, double dy) {
143153
}
144154

145155
public float yaw(float defaultValue) {
146-
if (!active || !enabled.get() || !mode.get().equals("freelook"))
156+
if (!(active.val || activeAlt.val) || !enabled.get() || !mode.get().equals("freelook"))
147157
return defaultValue;
148158

149159
return yaw;
150160
}
151161

152162
public float pitch(float defaultValue) {
153-
if (!active || !enabled.get() || !mode.get().equals("freelook"))
163+
if (!(active.val || activeAlt.val) || !enabled.get() || !mode.get().equals("freelook"))
154164
return defaultValue;
155165

156166
return pitch;
@@ -159,4 +169,12 @@ public float pitch(float defaultValue) {
159169
public boolean needsDisabling() {
160170
return mode.get().equals("freelook");
161171
}
172+
173+
public boolean isActive(){
174+
return active.val || activeAlt.val;
175+
}
176+
177+
private static class WrappedValue {
178+
boolean val;
179+
}
162180
}

1.16_combat-6/src/main/java/io/github/axolotlclient/modules/hud/gui/hud/item/ArmorHud.java

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
package io.github.axolotlclient.modules.hud.gui.hud.item;
2424

2525
import java.util.List;
26+
import java.util.stream.Stream;
2627

2728
import io.github.axolotlclient.AxolotlClientConfig.api.options.Option;
2829
import io.github.axolotlclient.AxolotlClientConfig.impl.options.BooleanOption;
@@ -62,16 +63,19 @@ public ArmorHud() {
6263
@Override
6364
public void renderComponent(MatrixStack matrices, float delta) {
6465
int width = 20;
65-
if (showDurabilityNumber.get()) {
66-
width += 15;
67-
}
68-
if (showMaxDurabilityNumber.get()) {
69-
width += 15;
66+
boolean showDurability = showDurabilityNumber.get();
67+
boolean showMaxDurability = showMaxDurabilityNumber.get();
68+
int labelWidth = showDurability || showMaxDurability ? Stream.concat(Stream.of(client.player.inventory.getMainHandStack()), client.player.inventory.armor.stream())
69+
.map(stack -> showDurability && showMaxDurability ? (stack.getMaxDamage() - stack.getDamage())+"/"+stack.getMaxDamage() : String.valueOf((showDurability ? stack.getMaxDamage() - stack.getDamage() : stack.getMaxDamage())))
70+
.mapToInt(text -> client.textRenderer.getWidth(text)+2).max().orElse(0) : 0;
71+
width += labelWidth;
72+
if (width != getWidth()) {
73+
setWidth(width);
74+
onBoundsUpdate();
7075
}
71-
setWidth(width);
7276
DrawPosition pos = getPos();
7377
int lastY = 2 + (4 * 20);
74-
renderMainItem(matrices, client.player.inventory.getMainHandStack(), pos.x() + 2, pos.y() + lastY);
78+
renderMainItem(matrices, client.player.inventory.getMainHandStack(), pos.x() + 2, pos.y() + lastY, labelWidth);
7579
lastY = lastY - 20;
7680
for (int i = 0; i <= 3; i++) {
7781
ItemStack stack = client.player.inventory.getArmorStack(i).copy();
@@ -87,27 +91,29 @@ public void renderComponent(MatrixStack matrices, float delta) {
8791
}
8892
}
8993
}
90-
renderItem(matrices, stack, pos.x() + 2, lastY + pos.y());
94+
renderItem(matrices, stack, pos.x() + 2, lastY + pos.y(), labelWidth);
9195
lastY = lastY - 20;
9296
}
9397
}
9498

95-
public void renderMainItem(MatrixStack matrices, ItemStack stack, int x, int y) {
99+
public void renderMainItem(MatrixStack matrices, ItemStack stack, int x, int y, int offset) {
100+
renderDurabilityNumber(matrices, stack, x, y);
101+
x += offset;
96102
ItemUtil.renderGuiItemModel(getScale(), stack, x, y);
97103
String total = String.valueOf(ItemUtil.getTotal(client, stack));
98104
if (total.equals("1")) {
99105
total = null;
100106
}
101107
ItemUtil.renderGuiItemOverlay(matrices, client.textRenderer, stack, x, y, total, textColor.get().toInt(),
102108
shadow.get());
103-
renderDurabilityNumber(matrices, stack, x, y);
104109
}
105110

106-
public void renderItem(MatrixStack matrices, ItemStack stack, int x, int y) {
111+
public void renderItem(MatrixStack matrices, ItemStack stack, int x, int y, int offset) {
112+
renderDurabilityNumber(matrices, stack, x, y);
113+
x += offset;
107114
ItemUtil.renderGuiItemModel(getScale(), stack, x, y);
108115
ItemUtil.renderGuiItemOverlay(matrices, client.textRenderer, stack, x, y, null, textColor.get().toInt(),
109116
shadow.get());
110-
renderDurabilityNumber(matrices, stack, x, y);
111117
}
112118

113119
private void renderDurabilityNumber(MatrixStack graphics, ItemStack stack, int x, int y) {
@@ -128,13 +134,24 @@ private void renderDurabilityNumber(MatrixStack graphics, ItemStack stack, int x
128134

129135
@Override
130136
public void renderPlaceholderComponent(MatrixStack matrices, float delta) {
137+
int width = 20;
138+
boolean showDurability = showDurabilityNumber.get();
139+
boolean showMaxDurability = showMaxDurabilityNumber.get();
140+
int labelWidth = showDurability || showMaxDurability ? Stream.concat(Stream.of(client.player.inventory.getMainHandStack()), client.player.inventory.armor.stream())
141+
.map(stack -> showDurability && showMaxDurability ? (stack.getMaxDamage() - stack.getDamage())+"/"+stack.getMaxDamage() : String.valueOf((showDurability ? stack.getMaxDamage() - stack.getDamage() : stack.getMaxDamage())))
142+
.mapToInt(text -> client.textRenderer.getWidth(text)+2).max().orElse(0) : 0;
143+
width += labelWidth;
144+
if (width != getWidth()) {
145+
setWidth(width);
146+
onBoundsUpdate();
147+
}
131148
DrawPosition pos = getPos();
132149
int lastY = 2 + (4 * 20);
133-
renderItem(matrices, placeholderStacks[4], pos.x() + 2, pos.y() + lastY);
150+
renderItem(matrices, placeholderStacks[4], pos.x() + 2, pos.y() + lastY, labelWidth);
134151
lastY = lastY - 20;
135152
for (int i = 0; i <= 3; i++) {
136153
ItemStack item = placeholderStacks[i];
137-
renderItem(matrices, item, pos.x() + 2, lastY + pos.y());
154+
renderItem(matrices, item, pos.x() + 2, lastY + pos.y(), labelWidth);
138155
lastY = lastY - 20;
139156
}
140157
}

1.20/src/main/java/io/github/axolotlclient/mixin/CameraMixin.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ public abstract class CameraMixin {
4949
private void axolotlclient$perspectiveUpdatePitchYaw(BlockView area, Entity focusedEntity, boolean thirdPerson,
5050
boolean inverseView, float tickDelta, CallbackInfo ci) {
5151
this.pitch = Freelook.getInstance().pitch(pitch)
52-
* (inverseView && Freelook.getInstance().enabled.get() && Freelook.getInstance().active ? -1 : 1);
52+
* (inverseView && Freelook.getInstance().enabled.get() && Freelook.getInstance().isActive() ? -1 : 1);
5353
this.yaw = Freelook.getInstance().yaw(yaw)
54-
+ (inverseView && Freelook.getInstance().enabled.get() && Freelook.getInstance().active ? 180 : 0);
54+
+ (inverseView && Freelook.getInstance().enabled.get() && Freelook.getInstance().isActive() ? 180 : 0);
5555
}
5656

5757
@ModifyArgs(method = "update", at = @At(value = "INVOKE", target = "net/minecraft/client/render/Camera.setRotation(FF)V", ordinal = 0))
@@ -62,7 +62,7 @@ public abstract class CameraMixin {
6262

6363
@ModifyArg(method = "update", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/Camera;moveBy(DDD)V", ordinal = 0), index = 0)
6464
private double axolotlclient$correctDistance(double x) {
65-
if (Freelook.getInstance().enabled.get() && Freelook.getInstance().active
65+
if (Freelook.getInstance().enabled.get() && Freelook.getInstance().isActive()
6666
&& MinecraftClient.getInstance().options.getPerspective().isFrontView()) {
6767
return -clipToSpace(4);
6868
}

0 commit comments

Comments
 (0)