41 lines
1.5 KiB
Java
41 lines
1.5 KiB
Java
package fr.username404.snowygui.mixins;
|
|
|
|
import com.google.common.collect.Lists;
|
|
import net.minecraft.client.KeyMapping;
|
|
import net.minecraft.client.Minecraft;
|
|
import net.minecraft.client.Options;
|
|
import org.spongepowered.asm.mixin.Final;
|
|
import org.spongepowered.asm.mixin.Mixin;
|
|
import org.spongepowered.asm.mixin.Mutable;
|
|
import org.spongepowered.asm.mixin.Shadow;
|
|
import fr.username404.snowygui.config.AddKeyMaps;
|
|
import org.spongepowered.asm.mixin.injection.At;
|
|
import org.spongepowered.asm.mixin.injection.Inject;
|
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
|
|
import java.io.File;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Optional;
|
|
|
|
@Mixin(Options.class)
|
|
class KeyMappings {
|
|
private static final List<KeyMapping> keysToAdd = AddKeyMaps.INSTANCE.getList();
|
|
|
|
@Mutable @Shadow @Final public KeyMapping[] keyMappings;
|
|
|
|
@Inject(method = "<init>*", at = @At("RETURN"))
|
|
private void onSettingsConstructed(Minecraft minecraft, File file, CallbackInfo ci) {
|
|
Map<String, Integer> categoryMap = KeysAccessor.getSortedCategoryMap();
|
|
List<KeyMapping> newKeys = Lists.newArrayList(keyMappings);
|
|
for (KeyMapping key : keysToAdd) {
|
|
if (!categoryMap.containsKey(key.getCategory())) {
|
|
Optional<Integer> biggest = categoryMap.values().stream().max(Integer::compareTo); int biggestInt = biggest.orElse(0);
|
|
categoryMap.put(key.getCategory(), biggestInt + 1);
|
|
}
|
|
newKeys.remove(key);
|
|
newKeys.add(key);
|
|
}
|
|
keyMappings = newKeys.toArray(new KeyMapping[0]);
|
|
}
|
|
} |