Skip to content

Commit

Permalink
Apply old fixes from 1.2.0
Browse files Browse the repository at this point in the history
 - I just wrongly worked on the 1.1.x base :(
  • Loading branch information
XIAYM-gh committed Jul 13, 2024
1 parent 1da137a commit 3e4c175
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/main/java/cn/xiaym/skin/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
import net.fabricmc.api.ClientModInitializer;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import org.lwjgl.glfw.GLFW;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Main implements ClientModInitializer {
public static final KeyBinding MANUAL_KEY = new KeyBinding(
"keybinding.skinpr.refreshManually",
InputUtil.Type.KEYSYM,
GLFW.GLFW_KEY_N,
"category.skinpr.keybindings"
);
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/cn/xiaym/skin/mixin/KeyBindingHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,36 @@
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.gen.Accessor;
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.Map;

public class KeyBindingHandler {
@Mixin(KeyBinding.class)
public interface CategoryAccessor {
@Accessor("CATEGORY_ORDER_MAP")
static Map<String, Integer> getCategoryMap() {
throw new AssertionError();
}
}

@Mixin(GameOptions.class)
public static class Binder {
@Shadow
@Final
@Mutable
public KeyBinding[] allKeys;

@SuppressWarnings("all")
@Inject(method = "load()V", at = @At("HEAD"))
public void registerKey(CallbackInfo info) {
Map<String, Integer> categories = CategoryAccessor.getCategoryMap();
categories.put(Main.MANUAL_KEY.getCategory(),
categories.values().stream().max(Integer::compareTo).orElse(0) + 1);

KeyBinding[] bindings = new KeyBinding[allKeys.length + 1];
System.arraycopy(allKeys, 0, bindings, 0, allKeys.length);
bindings[bindings.length - 1] = Main.MANUAL_KEY;
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/show-my-skin-parts.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"client": [
"DimensionChangeHandler",
"KeyBindingHandler$Binder",
"KeyBindingHandler$CategoryAccessor",
"KeyBindingHandler$PressHandler",
"PlayerRendererMixin",
"RespawnHandler"
Expand Down

0 comments on commit 3e4c175

Please sign in to comment.