Compare commits
1 Commits
1.21.5-7
...
1.21.5-7v2
| Author | SHA1 | Date | |
|---|---|---|---|
| f2e1d3e7c9 |
@@ -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 {
|
||||||
|
|||||||
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,
|
"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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user