This commit is contained in:
@@ -7,12 +7,12 @@ import net.minecraft.text.Text;
|
||||
import net.minecraft.client.util.InputUtil;
|
||||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class PriorityKeysClient implements ClientModInitializer {
|
||||
|
||||
private static final Set<Integer> keysPressedThisTick = new HashSet<>();
|
||||
private static KeyBinding cyclePresetKey;
|
||||
|
||||
@Override
|
||||
@@ -42,24 +42,7 @@ public class PriorityKeysClient implements ClientModInitializer {
|
||||
PriorityConfig.save();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
{
|
||||
"required": true,
|
||||
"package": "me.advait.mixin.client",
|
||||
"compatibilityLevel": "JAVA_21",
|
||||
"client": [
|
||||
"ControlsOptionsScreenMixin",
|
||||
"GameOptionsScreenAccessor"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
"required": true,
|
||||
"package": "me.advait.mixin.client",
|
||||
"compatibilityLevel": "JAVA_21",
|
||||
"client": [
|
||||
"ControlsOptionsScreenMixin",
|
||||
"GameOptionsScreenAccessor",
|
||||
"MinecraftClientMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user