From 7a90e2dad31364eb011d15ca3c13e53f47ce071f Mon Sep 17 00:00:00 2001 From: plusls Date: Mon, 17 Jan 2022 00:59:44 +0800 Subject: [PATCH] add sortInventoryShulkerBoxLastType.AUTO --- .../java/com/plusls/ommc/config/Configs.java | 57 ++++++++++++++++++- .../sortInventory/SortInventoryUtil.java | 3 +- .../resources/assets/ommc/lang/en_us.json | 3 + .../resources/assets/ommc/lang/zh_cn.json | 3 + 4 files changed, 64 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/plusls/ommc/config/Configs.java b/src/main/java/com/plusls/ommc/config/Configs.java index e40feb0..fd7640a 100644 --- a/src/main/java/com/plusls/ommc/config/Configs.java +++ b/src/main/java/com/plusls/ommc/config/Configs.java @@ -11,6 +11,7 @@ import fi.dy.masa.malilib.config.ConfigUtils; import fi.dy.masa.malilib.config.IConfigBase; import fi.dy.masa.malilib.config.IConfigHandler; +import fi.dy.masa.malilib.config.IConfigOptionListEntry; import fi.dy.masa.malilib.config.options.*; import fi.dy.masa.malilib.gui.GuiBase; import fi.dy.masa.malilib.hotkeys.KeybindSettings; @@ -19,6 +20,7 @@ import fi.dy.masa.malilib.util.restrictions.UsageRestriction; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayerInteractionManager; +import net.minecraft.client.resource.language.I18n; import net.minecraft.client.sound.PositionedSoundInstance; import net.minecraft.entity.Entity; import net.minecraft.sound.SoundEvents; @@ -145,7 +147,60 @@ public static class Generic { SEND_LOOKING_AT_BLOCK_POS, SORT_INVENTORY ); - public static final ConfigBoolean SORT_INVENTORY_SHULKER_BOX_LAST = new TranslatableConfigBoolean(PREFIX, "sortInventoryShulkerBoxLast", false); + public static final ConfigOptionList SORT_INVENTORY_SHULKER_BOX_LAST = new TranslatableConfigOptionList(PREFIX, "sortInventoryShulkerBoxLast", SortInventoryShulkerBoxLastType.AUTO); + + public enum SortInventoryShulkerBoxLastType implements IConfigOptionListEntry { + FALSE("false", "ommc.gui.label.sort_inventory_shulker_box_last_type.false"), + TRUE("true", "ommc.gui.label.sort_inventory_shulker_box_last_type.true"), + AUTO("auto", "ommc.gui.label.sort_inventory_shulker_box_last_type.auto"); + private final String configString; + private final String translationKey; + + SortInventoryShulkerBoxLastType(String configString, String translationKey) { + this.configString = configString; + this.translationKey = translationKey; + } + + @Override + public String getStringValue() { + return this.configString; + } + + @Override + public String getDisplayName() { + return I18n.translate(this.translationKey); + } + + @Override + public IConfigOptionListEntry cycle(boolean forward) { + int id = this.ordinal(); + if (forward) { + ++id; + if (id >= values().length) { + id = 0; + } + } else { + --id; + if (id < 0) { + id = values().length - 1; + } + } + + return values()[id % values().length]; + } + + @Override + public IConfigOptionListEntry fromString(String name) { + SortInventoryShulkerBoxLastType[] values = values(); + for (SortInventoryShulkerBoxLastType mode : values) { + if (mode.configString.equalsIgnoreCase(name)) { + return mode; + } + } + return AUTO; + } + } + public static final ConfigBoolean SORT_INVENTORY_SUPPORT_EMPTY_SHULKER_BOX_STACK = new TranslatableConfigBoolean(PREFIX, "sortInventorySupportEmptyShulkerBoxStack", false); public static final ImmutableList OPTIONS = ImmutableList.of( OPEN_CONFIG_GUI, diff --git a/src/main/java/com/plusls/ommc/feature/sortInventory/SortInventoryUtil.java b/src/main/java/com/plusls/ommc/feature/sortInventory/SortInventoryUtil.java index ffa1f1a..d7b2cec 100644 --- a/src/main/java/com/plusls/ommc/feature/sortInventory/SortInventoryUtil.java +++ b/src/main/java/com/plusls/ommc/feature/sortInventory/SortInventoryUtil.java @@ -260,7 +260,8 @@ static class ItemStackComparator implements Comparator { public int compare(ItemStack a, ItemStack b) { int aId = getItemId(a); int bId = getItemId(b); - if (!allShulkerBox && Configs.Generic.SORT_INVENTORY_SHULKER_BOX_LAST.getBooleanValue()) { + if (Configs.Generic.SORT_INVENTORY_SHULKER_BOX_LAST.getOptionListValue() == Configs.Generic.SortInventoryShulkerBoxLastType.TRUE || + (Configs.Generic.SORT_INVENTORY_SHULKER_BOX_LAST.getOptionListValue() == Configs.Generic.SortInventoryShulkerBoxLastType.AUTO && !allShulkerBox)) { if (ShulkerBoxItemUtil.isShulkerBoxBlockItem(a) && !ShulkerBoxItemUtil.isShulkerBoxBlockItem(b)) { return 1; } else if (!ShulkerBoxItemUtil.isShulkerBoxBlockItem(a) && ShulkerBoxItemUtil.isShulkerBoxBlockItem(b)) { diff --git a/src/main/resources/assets/ommc/lang/en_us.json b/src/main/resources/assets/ommc/lang/en_us.json index cbee239..53edf93 100644 --- a/src/main/resources/assets/ommc/lang/en_us.json +++ b/src/main/resources/assets/ommc/lang/en_us.json @@ -5,6 +5,9 @@ "ommc.gui.button.config_gui.feature_hotkey": "Feature Hotkeys", "ommc.gui.button.config_gui.lists": "Lists", "ommc.gui.button.config_gui.advanced_integrated_server": "Advanced Integrated Server", + "ommc.gui.label.sort_inventory_shulker_box_last_type.false": "FALSE", + "ommc.gui.label.sort_inventory_shulker_box_last_type.true": "TRUE", + "ommc.gui.label.sort_inventory_shulker_box_last_type.auto": "AUTO", "ommc.config.generic.openConfigGui.name": "openConfigGui", "ommc.config.generic.openConfigGui.comment": "A hotkey to open the in-game Config GUI", "ommc.config.generic.debug.name": "debug", diff --git a/src/main/resources/assets/ommc/lang/zh_cn.json b/src/main/resources/assets/ommc/lang/zh_cn.json index 7ed34b3..8b6028e 100644 --- a/src/main/resources/assets/ommc/lang/zh_cn.json +++ b/src/main/resources/assets/ommc/lang/zh_cn.json @@ -5,6 +5,9 @@ "ommc.gui.button.config_gui.feature_hotkey": "特性快捷键", "ommc.gui.button.config_gui.lists": "列表", "ommc.gui.button.config_gui.advanced_integrated_server": "本地服务器设置", + "ommc.gui.label.sort_inventory_shulker_box_last_type.false": "关闭", + "ommc.gui.label.sort_inventory_shulker_box_last_type.true": "开启", + "ommc.gui.label.sort_inventory_shulker_box_last_type.auto": "自动", "ommc.config.generic.openConfigGui.name": "打开设置界面", "ommc.config.generic.openConfigGui.comment": "打开设置界面的快捷键", "ommc.config.generic.debug.name": "调试模式",