Skip to content

Commit

Permalink
Add a toggle for hotbar sorting (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
0hwx authored Jan 17, 2025
1 parent c9f1aa8 commit 428eba8
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.cleanroommc.bogosorter.api.SortRule;
import com.cleanroommc.bogosorter.common.config.BogoSorterConfig;
import com.cleanroommc.bogosorter.common.config.ConfigGui;
import com.cleanroommc.bogosorter.common.config.PlayerConfig;
import com.cleanroommc.bogosorter.common.dropoff.DropOffHandler;
import com.cleanroommc.bogosorter.common.dropoff.render.RendererCube;
import com.cleanroommc.bogosorter.common.network.CDropOff;
Expand Down Expand Up @@ -344,7 +345,8 @@ public static boolean sort(GuiScreen guiScreen, @Nullable ISlot slot) {
.get(0);
} else {
slotGroup = sortingContext.getSlotGroup(slot.bogo$getSlotNumber());
if (slotGroup == null || slotGroup.isEmpty()) return false;
if (slotGroup == null || slotGroup.isEmpty()
|| (slotGroup.isHotbar() && !PlayerConfig.getClient().enableHotbarSort)) return false;
}

List<SortRule<ItemStack>> sortRules = BogoSorterConfig.sortRules;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class BogoSorterConfig {
public static void save(JsonObject json) {
PlayerConfig playerConfig = PlayerConfig.getClient();
JsonObject general = new JsonObject();
general.addProperty("enableHotbarSort", playerConfig.enableHotbarSort);
general.addProperty("enableAutoRefill", playerConfig.enableAutoRefill);
general.addProperty("refillDmgThreshold", playerConfig.autoRefillDamageThreshold);
general.addProperty("enableDropoff", DropOffHandler.enableDropOff);
Expand Down Expand Up @@ -93,6 +94,7 @@ public static void load(JsonObject json) {
PlayerConfig playerConfig = PlayerConfig.getClient();
if (json.has("General")) {
JsonObject general = json.getAsJsonObject("General");
playerConfig.enableHotbarSort = JsonHelper.getBoolean(general, true, "enableHotbarSort");
playerConfig.enableAutoRefill = JsonHelper.getBoolean(general, true, "enableAutoRefill");
playerConfig.autoRefillDamageThreshold = (short) JsonHelper.getInt(general, 1, "refillDmgThreshold");
DropOffHandler.enableDropOff = JsonHelper.getBoolean(general, true, "enableDropoff");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,27 @@ public IWidget createGeneralConfigUI(GuiContext context) {
.top(1)
.left(32)
.size(1, 56))
.child(
new Row().widthRel(1f)
.height(14)
.margin(0, 2)
.child(
new CycleButtonWidget()
.value(
new BoolValue.Dynamic(
() -> PlayerConfig.getClient().enableHotbarSort,
val -> PlayerConfig.getClient().enableHotbarSort = val))
.stateOverlay(TOGGLE_BUTTON)
.disableHoverBackground()
.size(14, 14)
.margin(8, 0)
.background(IDrawable.EMPTY))
.child(
IKey.lang("bogosort.gui.enable_hotbarSort")
.asWidget()
.height(14)
.marginLeft(10)
.expanded()))
.child(
new Row().widthRel(1f)
.height(14)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class PlayerConfig {

private static final Map<EntityPlayerMP, PlayerConfig> playerConfig = new Object2ObjectOpenHashMap<>();
private static final PlayerConfig CLIENT = new PlayerConfig();
public boolean enableHotbarSort = true;
public boolean enableAutoRefill = true;
public int autoRefillDamageThreshold = 1;

Expand All @@ -44,11 +45,13 @@ public static PlayerConfig getClient() {
}

public void writePacket(PacketBuffer buffer) {
buffer.writeBoolean(enableHotbarSort);
buffer.writeBoolean(enableAutoRefill);
buffer.writeVarIntToBuffer(autoRefillDamageThreshold);
}

public void readPacket(PacketBuffer buffer) {
enableHotbarSort = buffer.readBoolean();
enableAutoRefill = buffer.readBoolean();
autoRefillDamageThreshold = buffer.readVarIntFromBuffer();
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/bogosorter/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ bogosort.gui.tab.item_sort_rules.name=Item sort rules
bogosort.gui.tab.nbt_sort_rules.name=NBT sort rules
bogosort.gui.available_sort_rules=Available Sort-Rules
bogosort.gui.configured_sort_rules=Configured Sort-Rules
bogosort.gui.enable_hotbarSort=Enable hotbar sorting
bogosort.gui.enable_refill=Enable auto hotbar refill
bogosort.gui.refill_comment=Quark is installed. If this option is disabled, theirs might still be enabled. You can find the config at 'Management' -> 'Automatic Tool Restock'.
bogosort.gui.refill_threshold=Auto refill damage threshold
Expand Down

0 comments on commit 428eba8

Please sign in to comment.