Skip to content

Commit

Permalink
disable sorting when middle clicking a stack in creative
Browse files Browse the repository at this point in the history
  • Loading branch information
JaisDK committed Aug 7, 2024
1 parent c74539d commit 65959db
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ dependencies {
implementation "curse.maven:jei-238222:5525108"
implementation "curse.maven:productivebees-377897:5512587"
implementation "curse.maven:iron-furnaces-237664:5489826"
implementation "curse.maven:just-dire-things-1002348:5529221"
}

tasks.withType(ProcessResources).configureEach {
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/invtweaks/config/InvTweaksConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,18 @@ public class InvTweaksConfig {
.put("com.direwolf20.laserio.client.screens.*", new ContOverride(NO_POS_OVERRIDE, NO_POS_OVERRIDE, ""))
.put("cofh.thermal.core.client.gui.*", new ContOverride(NO_POS_OVERRIDE, NO_POS_OVERRIDE, ""))
.put("ironfurnaces.gui.furnaces.*", new ContOverride(NO_POS_OVERRIDE, NO_POS_OVERRIDE, "0-45"))

.put("com.direwolf20.justdirethings.client.screens.*", new ContOverride(NO_POS_OVERRIDE, NO_POS_OVERRIDE, ""))
.put("com.glodblock.github.extendedae.client.gui.*", new ContOverride(NO_POS_OVERRIDE, NO_POS_OVERRIDE, ""))
.build();

private static final ModConfigSpec.ConfigValue<List<? extends UnmodifiableConfig>> CATS;
private static final ModConfigSpec.ConfigValue<List<? extends String>> RULES;
private static final ModConfigSpec.BooleanValue ENABLE_DEBUG;
private static final ModConfigSpec.BooleanValue ENABLE_AUTOREFILL;
private static final ModConfigSpec.BooleanValue ENABLE_QUICKVIEW;
private static final ModConfigSpec.IntValue ENABLE_SORT;
private static final ModConfigSpec.IntValue ENABLE_BUTTONS;
private static final ModConfigSpec.ConfigValue<List<? extends UnmodifiableConfig>>
CONT_OVERRIDES;
private static final ModConfigSpec.ConfigValue<List<? extends UnmodifiableConfig>> CONT_OVERRIDES;
private static final Map<UUID, Map<String, Category>> playerToCats = new HashMap<>();
private static final Map<UUID, Ruleset> playerToRules = new HashMap<>();
private static final Set<UUID> playerAutoRefill = new HashSet<>();
Expand Down Expand Up @@ -166,6 +167,7 @@ public class InvTweaksConfig {
{
builder.comment("Tweaks").push("tweaks");

ENABLE_DEBUG = builder.comment("Enable debug will log the name of the screens being opened").define("enableDebug", false);
ENABLE_AUTOREFILL = builder.comment("Enable auto-refill").define("autoRefill", true);
ENABLE_QUICKVIEW =
builder
Expand Down Expand Up @@ -333,6 +335,10 @@ public static boolean isQuickViewEnabled() {
return ENABLE_QUICKVIEW.get();
}

public static boolean isDebugEnabled() {
return ENABLE_DEBUG.get();
}

public static Map<String, Category> cfgToCompiledCats(List<UnmodifiableConfig> lst) {
Map<String, Category> catsMap = new LinkedHashMap<>();
for (UnmodifiableConfig subCfg : lst) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/invtweaks/events/ClientEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ public static void onMouseButtonPressed(ScreenEvent.MouseButtonPressed.Pre event

Slot slot = screen.getSlotUnderMouse();
if (slot != null) {
// Disable sort if in creative and has clicked a non-empty slot
if (Minecraft.getInstance().player.isCreative() && slot.hasItem()) {
return;
}
boolean isPlayerSort = Utils.isPlayerContainer(slot.container, screen, Minecraft.getInstance().player);
if (InvTweaksConfig.isSortEnabled(isPlayerSort) && (isPlayerSort || screensWithExtSort.contains(event.getScreen()))) {
requestSort(isPlayerSort, screen.getClass().getName());
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/invtweaks/util/Sorting.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@

public class Sorting {
public static void executeSort(Player player, boolean isPlayerSort, String screenClass) {
InvTweaksMod.LOGGER.debug("opened screen: " + screenClass);
if (InvTweaksConfig.isDebugEnabled()) {
InvTweaksMod.LOGGER.debug("screen: " + screenClass);
}
if (isPlayerSort) {
Map<String, Category> cats = InvTweaksConfig.getPlayerCats(player);
Ruleset rules = InvTweaksConfig.getPlayerRules(player);
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/invtweaks/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,6 @@ public static List<ItemStack> condensed(Iterable<ItemStack> iterable) {

public static boolean isPlayerContainer(Container container, AbstractContainerScreen<?> screen, @Nullable Player player) {
Slot slot = screen.getSlotUnderMouse();
// for (int i = 0; i < container.getContainerSize(); i++) {
// InvTweaksMod.LOGGER.info("slot " + i + " contains " + container.getItem(i));
// }
if (slot != null) {
if (slot.container instanceof InvWrapper invWrapper) {
return invWrapper.getInv() instanceof Inventory;
Expand Down

0 comments on commit 65959db

Please sign in to comment.