Moved on from tick-based system
Some checks failed
build / build (push) Has been cancelled

This commit is contained in:
2025-07-30 19:35:30 -04:00
parent 3bea362e81
commit f2e1d3e7c9
4 changed files with 57 additions and 29 deletions

View File

@@ -42,7 +42,6 @@ dependencies {
// Fabric API. This is technically optional, but you probably want it anyway. // Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
} }
processResources { processResources {

View File

@@ -7,12 +7,12 @@ import net.minecraft.text.Text;
import net.minecraft.client.util.InputUtil; import net.minecraft.client.util.InputUtil;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFW;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import java.util.*; import java.util.*;
public class PriorityKeysClient implements ClientModInitializer { public class PriorityKeysClient implements ClientModInitializer {
private static final Set<Integer> keysPressedThisTick = new HashSet<>();
private static KeyBinding cyclePresetKey; private static KeyBinding cyclePresetKey;
@Override @Override
@@ -42,24 +42,7 @@ public class PriorityKeysClient implements ClientModInitializer {
PriorityConfig.save(); PriorityConfig.save();
client.player.sendMessage(Text.of("§aSwitched to priority preset: §f" + next), true); client.player.sendMessage(Text.of("§aSwitched to priority preset: §f" + next), true);
} }
KeyBinding[] currentHotbarKeys = client.options.hotbarKeys;
keysPressedThisTick.clear();
for (int i = 0; i < currentHotbarKeys.length; i++) {
if (currentHotbarKeys[i].isPressed()) {
keysPressedThisTick.add(i);
}
}
if (keysPressedThisTick.size() > 1) {
for (int slot : PriorityConfig.priorityOrder) {
if (keysPressedThisTick.contains(slot)) {
client.player.getInventory().setSelectedSlot(slot);
break;
}
}
}
}); });
} }
} }

View File

@@ -0,0 +1,45 @@
package me.advait.mixin.client;
import me.advait.PriorityConfig;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.option.KeyBinding;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.ArrayList;
import java.util.List;
@Mixin(MinecraftClient.class)
public class MinecraftClientMixin {
@Inject(method = "handleInputEvents", at = @At("HEAD"))
private void onHandleInputEvents(CallbackInfo ci) {
MinecraftClient client = MinecraftClient.getInstance();
if (client.player == null || client.options == null) return;
if (client.player.isSpectator()) return;
KeyBinding[] hotbarKeys = client.options.hotbarKeys;
List<Integer> pressedSlots = new ArrayList<>();
for (int i = 0; i < hotbarKeys.length; i++) {
if (hotbarKeys[i].wasPressed()) {
pressedSlots.add(i);
}
}
if (pressedSlots.size() > 1) {
for (int slot : PriorityConfig.priorityOrder) {
if (pressedSlots.contains(slot)) {
client.player.getInventory().setSelectedSlot(slot);
break;
}
}
} else if (pressedSlots.size() == 1) {
client.player.getInventory().setSelectedSlot(pressedSlots.get(0));
}
}
}

View File

@@ -1,12 +1,13 @@
{ {
"required": true, "required": true,
"package": "me.advait.mixin.client", "package": "me.advait.mixin.client",
"compatibilityLevel": "JAVA_21", "compatibilityLevel": "JAVA_21",
"client": [ "client": [
"ControlsOptionsScreenMixin", "ControlsOptionsScreenMixin",
"GameOptionsScreenAccessor" "GameOptionsScreenAccessor",
], "MinecraftClientMixin"
"injectors": { ],
"defaultRequire": 1 "injectors": {
"defaultRequire": 1
} }
} }