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

Commit 1b76dfe

Browse files
committed
configurable keystrokes
1 parent 7e34971 commit 1b76dfe

File tree

107 files changed

+7005
-840
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+7005
-840
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222

2323
package io.github.axolotlclient;
2424

25+
import java.nio.file.Path;
2526
import java.util.ArrayList;
2627
import java.util.HashMap;
2728
import java.util.List;
2829

30+
import com.google.gson.JsonObject;
2931
import io.github.axolotlclient.AxolotlClientConfig.api.manager.ConfigManager;
3032
import io.github.axolotlclient.AxolotlClientConfig.api.options.OptionCategory;
3133
import io.github.axolotlclient.AxolotlClientConfig.impl.managers.VersionedJsonConfigManager;
@@ -129,7 +131,17 @@ public void onInitializeClient() {
129131

130132
io.github.axolotlclient.AxolotlClientConfig.api.AxolotlClientConfig.getInstance()
131133
.register(configManager = new VersionedJsonConfigManager(FabricLoader.getInstance().getConfigDir().resolve("AxolotlClient.json"),
132-
CONFIG.config, 1, (oldVersion, newVersion, config, json) -> {
134+
CONFIG.config, 2, (oldVersion, newVersion, config, json) -> {
135+
if (oldVersion.getMajor() == 1) {
136+
var keystrokes = json.get("hud").getAsJsonObject().get("keystrokehud")
137+
.getAsJsonObject();
138+
var mousemovement = new JsonObject();
139+
mousemovement.addProperty("enabled", keystrokes.get("mousemovement").getAsBoolean());
140+
mousemovement.addProperty("mouseMovementIndicator", keystrokes.get("mouseMovementIndicator").getAsString());
141+
mousemovement.addProperty("mouseMovementIndicatorOuter", keystrokes.get("mouseMovementIndicatorOuter").getAsString());
142+
json.get("hud").getAsJsonObject().add("mousemovementhud", mousemovement);
143+
}
144+
133145
// convert changed Options between versions here
134146
return json;
135147
}));
@@ -148,4 +160,8 @@ public void onInitializeClient() {
148160

149161
LOGGER.info("AxolotlClient Initialized");
150162
}
163+
164+
public static Path resolveConfigFile(String file) {
165+
return FabricLoader.getInstance().getConfigDir().resolve("axolotlclient").resolve(file);
166+
}
151167
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package io.github.axolotlclient.mixin;
2+
3+
import net.minecraft.client.util.InputUtil;
4+
import net.minecraft.text.Text;
5+
import net.minecraft.text.TranslatableText;
6+
import org.spongepowered.asm.mixin.Mixin;
7+
import org.spongepowered.asm.mixin.injection.At;
8+
import org.spongepowered.asm.mixin.injection.Inject;
9+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
10+
11+
@Mixin(InputUtil.Type.class)
12+
public class InputUtilTypeMixin {
13+
14+
@Inject(method = "method_27450", at = @At(value = "INVOKE", target = "Lorg/lwjgl/glfw/GLFW;glfwGetKeyName(II)Ljava/lang/String;"), cancellable = true)
15+
private static void fixScancodeError(Integer i, String string, CallbackInfoReturnable<Text> cir) {
16+
if (i == -1) {
17+
cir.setReturnValue(new TranslatableText(string));
18+
}
19+
}
20+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright © 2024 moehreag <[email protected]> & Contributors
3+
*
4+
* This file is part of AxolotlClient.
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 3 of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+
*
20+
* For more information, see the LICENSE file.
21+
*/
22+
23+
package io.github.axolotlclient.mixin;
24+
25+
import java.util.Map;
26+
27+
import net.minecraft.client.options.KeyBinding;
28+
import org.spongepowered.asm.mixin.Mixin;
29+
import org.spongepowered.asm.mixin.gen.Accessor;
30+
31+
@Mixin(KeyBinding.class)
32+
public interface KeyBindAccessor {
33+
34+
@Accessor("keysById")
35+
static Map<String, KeyBinding> getAllKeyBinds() {
36+
throw new UnsupportedOperationException();
37+
}
38+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,9 @@ public abstract class MinecraftClientMixin {
8787
private void axolotlclient$onWorldLoad(ClientWorld world, CallbackInfo ci) {
8888
Events.WORLD_LOAD_EVENT.invoker().invoke(new WorldLoadEvent(world));
8989
}
90+
91+
@Inject(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/TitleScreen;<init>()V"))
92+
private void onGameLoad(CallbackInfo ci) {
93+
Events.GAME_LOAD_EVENT.invoker().invoke((MinecraftClient) (Object)this);
94+
}
9095
}

1.16_combat-6/src/main/java/io/github/axolotlclient/modules/hud/HudEditScreen.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ public class HudEditScreen extends Screen {
5454
private static final BooleanOption snapping = new BooleanOption("snapping", true);
5555
private static final OptionCategory hudEditScreenCategory = OptionCategory.create("hudEditScreen");
5656

57+
public static boolean isSnappingEnabled() {
58+
return snapping.get();
59+
}
60+
61+
public static void toggleSnapping() {
62+
snapping.toggle();
63+
}
64+
5765
static {
5866
hudEditScreenCategory.add(snapping);
5967
AxolotlClient.config.add(hudEditScreenCategory);

1.16_combat-6/src/main/java/io/github/axolotlclient/modules/hud/HudManager.java

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,14 @@
2222

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

25+
import java.io.IOException;
26+
import java.nio.file.Files;
27+
import java.nio.file.Path;
2528
import java.util.*;
2629
import java.util.stream.Collectors;
2730

2831
import io.github.axolotlclient.AxolotlClient;
32+
import io.github.axolotlclient.AxolotlClientConfig.api.options.Option;
2933
import io.github.axolotlclient.AxolotlClientConfig.api.options.OptionCategory;
3034
import io.github.axolotlclient.modules.AbstractModule;
3135
import io.github.axolotlclient.modules.hud.gui.AbstractHudEntry;
@@ -38,6 +42,10 @@
3842
import io.github.axolotlclient.modules.hud.gui.hud.vanilla.*;
3943
import io.github.axolotlclient.modules.hud.util.Rectangle;
4044
import io.github.axolotlclient.modules.hypixel.bedwars.BedwarsMod;
45+
import io.github.axolotlclient.util.GsonHelper;
46+
import io.github.axolotlclient.util.events.Events;
47+
import io.github.axolotlclient.util.options.GenericOption;
48+
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
4149
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
4250
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
4351
import net.minecraft.client.MinecraftClient;
@@ -55,6 +63,7 @@
5563

5664
public class HudManager extends AbstractModule {
5765

66+
private final static Path CUSTOM_MODULE_SAVE_PATH = AxolotlClient.resolveConfigFile("custom_hud.json");
5867
private final static HudManager INSTANCE = new HudManager();
5968
private final OptionCategory hudCategory = OptionCategory.create("hud");
6069
private final Map<Identifier, HudEntry> entries;
@@ -108,11 +117,74 @@ public void init() {
108117
add(new TPSHud());
109118
add(new ComboHud());
110119
add(new PlayerHud());
120+
add(new MouseMovementHud());
111121
entries.put(BedwarsMod.getInstance().getUpgradesOverlay().getId(), BedwarsMod.getInstance().getUpgradesOverlay());
112122

113123
entries.values().forEach(HudEntry::init);
114124

115125
refreshAllBounds();
126+
127+
Events.GAME_LOAD_EVENT.register(mc -> loadCustomEntries());
128+
129+
hudCategory.add(new GenericOption("hud.custom_entry", "hud.custom_entry.add", () -> {
130+
CustomHudEntry entry = new CustomHudEntry();
131+
entry.setEnabled(true);
132+
entry.init();
133+
entry.onBoundsUpdate();
134+
entry.getAllOptions().includeInParentTree(false);
135+
add(entry);
136+
client.currentScreen.resize(client, client.currentScreen.width, client.currentScreen.height);
137+
saveCustomEntries();
138+
}));
139+
ClientLifecycleEvents.CLIENT_STOPPING.register(client -> saveCustomEntries());
140+
}
141+
142+
@SuppressWarnings("unchecked")
143+
private void loadCustomEntries() {
144+
try {
145+
if (Files.exists(CUSTOM_MODULE_SAVE_PATH)) {
146+
var obj = (List<Object>) GsonHelper.read(Files.readString(CUSTOM_MODULE_SAVE_PATH));
147+
obj.forEach(o -> {
148+
CustomHudEntry entry = new CustomHudEntry();
149+
var values = (Map<String, Object>)o;
150+
entry.getAllOptions().getOptions().forEach(opt -> {
151+
if (values.containsKey(opt.getName())) {
152+
opt.fromSerializedValue((String) values.get(opt.getName()));
153+
}
154+
});
155+
entry.getCategory().includeInParentTree(false);
156+
add(entry);
157+
entry.init();
158+
entry.onBoundsUpdate();
159+
});
160+
}
161+
} catch (IOException e) {
162+
//TODO notify
163+
}
164+
}
165+
166+
public void saveCustomEntries() {
167+
try {
168+
Files.createDirectories(CUSTOM_MODULE_SAVE_PATH.getParent());
169+
var writer = Files.newBufferedWriter(CUSTOM_MODULE_SAVE_PATH);
170+
var json = GsonHelper.GSON.newJsonWriter(writer);
171+
json.beginArray();
172+
for (Map.Entry<Identifier, HudEntry> entry : entries.entrySet()) {
173+
HudEntry hudEntry = entry.getValue();
174+
if (hudEntry instanceof CustomHudEntry hud) {
175+
json.beginObject();
176+
for (Option<?> opt : hud.getCategory().getOptions()) {
177+
json.name(opt.getName());
178+
json.value(opt.toSerializedValue());
179+
}
180+
json.endObject();
181+
}
182+
}
183+
json.endArray();
184+
json.close();
185+
} catch (IOException e) {
186+
//TODO notify
187+
}
116188
}
117189

118190
public void tick() {
@@ -133,7 +205,7 @@ public void refreshAllBounds() {
133205
}
134206

135207
public List<HudEntry> getEntries() {
136-
if (entries.size() > 0) {
208+
if (!entries.isEmpty()) {
137209
return new ArrayList<>(entries.values());
138210
}
139211
return new ArrayList<>();
@@ -143,6 +215,10 @@ public HudEntry get(Identifier identifier) {
143215
return entries.get(identifier);
144216
}
145217

218+
public void removeEntry(Identifier identifier) {
219+
hudCategory.getSubCategories().remove(entries.remove(identifier).getCategory());
220+
}
221+
146222
public void render(MatrixStack matrices, float delta) {
147223
client.getProfiler().push("Hud Modules");
148224
if (!(client.currentScreen instanceof HudEditScreen)) {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ public abstract class AbstractHudEntry extends DrawUtil implements HudEntry {
7373
public AbstractHudEntry(int width, int height) {
7474
this.width = width;
7575
this.height = height;
76+
truePosition = new DrawPosition(0, 0);
77+
renderPosition = new DrawPosition(0, 0);
78+
renderBounds = new Rectangle(0, 0, 1, 1);
79+
trueBounds = new Rectangle(0, 0, 1, 1);
7680
}
7781

7882
public static float intToFloat(int current, int max, int offset) {

0 commit comments

Comments
 (0)