Skip to content

Commit

Permalink
add sortInventoryShulkerBoxLastType.AUTO
Browse files Browse the repository at this point in the history
  • Loading branch information
plusls committed Jan 16, 2022
1 parent b9adebf commit 7a90e2d
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 2 deletions.
57 changes: 56 additions & 1 deletion src/main/java/com/plusls/ommc/config/Configs.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<IConfigBase> OPTIONS = ImmutableList.of(
OPEN_CONFIG_GUI,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ static class ItemStackComparator implements Comparator<ItemStack> {
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)) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/assets/ommc/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/assets/ommc/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "调试模式",
Expand Down

0 comments on commit 7a90e2d

Please sign in to comment.