From 72c8214da25e4fee2e3319f4cb4a214878307b21 Mon Sep 17 00:00:00 2001 From: telontelvarost Date: Fri, 26 Jan 2024 01:09:55 -0500 Subject: [PATCH 01/13] ISSUE-8 - Port in mouse tweak fixes that are completed so far --- gradle.properties | 2 +- .../telvarost/inventorytweaks/Config.java | 19 +- .../mixin/ContainerBaseMixin.java | 674 +++++++++++------- 3 files changed, 449 insertions(+), 246 deletions(-) diff --git a/gradle.properties b/gradle.properties index 652148b..a50c180 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ yarn_mappings=b1.7.3-build.2 loader_version=0.14.24-babric.1 # Mod Properties -mod_version=1.1.2 +mod_version=2.0.0 maven_group=com.github.telvarost archives_base_name=InventoryTweaks diff --git a/src/main/java/com/github/telvarost/inventorytweaks/Config.java b/src/main/java/com/github/telvarost/inventorytweaks/Config.java index ecd1f77..f0f2bb2 100644 --- a/src/main/java/com/github/telvarost/inventorytweaks/Config.java +++ b/src/main/java/com/github/telvarost/inventorytweaks/Config.java @@ -1,5 +1,6 @@ package com.github.telvarost.inventorytweaks; +import blue.endless.jankson.Comment; import net.glasslauncher.mods.api.gcapi.api.ConfigName; import net.glasslauncher.mods.api.gcapi.api.GConfig; @@ -10,7 +11,21 @@ public class Config { public static class ConfigFields { -// @ConfigName("Fix double doors") -// public static Boolean FIX_DOUBLE_DOORS = true; + @ConfigName("Empty-hand [Shift + Left-Click + Drag]") + @Comment("[Shift-Click] items of any type") + public static Boolean LMBTweakWithoutItem = true; + + @ConfigName("Prefer [Shift-Click] over [Left-Click + Drag]") + public static Boolean LMBPreferShiftClick = true; + + @ConfigName("Prefer [Shift-Click] over [Right-Click + Drag]") + public static Boolean RMBPreferShiftClick = true; + + @ConfigName("[Right-Click + Drag] over existing slots") + public static Boolean RMBTweak = true; + + @ConfigName("[Left-Click + Drag] to pick up items") + @Comment("Hold [Shift] to [Shift-Click] items instead") + public static Boolean LMBTweakWithItem = true; } } diff --git a/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java b/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java index 9282f5e..f38c9fc 100644 --- a/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java +++ b/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java @@ -1,8 +1,8 @@ package com.github.telvarost.inventorytweaks.mixin; +import com.github.telvarost.inventorytweaks.Config; import net.minecraft.client.gui.screen.ScreenBase; import net.minecraft.client.gui.screen.container.ContainerBase; -import net.minecraft.item.ItemBase; import net.minecraft.item.ItemInstance; import net.minecraft.container.slot.Slot; import org.lwjgl.input.Keyboard; @@ -45,10 +45,16 @@ public abstract class ContainerBaseMixin extends ScreenBase { @Unique int lastLMBSlotId = -1; @Unique - private ItemInstance leftClickPersistentStack; + private ItemInstance leftClickMouseTweaksPersistentStack = null; @Unique - private ItemInstance rightClickPersistentStack; + private ItemInstance leftClickPersistentStack = null; + + @Unique + private ItemInstance rightClickPersistentStack = null; + + @Unique + private boolean isLeftClickDragMouseTweaksStarted = false; @Unique private boolean isLeftClickDragStarted = false; @@ -71,159 +77,61 @@ public abstract class ContainerBaseMixin extends ScreenBase { @Unique List leftClickAmountToFillPersistent = new ArrayList<>(); - @Unique List rightClickAmountToFillPersistent = new ArrayList<>(); - - @Unique private void inventoryTweaks_resetLeftClickDragVariables() - { - leftClickExistingAmount.clear(); - leftClickAmountToFillPersistent.clear(); - leftClickHoveredSlots.clear(); - leftClickPersistentStack = null; - leftClickItemAmount = 0; - isLeftClickDragStarted = false; - } - - @Unique private void inventoryTweaks_resetRightClickDragVariables() - { - rightClickExistingAmount.clear(); - rightClickHoveredSlots.clear(); - rightClickPersistentStack = null; - rightClickItemAmount = 0; - isRightClickDragStarted = false; - } - @Inject(method = "mouseClicked", at = @At("HEAD"), cancellable = true) - protected void inventoryTweaks_mouseClicked(int mouseX, int mouseY, int button, CallbackInfo ci) { + protected void mouseTweaks_mouseClicked(int mouseX, int mouseY, int button, CallbackInfo ci) { + isLeftClickDragMouseTweaksStarted = false; /** - Right-click */ if (button == 1) { - /** - Get held item */ - ItemInstance cursorStack = minecraft.player.inventory.getCursorItem(); + boolean exitFunction = false; - /** - Cancel Left-click + Drag */ - if (isLeftClickDragStarted) { - if (leftClickHoveredSlots.size() > 1) { - /** - Handle if a button was clicked */ - super.mouseClicked(mouseX, mouseY, button); - - /** - Return all slots to normal */ - minecraft.player.inventory.setCursorItem(new ItemInstance(leftClickPersistentStack.itemId, leftClickItemAmount, leftClickPersistentStack.getDamage())); - for (int leftClickHoveredSlotsIndex = 0; leftClickHoveredSlotsIndex < leftClickHoveredSlots.size(); leftClickHoveredSlotsIndex++) { - if (0 != leftClickExistingAmount.get(leftClickHoveredSlotsIndex)) { - leftClickHoveredSlots.get(leftClickHoveredSlotsIndex).setStack(new ItemInstance(leftClickPersistentStack.itemId, leftClickExistingAmount.get(leftClickHoveredSlotsIndex), leftClickPersistentStack.getDamage())); - } else { - leftClickHoveredSlots.get(leftClickHoveredSlotsIndex).setStack(null); - } - } + /** - Should click cancel Left-click + Drag */ + if (!mouseTweaks_cancelLeftClickDrag()) { - /** - Reset Left-click + Drag variables and exit function */ - inventoryTweaks_resetLeftClickDragVariables(); - ci.cancel(); - return; - } + /** - Handle Right-click */ + exitFunction = mouseTweaks_handleRightClick(mouseX, mouseY); + } else { + exitFunction = true; } - /** - Handle Right-click if an item is held */ - if (cursorStack != null) { - /** - Ensure a slot was clicked */ - Slot clickedSlot = this.getSlot(mouseX, mouseY); - if (clickedSlot != null) { - /** - Handle if a button was clicked */ - super.mouseClicked(mouseX, mouseY, button); - - /** - Record how many items are in the slot */ - if (null != clickedSlot.getItem()) { - rightClickExistingAmount.add(clickedSlot.getItem().count); - } - else - { - rightClickExistingAmount.add(0); - } - - /** - Begin Right-click + Drag */ - if (cursorStack != null && rightClickPersistentStack == null && isRightClickDragStarted == false) { - rightClickPersistentStack = cursorStack; - rightClickItemAmount = rightClickPersistentStack.count; - isRightClickDragStarted = true; - } - - /** - Handle initial Right-click */ - lastRMBSlotId = clickedSlot.id; - lastRMBSlot = clickedSlot; - this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, clickedSlot.id, 1, false, this.minecraft.player); - ci.cancel(); - return; - } + if (exitFunction) { + /** - Handle if a button was clicked */ + super.mouseClicked(mouseX, mouseY, button); + ci.cancel(); + return; } } /** - Left-click */ if (button == 0) { - /** - Get held item */ - ItemInstance cursorStack = minecraft.player.inventory.getCursorItem(); + boolean exitFunction = false; - /** - Cancel Right-click + Drag */ - if (isRightClickDragStarted) { - if (rightClickHoveredSlots.size() > 1) { - /** - Handle if a button was clicked */ - super.mouseClicked(mouseX, mouseY, button); - - /** - Return all slots to normal */ - minecraft.player.inventory.setCursorItem(new ItemInstance(rightClickPersistentStack.itemId, rightClickItemAmount, rightClickPersistentStack.getDamage())); - for (int leftClickHoveredSlotsIndex = 0; leftClickHoveredSlotsIndex < rightClickHoveredSlots.size(); leftClickHoveredSlotsIndex++) { - if (0 != rightClickExistingAmount.get(leftClickHoveredSlotsIndex)) { - rightClickHoveredSlots.get(leftClickHoveredSlotsIndex).setStack(new ItemInstance(rightClickPersistentStack.itemId, rightClickExistingAmount.get(leftClickHoveredSlotsIndex), rightClickPersistentStack.getDamage())); - } else { - rightClickHoveredSlots.get(leftClickHoveredSlotsIndex).setStack(null); - } - } + /** - Should click cancel Right-click + Drag */ + if (!mouseTweaks_cancelRightClickDrag()) { - /** - Reset Right-click + Drag variables and exit function */ - inventoryTweaks_resetRightClickDragVariables(); - ci.cancel(); - return; + /** - Handle Left-click */ + ItemInstance cursorStack = minecraft.player.inventory.getCursorItem(); + Slot clickedSlot = this.getSlot(mouseX, mouseY); + if (cursorStack != null) { + exitFunction = mouseTweaks_handleLeftClickWithItem(cursorStack, clickedSlot); + } else { + exitFunction = mouseTweaks_handleLeftClickWithoutItem(clickedSlot); } + } else { + exitFunction = true; } - /** - Handle Left-click if an item is held */ - if (cursorStack != null) { - /** - Ensure a slot was clicked */ - Slot clickedSlot = this.getSlot(mouseX, mouseY); - if (clickedSlot != null) { - /** - Handle if a button was clicked */ - super.mouseClicked(mouseX, mouseY, button); - - /** - Record how many items are in the slot and how many items are needed to fill the slot */ - if (null != clickedSlot.getItem()) { - leftClickAmountToFillPersistent.add(cursorStack.getMaxStackSize() - clickedSlot.getItem().count); - leftClickExistingAmount.add(clickedSlot.getItem().count); - } - else - { - leftClickAmountToFillPersistent.add(cursorStack.getMaxStackSize()); - leftClickExistingAmount.add(0); - } - - /** - Begin Left-click + Drag */ - if (cursorStack != null && leftClickPersistentStack == null && isLeftClickDragStarted == false) { - leftClickPersistentStack = cursorStack; - leftClickItemAmount = leftClickPersistentStack.count; - isLeftClickDragStarted = true; - } - - /** - Handle initial Left-click */ - lastLMBSlotId = clickedSlot.id; - lastLMBSlot = clickedSlot; - this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, clickedSlot.id, 0, false, this.minecraft.player); - ci.cancel(); - return; - } + if (exitFunction) { + /** - Handle if a button was clicked */ + super.mouseClicked(mouseX, mouseY, button); + ci.cancel(); + return; } } } @Inject(method = "mouseReleased", at = @At("RETURN"), cancellable = true) - private void inventoryTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, int button, CallbackInfo ci) { + private void mouseTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, int button, CallbackInfo ci) { slot = this.getSlot(mouseX, mouseY); /** - Do nothing if mouse is not over a slot */ @@ -232,159 +140,439 @@ private void inventoryTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, /** - Right-click + Drag logic = distribute one item from held items to each slot */ if ( ( button == -1 ) - && ( Mouse.isButtonDown(1) ) - && ( isLeftClickDragStarted == false ) - && ( rightClickPersistentStack != null ) - ) + && ( Mouse.isButtonDown(1) ) + && ( isLeftClickDragStarted == false ) + && ( isLeftClickDragMouseTweaksStarted == false ) + && ( rightClickPersistentStack != null ) + ) { - /** - Do nothing if slot has already been added to Right-click + Drag logic */ + ItemInstance slotItemToExamine = slot.getItem(); + + /** - Do nothing if slot item does not match held item or if the slot is full */ + if ( (null != slotItemToExamine) + && ( (!slotItemToExamine.isDamageAndIDIdentical(rightClickPersistentStack)) + || (slotItemToExamine.count == rightClickPersistentStack.getMaxStackSize()) + ) + ) { + return; + } + + /** - Do nothing if there are no more items to distribute */ + ItemInstance cursorStack = minecraft.player.inventory.getCursorItem(); + if (null == cursorStack) { + return; + } + if (!rightClickHoveredSlots.contains(slot)) { - ItemInstance slotItemToExamine = slot.getItem(); + mouseTweaks_handleRightClickDrag(slotItemToExamine); + } else if (Config.ConfigFields.RMBTweak) { + mouseTweaks_handleRightClickDragMouseTweaks(); + } + } else { + mouseTweaks_resetRightClickDragVariables(); + } - /** - Do nothing if slot item does not match held item */ - if (null != slotItemToExamine && !slotItemToExamine.isDamageAndIDIdentical(rightClickPersistentStack)) { + /** - Left-click + Drag logic = evenly distribute held items over slots */ + if ( ( button == -1 ) + && ( Mouse.isButtonDown(0) ) + && ( isRightClickDragStarted == false ) + ) + { + if (isLeftClickDragMouseTweaksStarted) { + mouseTweaks_handleLeftClickDragMouseTweaks(); + } else if ( leftClickPersistentStack != null ) { + if (mouseTweaks_handleLeftClickDrag()) { return; } + } else { + mouseTweaks_resetLeftClickDragVariables(); + } + } else { + mouseTweaks_resetLeftClickDragVariables(); + } + } - /** - Do nothing if there are no more items to distribute */ - if (1.0 == (double)rightClickItemAmount / (double)rightClickHoveredSlots.size()) { - return; + @Unique private boolean mouseTweaks_handleRightClick(int mouseX, int mouseY) { + /** - Get held item */ + ItemInstance cursorStack = minecraft.player.inventory.getCursorItem(); + + /** - Handle Right-click if an item is held */ + if (cursorStack != null) { + + /** - Ensure a slot was clicked */ + Slot clickedSlot = this.getSlot(mouseX, mouseY); + if (clickedSlot != null) { + + /** - Record how many items are in the slot */ + if (null != clickedSlot.getItem()) { + rightClickExistingAmount.add(clickedSlot.getItem().count); + } else { + rightClickExistingAmount.add(0); } - /** - First slot is handled instantly in mouseClicked function */ - if (slot.id != lastRMBSlotId) { - if (0 == rightClickHoveredSlots.size()) - { - /** - Add slot to item distribution */ - rightClickHoveredSlots.add(lastRMBSlot); - } + /** - Begin Right-click + Drag */ + if (cursorStack != null && rightClickPersistentStack == null && isRightClickDragStarted == false) { + rightClickPersistentStack = cursorStack; + rightClickItemAmount = rightClickPersistentStack.count; + isRightClickDragStarted = true; + } - /** - Add slot to item distribution */ - rightClickHoveredSlots.add(slot); + /** - Handle initial Right-click */ + lastRMBSlotId = clickedSlot.id; + lastRMBSlot = clickedSlot; + if (Config.ConfigFields.RMBPreferShiftClick) { + boolean isShiftKeyDown = (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)); + this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, clickedSlot.id, 1, isShiftKeyDown, this.minecraft.player); - /** - Record how many items are in the slot */ - if (null != slotItemToExamine) { - rightClickExistingAmount.add(slotItemToExamine.count); - } - else - { - rightClickExistingAmount.add(0); + if (isShiftKeyDown) { + mouseTweaks_resetRightClickDragVariables(); } - - /** - Distribute one item to the slot */ - this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, slot.id, 1, false, this.minecraft.player); + } else { + this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, clickedSlot.id, 1, false, this.minecraft.player); } + + return true; } - } else { - inventoryTweaks_resetRightClickDragVariables(); } - /** - Left-click + Drag logic = evenly distribute held items over slots */ - if ( ( button == -1 ) - && ( Mouse.isButtonDown(0) ) - && ( isRightClickDragStarted == false ) - && ( leftClickPersistentStack != null ) - ) - { - /** - Do nothing if slot has already been added to Left-click + Drag logic */ - if (!leftClickHoveredSlots.contains(slot)) { - ItemInstance slotItemToExamine = slot.getItem(); + return false; + } - /** - Do nothing if slot item does not match held item */ - if (null != slotItemToExamine && !slotItemToExamine.isDamageAndIDIdentical(leftClickPersistentStack)){ - return; + @Unique private void mouseTweaks_handleRightClickDragMouseTweaks() { + if (slot.id != lastRMBSlotId) { + ItemInstance cursorStack = minecraft.player.inventory.getCursorItem(); + + if (null != cursorStack ) { + /** - Distribute one item to the slot */ + lastRMBSlotId = slot.id; + this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, slot.id, 1, false, this.minecraft.player); + } + } + } + + @Unique private void mouseTweaks_handleRightClickDrag(ItemInstance slotItemToExamine) { + /** - First slot is handled instantly in mouseClicked function */ + if (slot.id != lastRMBSlotId) { + if (0 == rightClickHoveredSlots.size()) + { + /** - Add slot to item distribution */ + rightClickHoveredSlots.add(lastRMBSlot); + } + + /** - Add slot to item distribution */ + rightClickHoveredSlots.add(slot); + + /** - Record how many items are in the slot */ + if (null != slotItemToExamine) { + rightClickExistingAmount.add(slotItemToExamine.count); + } + else + { + rightClickExistingAmount.add(0); + } + + /** - Distribute one item to the slot */ + lastRMBSlotId = slot.id; + this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, slot.id, 1, false, this.minecraft.player); + } + } + + @Unique private boolean mouseTweaks_cancelRightClickDrag() + { + /** - Cancel Right-click + Drag */ + if (isRightClickDragStarted) { + if (rightClickHoveredSlots.size() > 1) { + + /** - Return all slots to normal */ + minecraft.player.inventory.setCursorItem(new ItemInstance(rightClickPersistentStack.itemId, rightClickItemAmount, rightClickPersistentStack.getDamage())); + for (int leftClickHoveredSlotsIndex = 0; leftClickHoveredSlotsIndex < rightClickHoveredSlots.size(); leftClickHoveredSlotsIndex++) { + if (0 != rightClickExistingAmount.get(leftClickHoveredSlotsIndex)) { + rightClickHoveredSlots.get(leftClickHoveredSlotsIndex).setStack(new ItemInstance(rightClickPersistentStack.itemId, rightClickExistingAmount.get(leftClickHoveredSlotsIndex), rightClickPersistentStack.getDamage())); + } else { + rightClickHoveredSlots.get(leftClickHoveredSlotsIndex).setStack(null); + } } - /** - Do nothing if there are no more items to distribute */ - if (1.0 == (double)leftClickItemAmount / (double)leftClickHoveredSlots.size()) { - return; + /** - Reset Right-click + Drag variables and exit function */ + mouseTweaks_resetRightClickDragVariables(); + + return true; + } + } + + return false; + } + + @Unique private void mouseTweaks_resetRightClickDragVariables() + { + rightClickExistingAmount.clear(); + rightClickHoveredSlots.clear(); + rightClickPersistentStack = null; + rightClickItemAmount = 0; + isRightClickDragStarted = false; + } + + @Unique private boolean mouseTweaks_handleLeftClickWithItem(ItemInstance cursorStack, Slot clickedSlot) { + /** - Ensure a slot was clicked */ + if (clickedSlot != null) { + /** - Record how many items are in the slot and how many items are needed to fill the slot */ + if (null != clickedSlot.getItem()) { + leftClickAmountToFillPersistent.add(cursorStack.getMaxStackSize() - clickedSlot.getItem().count); + leftClickExistingAmount.add(clickedSlot.getItem().count); + } else { + leftClickAmountToFillPersistent.add(cursorStack.getMaxStackSize()); + leftClickExistingAmount.add(0); + } + + /** - Begin Left-click + Drag */ + if (cursorStack != null && leftClickPersistentStack == null && isLeftClickDragStarted == false) { + leftClickPersistentStack = cursorStack; + leftClickItemAmount = leftClickPersistentStack.count; + isLeftClickDragStarted = true; + } + + /** - Handle initial Left-click */ + lastLMBSlotId = clickedSlot.id; + lastLMBSlot = clickedSlot; + if (Config.ConfigFields.LMBPreferShiftClick) { + boolean isShiftKeyDown = (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)); + this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, clickedSlot.id, 0, isShiftKeyDown, this.minecraft.player); + + if (isShiftKeyDown) { + mouseTweaks_resetLeftClickDragVariables(); + leftClickMouseTweaksPersistentStack = cursorStack; + isLeftClickDragMouseTweaksStarted = true; } + } else { + this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, clickedSlot.id, 0, false, this.minecraft.player); + } - /** - First slot is handled instantly in mouseClicked function */ - if (slot.id != lastLMBSlotId) { - if (0 == leftClickHoveredSlots.size()) - { - /** - Add slot to item distribution */ - leftClickHoveredSlots.add(lastLMBSlot); - } + return true; + } - /** - Add slot to item distribution */ - leftClickHoveredSlots.add(slot); + return false; + } - /** - Record how many items are in the slot and how many items are needed to fill the slot */ - if (null != slotItemToExamine) { - leftClickAmountToFillPersistent.add(leftClickPersistentStack.getMaxStackSize() - slotItemToExamine.count); - leftClickExistingAmount.add(slotItemToExamine.count); - } - else - { - leftClickAmountToFillPersistent.add(leftClickPersistentStack.getMaxStackSize()); - leftClickExistingAmount.add(0); - } + @Unique private boolean mouseTweaks_handleLeftClickWithoutItem(Slot clickedSlot) { + isLeftClickDragMouseTweaksStarted = true; + + /** - Ensure a slot was clicked */ + if (clickedSlot != null) { + /** - Get info for MouseTweaks `Left-Click + Drag` mechanics */ + ItemInstance itemInSlot = clickedSlot.getItem(); + leftClickMouseTweaksPersistentStack = itemInSlot; + + /** - Handle initial Left-click */ + lastLMBSlotId = clickedSlot.id; + lastLMBSlot = clickedSlot; + boolean isShiftKeyDown = (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)); + this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, clickedSlot.id, 0, isShiftKeyDown, this.minecraft.player); + + return true; + } else { + /** - Get info for MouseTweaks `Left-Click + Drag` mechanics */ + leftClickMouseTweaksPersistentStack = null; + } + + return false; + } + + @Unique private void mouseTweaks_handleLeftClickDragMouseTweaks() { + if (slot.id != lastLMBSlotId) { + lastLMBSlotId = slot.id; - /** - Return all slots to normal */ - List leftClickAmountToFill = new ArrayList<>(); - minecraft.player.inventory.setCursorItem(new ItemInstance(leftClickPersistentStack.itemId, leftClickItemAmount, leftClickPersistentStack.getDamage())); - for (int leftClickHoveredSlotsIndex = 0; leftClickHoveredSlotsIndex < leftClickHoveredSlots.size(); leftClickHoveredSlotsIndex++) { - leftClickAmountToFill.add(leftClickAmountToFillPersistent.get(leftClickHoveredSlotsIndex)); - if (0 != leftClickExistingAmount.get(leftClickHoveredSlotsIndex)) { - leftClickHoveredSlots.get(leftClickHoveredSlotsIndex).setStack(new ItemInstance(leftClickPersistentStack.itemId, leftClickExistingAmount.get(leftClickHoveredSlotsIndex), leftClickPersistentStack.getDamage())); + ItemInstance slotItemToExamine = slot.getItem(); + if (null != slotItemToExamine) + { + if (null != leftClickMouseTweaksPersistentStack) + { + if (slotItemToExamine.isDamageAndIDIdentical(leftClickMouseTweaksPersistentStack)) + { + if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) { + if (Config.ConfigFields.LMBTweakWithItem) + { + this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, slot.id, 0, true, this.minecraft.player); + } } else { - leftClickHoveredSlots.get(leftClickHoveredSlotsIndex).setStack(null); + if (Config.ConfigFields.LMBTweakWithItem) { + ItemInstance cursorStack = minecraft.player.inventory.getCursorItem(); + + if (cursorStack == null) { + /** - Pick up items from slot */ + this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, slot.id, 0, false, this.minecraft.player); + } else if (cursorStack.count < leftClickMouseTweaksPersistentStack.getMaxStackSize()) { + int amountAbleToPickUp = leftClickMouseTweaksPersistentStack.getMaxStackSize() - cursorStack.count; + int amountInSlot = slotItemToExamine.count; + + /** - Pick up items from slot */ + if (amountInSlot <= amountAbleToPickUp) { + this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, slot.id, 0, false, this.minecraft.player); + this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, slot.id, 0, false, this.minecraft.player); + } else if (cursorStack.count == leftClickMouseTweaksPersistentStack.getMaxStackSize()) { + slot.setStack(new ItemInstance(leftClickMouseTweaksPersistentStack.itemId, cursorStack.count, leftClickMouseTweaksPersistentStack.getDamage())); + minecraft.player.inventory.setCursorItem(new ItemInstance(leftClickMouseTweaksPersistentStack.itemId, amountInSlot, leftClickMouseTweaksPersistentStack.getDamage())); + } else { + this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, slot.id, 0, false, this.minecraft.player); + + slotItemToExamine = slot.getItem(); + cursorStack = minecraft.player.inventory.getCursorItem(); + amountInSlot = slotItemToExamine.count; + + slot.setStack(new ItemInstance(leftClickMouseTweaksPersistentStack.itemId, cursorStack.count, leftClickMouseTweaksPersistentStack.getDamage())); + minecraft.player.inventory.setCursorItem(new ItemInstance(leftClickMouseTweaksPersistentStack.itemId, amountInSlot, leftClickMouseTweaksPersistentStack.getDamage())); + } + } + } } } + } else if ( (Config.ConfigFields.LMBTweakWithoutItem) + && ( (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) + || (Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) + ) + ) { + this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, slot.id, 0, true, this.minecraft.player); + } + } + } + } + + @Unique private boolean mouseTweaks_handleLeftClickDrag() + { + /** - Do nothing if slot has already been added to Left-click + Drag logic */ + if (!leftClickHoveredSlots.contains(slot)) { + ItemInstance slotItemToExamine = slot.getItem(); - /** - Prepare to distribute over slots */ - int numberOfSlotsRemainingToFill = leftClickHoveredSlots.size(); - int itemsPerSlot = leftClickItemAmount / numberOfSlotsRemainingToFill; - int leftClickRemainingItemAmount = leftClickItemAmount; - boolean rerunLoop; + /** - Do nothing if slot item does not match held item */ + if (null != slotItemToExamine && !slotItemToExamine.isDamageAndIDIdentical(leftClickPersistentStack)){ + return true; + } - /** - Distribute fewer items to slots whose max stack size will be filled */ - do { - rerunLoop = false; - if (0 != numberOfSlotsRemainingToFill) { - itemsPerSlot = leftClickRemainingItemAmount / numberOfSlotsRemainingToFill; + /** - Do nothing if there are no more items to distribute */ + if (1.0 == (double)leftClickItemAmount / (double)leftClickHoveredSlots.size()) { + return true; + } - if (0 != itemsPerSlot) - { - for (int slotsToCheckIndex = 0; slotsToCheckIndex < leftClickAmountToFill.size(); slotsToCheckIndex++) { - if (0 != leftClickAmountToFill.get(slotsToCheckIndex) && leftClickAmountToFill.get(slotsToCheckIndex) < itemsPerSlot) { - /** - Just fill the slot and return */ - for (int fillTheAmountIndex = 0; fillTheAmountIndex < leftClickAmountToFill.get(slotsToCheckIndex); fillTheAmountIndex++) { - this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, leftClickHoveredSlots.get(slotsToCheckIndex).id, 1, false, this.minecraft.player); - } - - leftClickRemainingItemAmount = leftClickRemainingItemAmount - leftClickAmountToFill.get(slotsToCheckIndex); - leftClickAmountToFill.set(slotsToCheckIndex, 0); - numberOfSlotsRemainingToFill--; - rerunLoop = true; + /** - First slot is handled instantly in mouseClicked function */ + if (slot.id != lastLMBSlotId) { + if (0 == leftClickHoveredSlots.size()) + { + /** - Add slot to item distribution */ + leftClickHoveredSlots.add(lastLMBSlot); + } + + /** - Add slot to item distribution */ + leftClickHoveredSlots.add(slot); + + /** - Record how many items are in the slot and how many items are needed to fill the slot */ + if (null != slotItemToExamine) { + leftClickAmountToFillPersistent.add(leftClickPersistentStack.getMaxStackSize() - slotItemToExamine.count); + leftClickExistingAmount.add(slotItemToExamine.count); + } + else + { + leftClickAmountToFillPersistent.add(leftClickPersistentStack.getMaxStackSize()); + leftClickExistingAmount.add(0); + } + + /** - Return all slots to normal */ + List leftClickAmountToFill = new ArrayList<>(); + minecraft.player.inventory.setCursorItem(new ItemInstance(leftClickPersistentStack.itemId, leftClickItemAmount, leftClickPersistentStack.getDamage())); + for (int leftClickHoveredSlotsIndex = 0; leftClickHoveredSlotsIndex < leftClickHoveredSlots.size(); leftClickHoveredSlotsIndex++) { + leftClickAmountToFill.add(leftClickAmountToFillPersistent.get(leftClickHoveredSlotsIndex)); + if (0 != leftClickExistingAmount.get(leftClickHoveredSlotsIndex)) { + leftClickHoveredSlots.get(leftClickHoveredSlotsIndex).setStack(new ItemInstance(leftClickPersistentStack.itemId, leftClickExistingAmount.get(leftClickHoveredSlotsIndex), leftClickPersistentStack.getDamage())); + } else { + leftClickHoveredSlots.get(leftClickHoveredSlotsIndex).setStack(null); + } + } + + /** - Prepare to distribute over slots */ + int numberOfSlotsRemainingToFill = leftClickHoveredSlots.size(); + int itemsPerSlot = leftClickItemAmount / numberOfSlotsRemainingToFill; + int leftClickRemainingItemAmount = leftClickItemAmount; + boolean rerunLoop; + + /** - Distribute fewer items to slots whose max stack size will be filled */ + do { + rerunLoop = false; + if (0 != numberOfSlotsRemainingToFill) { + itemsPerSlot = leftClickRemainingItemAmount / numberOfSlotsRemainingToFill; + + if (0 != itemsPerSlot) + { + for (int slotsToCheckIndex = 0; slotsToCheckIndex < leftClickAmountToFill.size(); slotsToCheckIndex++) { + if (0 != leftClickAmountToFill.get(slotsToCheckIndex) && leftClickAmountToFill.get(slotsToCheckIndex) < itemsPerSlot) { + /** - Just fill the slot and return */ + for (int fillTheAmountIndex = 0; fillTheAmountIndex < leftClickAmountToFill.get(slotsToCheckIndex); fillTheAmountIndex++) { + this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, leftClickHoveredSlots.get(slotsToCheckIndex).id, 1, false, this.minecraft.player); } + + leftClickRemainingItemAmount = leftClickRemainingItemAmount - leftClickAmountToFill.get(slotsToCheckIndex); + leftClickAmountToFill.set(slotsToCheckIndex, 0); + numberOfSlotsRemainingToFill--; + rerunLoop = true; } } } - } while (rerunLoop && 0 != numberOfSlotsRemainingToFill); + } + } while (rerunLoop && 0 != numberOfSlotsRemainingToFill); - /** - Distribute remaining items evenly over remaining slots that were not already filled to max stack size */ - for (int distributeSlotsIndex = 0; distributeSlotsIndex < leftClickHoveredSlots.size(); distributeSlotsIndex++) { - if (0 != leftClickAmountToFill.get(distributeSlotsIndex)) { - for (int addSlotIndex = 0; addSlotIndex < itemsPerSlot; addSlotIndex++) { - this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, leftClickHoveredSlots.get(distributeSlotsIndex).id, 1, false, this.minecraft.player); - } + /** - Distribute remaining items evenly over remaining slots that were not already filled to max stack size */ + for (int distributeSlotsIndex = 0; distributeSlotsIndex < leftClickHoveredSlots.size(); distributeSlotsIndex++) { + if (0 != leftClickAmountToFill.get(distributeSlotsIndex)) { + for (int addSlotIndex = 0; addSlotIndex < itemsPerSlot; addSlotIndex++) { + this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, leftClickHoveredSlots.get(distributeSlotsIndex).id, 1, false, this.minecraft.player); } } } } - } else { - inventoryTweaks_resetLeftClickDragVariables(); } + + return false; + } + + @Unique private boolean mouseTweaks_cancelLeftClickDrag() + { + /** - Cancel Left-click + Drag */ + if (isLeftClickDragStarted) { + if (leftClickHoveredSlots.size() > 1) { + + /** - Return all slots to normal */ + minecraft.player.inventory.setCursorItem(new ItemInstance(leftClickPersistentStack.itemId, leftClickItemAmount, leftClickPersistentStack.getDamage())); + for (int leftClickHoveredSlotsIndex = 0; leftClickHoveredSlotsIndex < leftClickHoveredSlots.size(); leftClickHoveredSlotsIndex++) { + if (0 != leftClickExistingAmount.get(leftClickHoveredSlotsIndex)) { + leftClickHoveredSlots.get(leftClickHoveredSlotsIndex).setStack(new ItemInstance(leftClickPersistentStack.itemId, leftClickExistingAmount.get(leftClickHoveredSlotsIndex), leftClickPersistentStack.getDamage())); + } else { + leftClickHoveredSlots.get(leftClickHoveredSlotsIndex).setStack(null); + } + } + + /** - Reset Left-click + Drag variables and exit function */ + mouseTweaks_resetLeftClickDragVariables(); + return true; + } + } + + return false; + } + + @Unique private void mouseTweaks_resetLeftClickDragVariables() + { + leftClickExistingAmount.clear(); + leftClickAmountToFillPersistent.clear(); + leftClickHoveredSlots.clear(); + leftClickPersistentStack = null; + leftClickMouseTweaksPersistentStack = null; + leftClickItemAmount = 0; + isLeftClickDragStarted = false; + isLeftClickDragMouseTweaksStarted = false; } @Unique private boolean drawingHoveredSlot; @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/container/ContainerBase;isMouseOverSlot(Lnet/minecraft/container/slot/Slot;II)Z")) - private boolean inventoryTweaks_isMouseOverSlot(ContainerBase guiContainer, Slot slot, int x, int y) { + private boolean mouseTweaks_isMouseOverSlot(ContainerBase guiContainer, Slot slot, int x, int y) { return ( (drawingHoveredSlot = rightClickHoveredSlots.contains(slot)) || (drawingHoveredSlot = leftClickHoveredSlots.contains(slot)) || isMouseOverSlot(slot, x, y) @@ -392,14 +580,14 @@ private boolean inventoryTweaks_isMouseOverSlot(ContainerBase guiContainer, Slot } @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/container/ContainerBase;fillGradient(IIIIII)V", ordinal = 0)) - private void inventoryTweaks_fillGradient(ContainerBase instance, int startX, int startY, int endX, int endY, int colorStart, int colorEnd) { + private void mouseTweaks_fillGradient(ContainerBase instance, int startX, int startY, int endX, int endY, int colorStart, int colorEnd) { if (colorStart != colorEnd) throw new AssertionError(); int color = drawingHoveredSlot ? 0x20ffffff : colorStart; this.fillGradient(startX, startY, endX, endY, color, color); } @Inject(method = "keyPressed", at = @At("RETURN")) - private void inventoryTweaks_keyPressed(char character, int keyCode, CallbackInfo ci) { + private void mouseTweaks_keyPressed(char character, int keyCode, CallbackInfo ci) { if (this.slot == null) return; From 80923dd34eec75493b7e4e640ef52adf1619785e Mon Sep 17 00:00:00 2001 From: telontelvarost Date: Fri, 26 Jan 2024 01:12:58 -0500 Subject: [PATCH 02/13] ISSUE-8 - Fix function names --- .../mixin/ContainerBaseMixin.java | 64 +++++++++---------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java b/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java index f38c9fc..5c47844 100644 --- a/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java +++ b/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java @@ -78,7 +78,7 @@ public abstract class ContainerBaseMixin extends ScreenBase { @Unique List leftClickAmountToFillPersistent = new ArrayList<>(); @Inject(method = "mouseClicked", at = @At("HEAD"), cancellable = true) - protected void mouseTweaks_mouseClicked(int mouseX, int mouseY, int button, CallbackInfo ci) { + protected void inventoryTweaks_mouseClicked(int mouseX, int mouseY, int button, CallbackInfo ci) { isLeftClickDragMouseTweaksStarted = false; /** - Right-click */ @@ -86,10 +86,10 @@ protected void mouseTweaks_mouseClicked(int mouseX, int mouseY, int button, Call boolean exitFunction = false; /** - Should click cancel Left-click + Drag */ - if (!mouseTweaks_cancelLeftClickDrag()) { + if (!inventoryTweaks_cancelLeftClickDrag()) { /** - Handle Right-click */ - exitFunction = mouseTweaks_handleRightClick(mouseX, mouseY); + exitFunction = inventoryTweaks_handleRightClick(mouseX, mouseY); } else { exitFunction = true; } @@ -107,15 +107,15 @@ protected void mouseTweaks_mouseClicked(int mouseX, int mouseY, int button, Call boolean exitFunction = false; /** - Should click cancel Right-click + Drag */ - if (!mouseTweaks_cancelRightClickDrag()) { + if (!inventoryTweaks_cancelRightClickDrag()) { /** - Handle Left-click */ ItemInstance cursorStack = minecraft.player.inventory.getCursorItem(); Slot clickedSlot = this.getSlot(mouseX, mouseY); if (cursorStack != null) { - exitFunction = mouseTweaks_handleLeftClickWithItem(cursorStack, clickedSlot); + exitFunction = inventoryTweaks_handleLeftClickWithItem(cursorStack, clickedSlot); } else { - exitFunction = mouseTweaks_handleLeftClickWithoutItem(clickedSlot); + exitFunction = inventoryTweaks_handleLeftClickWithoutItem(clickedSlot); } } else { exitFunction = true; @@ -131,7 +131,7 @@ protected void mouseTweaks_mouseClicked(int mouseX, int mouseY, int button, Call } @Inject(method = "mouseReleased", at = @At("RETURN"), cancellable = true) - private void mouseTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, int button, CallbackInfo ci) { + private void inventoryTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, int button, CallbackInfo ci) { slot = this.getSlot(mouseX, mouseY); /** - Do nothing if mouse is not over a slot */ @@ -164,12 +164,12 @@ private void mouseTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, int } if (!rightClickHoveredSlots.contains(slot)) { - mouseTweaks_handleRightClickDrag(slotItemToExamine); + inventoryTweaks_handleRightClickDrag(slotItemToExamine); } else if (Config.ConfigFields.RMBTweak) { - mouseTweaks_handleRightClickDragMouseTweaks(); + inventoryTweaks_handleRightClickDragMouseTweaks(); } } else { - mouseTweaks_resetRightClickDragVariables(); + inventoryTweaks_resetRightClickDragVariables(); } /** - Left-click + Drag logic = evenly distribute held items over slots */ @@ -179,20 +179,20 @@ private void mouseTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, int ) { if (isLeftClickDragMouseTweaksStarted) { - mouseTweaks_handleLeftClickDragMouseTweaks(); + inventoryTweaks_handleLeftClickDragMouseTweaks(); } else if ( leftClickPersistentStack != null ) { - if (mouseTweaks_handleLeftClickDrag()) { + if (inventoryTweaks_handleLeftClickDrag()) { return; } } else { - mouseTweaks_resetLeftClickDragVariables(); + inventoryTweaks_resetLeftClickDragVariables(); } } else { - mouseTweaks_resetLeftClickDragVariables(); + inventoryTweaks_resetLeftClickDragVariables(); } } - @Unique private boolean mouseTweaks_handleRightClick(int mouseX, int mouseY) { + @Unique private boolean inventoryTweaks_handleRightClick(int mouseX, int mouseY) { /** - Get held item */ ItemInstance cursorStack = minecraft.player.inventory.getCursorItem(); @@ -225,7 +225,7 @@ private void mouseTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, int this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, clickedSlot.id, 1, isShiftKeyDown, this.minecraft.player); if (isShiftKeyDown) { - mouseTweaks_resetRightClickDragVariables(); + inventoryTweaks_resetRightClickDragVariables(); } } else { this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, clickedSlot.id, 1, false, this.minecraft.player); @@ -238,7 +238,7 @@ private void mouseTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, int return false; } - @Unique private void mouseTweaks_handleRightClickDragMouseTweaks() { + @Unique private void inventoryTweaks_handleRightClickDragMouseTweaks() { if (slot.id != lastRMBSlotId) { ItemInstance cursorStack = minecraft.player.inventory.getCursorItem(); @@ -250,7 +250,7 @@ private void mouseTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, int } } - @Unique private void mouseTweaks_handleRightClickDrag(ItemInstance slotItemToExamine) { + @Unique private void inventoryTweaks_handleRightClickDrag(ItemInstance slotItemToExamine) { /** - First slot is handled instantly in mouseClicked function */ if (slot.id != lastRMBSlotId) { if (0 == rightClickHoveredSlots.size()) @@ -277,7 +277,7 @@ private void mouseTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, int } } - @Unique private boolean mouseTweaks_cancelRightClickDrag() + @Unique private boolean inventoryTweaks_cancelRightClickDrag() { /** - Cancel Right-click + Drag */ if (isRightClickDragStarted) { @@ -294,7 +294,7 @@ private void mouseTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, int } /** - Reset Right-click + Drag variables and exit function */ - mouseTweaks_resetRightClickDragVariables(); + inventoryTweaks_resetRightClickDragVariables(); return true; } @@ -303,7 +303,7 @@ private void mouseTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, int return false; } - @Unique private void mouseTweaks_resetRightClickDragVariables() + @Unique private void inventoryTweaks_resetRightClickDragVariables() { rightClickExistingAmount.clear(); rightClickHoveredSlots.clear(); @@ -312,7 +312,7 @@ private void mouseTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, int isRightClickDragStarted = false; } - @Unique private boolean mouseTweaks_handleLeftClickWithItem(ItemInstance cursorStack, Slot clickedSlot) { + @Unique private boolean inventoryTweaks_handleLeftClickWithItem(ItemInstance cursorStack, Slot clickedSlot) { /** - Ensure a slot was clicked */ if (clickedSlot != null) { /** - Record how many items are in the slot and how many items are needed to fill the slot */ @@ -339,7 +339,7 @@ private void mouseTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, int this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, clickedSlot.id, 0, isShiftKeyDown, this.minecraft.player); if (isShiftKeyDown) { - mouseTweaks_resetLeftClickDragVariables(); + inventoryTweaks_resetLeftClickDragVariables(); leftClickMouseTweaksPersistentStack = cursorStack; isLeftClickDragMouseTweaksStarted = true; } @@ -353,7 +353,7 @@ private void mouseTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, int return false; } - @Unique private boolean mouseTweaks_handleLeftClickWithoutItem(Slot clickedSlot) { + @Unique private boolean inventoryTweaks_handleLeftClickWithoutItem(Slot clickedSlot) { isLeftClickDragMouseTweaksStarted = true; /** - Ensure a slot was clicked */ @@ -377,7 +377,7 @@ private void mouseTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, int return false; } - @Unique private void mouseTweaks_handleLeftClickDragMouseTweaks() { + @Unique private void inventoryTweaks_handleLeftClickDragMouseTweaks() { if (slot.id != lastLMBSlotId) { lastLMBSlotId = slot.id; @@ -436,7 +436,7 @@ private void mouseTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, int } } - @Unique private boolean mouseTweaks_handleLeftClickDrag() + @Unique private boolean inventoryTweaks_handleLeftClickDrag() { /** - Do nothing if slot has already been added to Left-click + Drag logic */ if (!leftClickHoveredSlots.contains(slot)) { @@ -531,7 +531,7 @@ private void mouseTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, int return false; } - @Unique private boolean mouseTweaks_cancelLeftClickDrag() + @Unique private boolean inventoryTweaks_cancelLeftClickDrag() { /** - Cancel Left-click + Drag */ if (isLeftClickDragStarted) { @@ -548,7 +548,7 @@ private void mouseTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, int } /** - Reset Left-click + Drag variables and exit function */ - mouseTweaks_resetLeftClickDragVariables(); + inventoryTweaks_resetLeftClickDragVariables(); return true; } } @@ -556,7 +556,7 @@ private void mouseTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, int return false; } - @Unique private void mouseTweaks_resetLeftClickDragVariables() + @Unique private void inventoryTweaks_resetLeftClickDragVariables() { leftClickExistingAmount.clear(); leftClickAmountToFillPersistent.clear(); @@ -572,7 +572,7 @@ private void mouseTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, int private boolean drawingHoveredSlot; @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/container/ContainerBase;isMouseOverSlot(Lnet/minecraft/container/slot/Slot;II)Z")) - private boolean mouseTweaks_isMouseOverSlot(ContainerBase guiContainer, Slot slot, int x, int y) { + private boolean inventoryTweaks_isMouseOverSlot(ContainerBase guiContainer, Slot slot, int x, int y) { return ( (drawingHoveredSlot = rightClickHoveredSlots.contains(slot)) || (drawingHoveredSlot = leftClickHoveredSlots.contains(slot)) || isMouseOverSlot(slot, x, y) @@ -580,14 +580,14 @@ private boolean mouseTweaks_isMouseOverSlot(ContainerBase guiContainer, Slot slo } @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/container/ContainerBase;fillGradient(IIIIII)V", ordinal = 0)) - private void mouseTweaks_fillGradient(ContainerBase instance, int startX, int startY, int endX, int endY, int colorStart, int colorEnd) { + private void inventoryTweaks_fillGradient(ContainerBase instance, int startX, int startY, int endX, int endY, int colorStart, int colorEnd) { if (colorStart != colorEnd) throw new AssertionError(); int color = drawingHoveredSlot ? 0x20ffffff : colorStart; this.fillGradient(startX, startY, endX, endY, color, color); } @Inject(method = "keyPressed", at = @At("RETURN")) - private void mouseTweaks_keyPressed(char character, int keyCode, CallbackInfo ci) { + private void inventoryTweaks_keyPressed(char character, int keyCode, CallbackInfo ci) { if (this.slot == null) return; From e1a5f1ce2fc9ed6793f46dc9912f821833fe074b Mon Sep 17 00:00:00 2001 From: telontelvarost Date: Fri, 26 Jan 2024 01:52:02 -0500 Subject: [PATCH 03/13] ISSUE-8 - Improve configuration options --- .../telvarost/inventorytweaks/Config.java | 43 +++++++++++++--- .../mixin/ContainerBaseMixin.java | 50 +++++++++++-------- .../inventorytweaks/mixin/PlayerMixin.java | 5 ++ 3 files changed, 70 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/github/telvarost/inventorytweaks/Config.java b/src/main/java/com/github/telvarost/inventorytweaks/Config.java index f0f2bb2..7a7def3 100644 --- a/src/main/java/com/github/telvarost/inventorytweaks/Config.java +++ b/src/main/java/com/github/telvarost/inventorytweaks/Config.java @@ -1,19 +1,25 @@ package com.github.telvarost.inventorytweaks; import blue.endless.jankson.Comment; +import net.glasslauncher.mods.api.gcapi.api.ConfigCategory; import net.glasslauncher.mods.api.gcapi.api.ConfigName; import net.glasslauncher.mods.api.gcapi.api.GConfig; public class Config { - @GConfig(value = "config", visibleName = "InventoryTweaks Config") - public static ConfigFields config = new ConfigFields(); + @GConfig(value = "inventoryTweaks", visibleName = "InventoryTweaks Config", primary = true) + public static InventoryTweaksConfig INVENTORY_TWEAKS_CONFIG = new InventoryTweaksConfig(); - public static class ConfigFields { + public static class InventoryTweaksConfig { - @ConfigName("Empty-hand [Shift + Left-Click + Drag]") - @Comment("[Shift-Click] items of any type") - public static Boolean LMBTweakWithoutItem = true; + @ConfigCategory("Modern Minecraft Config") + public static ModernMinecraftConfig MODERN_MINECRAFT_CONFIG = new ModernMinecraftConfig(); + + @ConfigCategory("MouseTweaks Config") + public static final MouseTweaksConfig MOUSE_TWEAKS_CONFIG = new MouseTweaksConfig(); + } + + public static class ModernMinecraftConfig { @ConfigName("Prefer [Shift-Click] over [Left-Click + Drag]") public static Boolean LMBPreferShiftClick = true; @@ -21,11 +27,32 @@ public static class ConfigFields { @ConfigName("Prefer [Shift-Click] over [Right-Click + Drag]") public static Boolean RMBPreferShiftClick = true; + @ConfigName("Use [DROP_KEY] to drop inventory items") + @Comment("Cursor must not be holding any items") + public static Boolean UseDropKeyInInventory = true; + + @ConfigName("Use [LCtrl + DROP_KEY] to drop entire stack") + public static Boolean LCtrlStackDrop = true; + + @ConfigName("Use [NUMBER_KEYS] to swap items to hotbar") + @Comment("Hover over the slot or move cursor item to hotbar") + public static Boolean NumKeyHotbarSwap = true; + } + + public static class MouseTweaksConfig { + + @ConfigName("Empty cursor [Shift + Left-Click + Drag]") + @Comment("[Shift-Click] items of any type") + public static Boolean LMBTweakShiftClickAny = true; + + @ConfigName("Item in cursor [Shift + Left-Click + Drag]") + @Comment("[Shift-Click] items of the held type") + public static Boolean LMBTweakShiftClick = true; + @ConfigName("[Right-Click + Drag] over existing slots") public static Boolean RMBTweak = true; @ConfigName("[Left-Click + Drag] to pick up items") - @Comment("Hold [Shift] to [Shift-Click] items instead") - public static Boolean LMBTweakWithItem = true; + public static Boolean LMBTweakPickUp = true; } } diff --git a/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java b/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java index 5c47844..9be30ba 100644 --- a/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java +++ b/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java @@ -165,7 +165,7 @@ private void inventoryTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, if (!rightClickHoveredSlots.contains(slot)) { inventoryTweaks_handleRightClickDrag(slotItemToExamine); - } else if (Config.ConfigFields.RMBTweak) { + } else if (Config.MouseTweaksConfig.RMBTweak) { inventoryTweaks_handleRightClickDragMouseTweaks(); } } else { @@ -220,7 +220,7 @@ private void inventoryTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, /** - Handle initial Right-click */ lastRMBSlotId = clickedSlot.id; lastRMBSlot = clickedSlot; - if (Config.ConfigFields.RMBPreferShiftClick) { + if (Config.ModernMinecraftConfig.RMBPreferShiftClick) { boolean isShiftKeyDown = (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)); this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, clickedSlot.id, 1, isShiftKeyDown, this.minecraft.player); @@ -334,7 +334,7 @@ private void inventoryTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, /** - Handle initial Left-click */ lastLMBSlotId = clickedSlot.id; lastLMBSlot = clickedSlot; - if (Config.ConfigFields.LMBPreferShiftClick) { + if (Config.ModernMinecraftConfig.LMBPreferShiftClick) { boolean isShiftKeyDown = (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)); this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, clickedSlot.id, 0, isShiftKeyDown, this.minecraft.player); @@ -389,12 +389,12 @@ private void inventoryTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, if (slotItemToExamine.isDamageAndIDIdentical(leftClickMouseTweaksPersistentStack)) { if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) { - if (Config.ConfigFields.LMBTweakWithItem) + if (Config.MouseTweaksConfig.LMBTweakShiftClick) { this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, slot.id, 0, true, this.minecraft.player); } } else { - if (Config.ConfigFields.LMBTweakWithItem) { + if (Config.MouseTweaksConfig.LMBTweakPickUp) { ItemInstance cursorStack = minecraft.player.inventory.getCursorItem(); if (cursorStack == null) { @@ -425,7 +425,7 @@ private void inventoryTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, } } } - } else if ( (Config.ConfigFields.LMBTweakWithoutItem) + } else if ( (Config.MouseTweaksConfig.LMBTweakShiftClickAny) && ( (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) || (Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) ) @@ -574,9 +574,9 @@ private void inventoryTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/container/ContainerBase;isMouseOverSlot(Lnet/minecraft/container/slot/Slot;II)Z")) private boolean inventoryTweaks_isMouseOverSlot(ContainerBase guiContainer, Slot slot, int x, int y) { return ( (drawingHoveredSlot = rightClickHoveredSlots.contains(slot)) - || (drawingHoveredSlot = leftClickHoveredSlots.contains(slot)) - || isMouseOverSlot(slot, x, y) - ); + || (drawingHoveredSlot = leftClickHoveredSlots.contains(slot)) + || isMouseOverSlot(slot, x, y) + ); } @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/container/ContainerBase;fillGradient(IIIIII)V", ordinal = 0)) @@ -588,23 +588,33 @@ private void inventoryTweaks_fillGradient(ContainerBase instance, int startX, in @Inject(method = "keyPressed", at = @At("RETURN")) private void inventoryTweaks_keyPressed(char character, int keyCode, CallbackInfo ci) { - if (this.slot == null) + if (this.slot == null) { return; + } - if (keyCode == this.minecraft.options.dropKey.key) { - if (this.minecraft.player.inventory.getCursorItem() != null) - return; + if (Config.ModernMinecraftConfig.UseDropKeyInInventory) { + if (keyCode == this.minecraft.options.dropKey.key) { + if (this.minecraft.player.inventory.getCursorItem() != null) { + return; + } - this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, slot.id, 0, false, this.minecraft.player); - this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, -999, Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) ? 0 : 1, false, this.minecraft.player); - this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, slot.id, 0, false, this.minecraft.player); + this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, slot.id, 0, false, this.minecraft.player); + if (Config.ModernMinecraftConfig.LCtrlStackDrop) { + this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, -999, Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) ? 0 : 1, false, this.minecraft.player); + } else { + this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, -999, 1, false, this.minecraft.player); + } + this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, slot.id, 0, false, this.minecraft.player); + } } - if (keyCode >= Keyboard.KEY_1 && keyCode <= Keyboard.KEY_9) { - if (this.minecraft.player.inventory.getCursorItem() == null) + if (Config.ModernMinecraftConfig.NumKeyHotbarSwap) { + if (keyCode >= Keyboard.KEY_1 && keyCode <= Keyboard.KEY_9) { + if (this.minecraft.player.inventory.getCursorItem() == null) + this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, slot.id, 0, false, this.minecraft.player); + this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, 35 + keyCode - 1, 0, false, this.minecraft.player); this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, slot.id, 0, false, this.minecraft.player); - this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, 35 + keyCode - 1, 0, false, this.minecraft.player); - this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, slot.id, 0, false, this.minecraft.player); + } } } } diff --git a/src/main/java/com/github/telvarost/inventorytweaks/mixin/PlayerMixin.java b/src/main/java/com/github/telvarost/inventorytweaks/mixin/PlayerMixin.java index 2e629df..bd8e474 100644 --- a/src/main/java/com/github/telvarost/inventorytweaks/mixin/PlayerMixin.java +++ b/src/main/java/com/github/telvarost/inventorytweaks/mixin/PlayerMixin.java @@ -1,5 +1,6 @@ package com.github.telvarost.inventorytweaks.mixin; +import com.github.telvarost.inventorytweaks.Config; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.ClientPlayer; import net.minecraft.entity.player.PlayerBase; @@ -13,6 +14,10 @@ public abstract class PlayerMixin { @Inject(method = "dropSelectedItem", at = @At("HEAD"), cancellable = true) private void inventoryTweaks_dropSelectedItem(CallbackInfo ci) { + if (!Config.ModernMinecraftConfig.LCtrlStackDrop) { + return; + } + if (Keyboard.isKeyDown(Keyboard.KEY_LCONTROL)) { Minecraft minecraft = MinecraftAccessor.getInstance(); PlayerBase playerBase = (PlayerBase) (Object) this; From bb46bb2543c408c5685fe5aed254cbd17606112d Mon Sep 17 00:00:00 2001 From: telontelvarost Date: Fri, 26 Jan 2024 01:56:28 -0500 Subject: [PATCH 04/13] ISSUE-8 - Update wording --- src/main/java/com/github/telvarost/inventorytweaks/Config.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/github/telvarost/inventorytweaks/Config.java b/src/main/java/com/github/telvarost/inventorytweaks/Config.java index 7a7def3..81059de 100644 --- a/src/main/java/com/github/telvarost/inventorytweaks/Config.java +++ b/src/main/java/com/github/telvarost/inventorytweaks/Config.java @@ -35,7 +35,7 @@ public static class ModernMinecraftConfig { public static Boolean LCtrlStackDrop = true; @ConfigName("Use [NUMBER_KEYS] to swap items to hotbar") - @Comment("Hover over the slot or move cursor item to hotbar") + @Comment("Hover over the slot or swap cursor item") public static Boolean NumKeyHotbarSwap = true; } From aa3b9798164e94cf9a0cc322769992edde984dba Mon Sep 17 00:00:00 2001 From: telontelvarost Date: Fri, 26 Jan 2024 02:09:07 -0500 Subject: [PATCH 05/13] ISSUE-8 - Extend config options further --- .../telvarost/inventorytweaks/Config.java | 6 ++++++ .../mixin/ContainerBaseMixin.java | 17 +++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/github/telvarost/inventorytweaks/Config.java b/src/main/java/com/github/telvarost/inventorytweaks/Config.java index 81059de..8654729 100644 --- a/src/main/java/com/github/telvarost/inventorytweaks/Config.java +++ b/src/main/java/com/github/telvarost/inventorytweaks/Config.java @@ -21,6 +21,12 @@ public static class InventoryTweaksConfig { public static class ModernMinecraftConfig { + @ConfigName("Enable [Left-Click + Drag]") + public static Boolean EnableLeftClickDrag = true; + + @ConfigName("Enable [Right-Click + Drag]") + public static Boolean EnableRightClickDrag = true; + @ConfigName("Prefer [Shift-Click] over [Left-Click + Drag]") public static Boolean LMBPreferShiftClick = true; diff --git a/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java b/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java index 9be30ba..9d0129a 100644 --- a/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java +++ b/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java @@ -89,7 +89,9 @@ protected void inventoryTweaks_mouseClicked(int mouseX, int mouseY, int button, if (!inventoryTweaks_cancelLeftClickDrag()) { /** - Handle Right-click */ - exitFunction = inventoryTweaks_handleRightClick(mouseX, mouseY); + if (Config.ModernMinecraftConfig.EnableRightClickDrag) { + exitFunction = inventoryTweaks_handleRightClick(mouseX, mouseY); + } } else { exitFunction = true; } @@ -113,7 +115,9 @@ protected void inventoryTweaks_mouseClicked(int mouseX, int mouseY, int button, ItemInstance cursorStack = minecraft.player.inventory.getCursorItem(); Slot clickedSlot = this.getSlot(mouseX, mouseY); if (cursorStack != null) { - exitFunction = inventoryTweaks_handleLeftClickWithItem(cursorStack, clickedSlot); + if (Config.ModernMinecraftConfig.EnableLeftClickDrag) { + exitFunction = inventoryTweaks_handleLeftClickWithItem(cursorStack, clickedSlot); + } } else { exitFunction = inventoryTweaks_handleLeftClickWithoutItem(clickedSlot); } @@ -150,9 +154,9 @@ private void inventoryTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, /** - Do nothing if slot item does not match held item or if the slot is full */ if ( (null != slotItemToExamine) - && ( (!slotItemToExamine.isDamageAndIDIdentical(rightClickPersistentStack)) - || (slotItemToExamine.count == rightClickPersistentStack.getMaxStackSize()) - ) + && ( (!slotItemToExamine.isDamageAndIDIdentical(rightClickPersistentStack)) + || (slotItemToExamine.count == rightClickPersistentStack.getMaxStackSize()) + ) ) { return; } @@ -610,8 +614,9 @@ private void inventoryTweaks_keyPressed(char character, int keyCode, CallbackInf if (Config.ModernMinecraftConfig.NumKeyHotbarSwap) { if (keyCode >= Keyboard.KEY_1 && keyCode <= Keyboard.KEY_9) { - if (this.minecraft.player.inventory.getCursorItem() == null) + if (this.minecraft.player.inventory.getCursorItem() == null) { this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, slot.id, 0, false, this.minecraft.player); + } this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, 35 + keyCode - 1, 0, false, this.minecraft.player); this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, slot.id, 0, false, this.minecraft.player); } From e5d90bcc51367893fda82cc7df5f4a09ed10b0e4 Mon Sep 17 00:00:00 2001 From: telontelvarost Date: Fri, 26 Jan 2024 02:27:23 -0500 Subject: [PATCH 06/13] ISSUE-8 - Rename config and ensure default hover color stays --- .../telvarost/inventorytweaks/Config.java | 3 +++ .../mixin/ContainerBaseMixin.java | 22 +++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/github/telvarost/inventorytweaks/Config.java b/src/main/java/com/github/telvarost/inventorytweaks/Config.java index 8654729..e209d7e 100644 --- a/src/main/java/com/github/telvarost/inventorytweaks/Config.java +++ b/src/main/java/com/github/telvarost/inventorytweaks/Config.java @@ -21,6 +21,9 @@ public static class InventoryTweaksConfig { public static class ModernMinecraftConfig { + @ConfigName("Enable [Click + Drag] graphics") + public static Boolean EnableDragGraphics = true; + @ConfigName("Enable [Left-Click + Drag]") public static Boolean EnableLeftClickDrag = true; diff --git a/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java b/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java index 9d0129a..22658cd 100644 --- a/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java +++ b/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java @@ -577,17 +577,25 @@ private void inventoryTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/container/ContainerBase;isMouseOverSlot(Lnet/minecraft/container/slot/Slot;II)Z")) private boolean inventoryTweaks_isMouseOverSlot(ContainerBase guiContainer, Slot slot, int x, int y) { - return ( (drawingHoveredSlot = rightClickHoveredSlots.contains(slot)) - || (drawingHoveredSlot = leftClickHoveredSlots.contains(slot)) - || isMouseOverSlot(slot, x, y) - ); + if (Config.ModernMinecraftConfig.EnableDragGraphics) { + return ( (drawingHoveredSlot = rightClickHoveredSlots.contains(slot)) + || (drawingHoveredSlot = leftClickHoveredSlots.contains(slot)) + || isMouseOverSlot(slot, x, y) + ); + } else { + return isMouseOverSlot(slot, x, y); + } } @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/container/ContainerBase;fillGradient(IIIIII)V", ordinal = 0)) private void inventoryTweaks_fillGradient(ContainerBase instance, int startX, int startY, int endX, int endY, int colorStart, int colorEnd) { - if (colorStart != colorEnd) throw new AssertionError(); - int color = drawingHoveredSlot ? 0x20ffffff : colorStart; - this.fillGradient(startX, startY, endX, endY, color, color); + if (Config.ModernMinecraftConfig.EnableDragGraphics) { + if (colorStart != colorEnd) throw new AssertionError(); + int color = drawingHoveredSlot ? 0x20ffffff : colorStart; + this.fillGradient(startX, startY, endX, endY, color, color); + } else { + this.fillGradient(startX, startY, endX, endY, colorStart, colorEnd); + } } @Inject(method = "keyPressed", at = @At("RETURN")) From 47dac6c9148f56b8c776a1401e68545672533d24 Mon Sep 17 00:00:00 2001 From: telontelvarost Date: Fri, 26 Jan 2024 03:03:30 -0500 Subject: [PATCH 07/13] ISSUE-8 - Implement simple scroll wheel tranfer --- .../telvarost/inventorytweaks/Config.java | 3 + .../mixin/ContainerBaseMixin.java | 74 ++++++++++++++++--- 2 files changed, 67 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/github/telvarost/inventorytweaks/Config.java b/src/main/java/com/github/telvarost/inventorytweaks/Config.java index e209d7e..60abd7d 100644 --- a/src/main/java/com/github/telvarost/inventorytweaks/Config.java +++ b/src/main/java/com/github/telvarost/inventorytweaks/Config.java @@ -50,6 +50,9 @@ public static class ModernMinecraftConfig { public static class MouseTweaksConfig { + @ConfigName("Cursor/Slot [ScrollWheel] transfer") + public static Boolean ScrollWheelTransfer = true; + @ConfigName("Empty cursor [Shift + Left-Click + Drag]") @Comment("[Shift-Click] items of any type") public static Boolean LMBTweakShiftClickAny = true; diff --git a/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java b/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java index 22658cd..ff29d81 100644 --- a/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java +++ b/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java @@ -18,6 +18,8 @@ import java.util.ArrayList; import java.util.List; +import static java.lang.Math.abs; + @Mixin(ContainerBase.class) public abstract class ContainerBaseMixin extends ScreenBase { @Shadow @@ -142,14 +144,23 @@ private void inventoryTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, if (slot == null) return; + if (Config.MouseTweaksConfig.ScrollWheelTransfer) { + int currentWheelDegrees = Mouse.getDWheel(); + if ( (0 != currentWheelDegrees) + && (isLeftClickDragStarted == false) + && (isRightClickDragStarted == false) + ) { + inventoryTweaks_handleScrollWheel(currentWheelDegrees); + } + } + /** - Right-click + Drag logic = distribute one item from held items to each slot */ if ( ( button == -1 ) - && ( Mouse.isButtonDown(1) ) - && ( isLeftClickDragStarted == false ) - && ( isLeftClickDragMouseTweaksStarted == false ) - && ( rightClickPersistentStack != null ) - ) - { + && ( Mouse.isButtonDown(1) ) + && ( isLeftClickDragStarted == false ) + && ( isLeftClickDragMouseTweaksStarted == false ) + && ( rightClickPersistentStack != null ) + ) { ItemInstance slotItemToExamine = slot.getItem(); /** - Do nothing if slot item does not match held item or if the slot is full */ @@ -178,10 +189,9 @@ private void inventoryTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, /** - Left-click + Drag logic = evenly distribute held items over slots */ if ( ( button == -1 ) - && ( Mouse.isButtonDown(0) ) - && ( isRightClickDragStarted == false ) - ) - { + && ( Mouse.isButtonDown(0) ) + && ( isRightClickDragStarted == false ) + ) { if (isLeftClickDragMouseTweaksStarted) { inventoryTweaks_handleLeftClickDragMouseTweaks(); } else if ( leftClickPersistentStack != null ) { @@ -196,6 +206,50 @@ private void inventoryTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, } } + @Unique private void inventoryTweaks_handleScrollWheel(int wheelDegrees) { + ItemInstance cursorStack = minecraft.player.inventory.getCursorItem(); + ItemInstance slotItemToExamine = slot.getItem(); + + if ( (null != cursorStack) + || (null != slotItemToExamine) + ) + { + float numberOfTurns = (float)wheelDegrees / 120.0f; + int cursorStackAmount = 0; + int slotStackAmount = 0; + ItemInstance itemBeingTransfered = null; + + if (null != cursorStack) { + itemBeingTransfered = cursorStack; + cursorStackAmount = cursorStack.count; + } + + if (null != slotItemToExamine) { + itemBeingTransfered = slotItemToExamine; + slotStackAmount = slotItemToExamine.count; + } + + if (0 > numberOfTurns) { + if (0 != cursorStackAmount) { + if (slotStackAmount != itemBeingTransfered.getMaxStackSize()) { + for (int turnIndex = 0; turnIndex < abs(numberOfTurns); turnIndex++) { + this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, slot.id, 1, false, this.minecraft.player); + } + } + } + } else { + if (0 != slotStackAmount) { + for (int turnIndex = 0; turnIndex < abs(numberOfTurns); turnIndex++) { + if (cursorStackAmount != itemBeingTransfered.getMaxStackSize()) { + slot.setStack(new ItemInstance(itemBeingTransfered.itemId, (slotStackAmount - 1), itemBeingTransfered.getDamage())); + minecraft.player.inventory.setCursorItem(new ItemInstance(itemBeingTransfered.itemId, (cursorStackAmount + 1), itemBeingTransfered.getDamage())); + } + } + } + } + } + } + @Unique private boolean inventoryTweaks_handleRightClick(int mouseX, int mouseY) { /** - Get held item */ ItemInstance cursorStack = minecraft.player.inventory.getCursorItem(); From a07c9bd9c877995c137fbb55b8235e4004f994b0 Mon Sep 17 00:00:00 2001 From: telontelvarost Date: Fri, 26 Jan 2024 03:21:17 -0500 Subject: [PATCH 08/13] ISSUE-8 - Write notes about configs to add and work to code --- .../com/github/telvarost/inventorytweaks/Config.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/com/github/telvarost/inventorytweaks/Config.java b/src/main/java/com/github/telvarost/inventorytweaks/Config.java index 60abd7d..82b9e20 100644 --- a/src/main/java/com/github/telvarost/inventorytweaks/Config.java +++ b/src/main/java/com/github/telvarost/inventorytweaks/Config.java @@ -50,6 +50,17 @@ public static class ModernMinecraftConfig { public static class MouseTweaksConfig { + /** @todo - All of the comments below */ + // Turn this into a category with submenus and implement the following + // - Invert scroll wheel direction -> default false + // - Position aware scrolling (inventory scroll action) -> default false + // - Slot position will determine scroll direction + // - Transfer between cursor and slot + // - Hit shift to transfer between inventories + // - Transfer between inventories without shift + // - If true disable transfer between cursor and slot + // - WheelSearchOrder true equals first to last + // - Make false for last to first @ConfigName("Cursor/Slot [ScrollWheel] transfer") public static Boolean ScrollWheelTransfer = true; From a1ea9cf8dec58ff85ac54416e3d98228d0d6e42c Mon Sep 17 00:00:00 2001 From: telontelvarost Date: Fri, 26 Jan 2024 18:50:58 -0500 Subject: [PATCH 09/13] ISSUE-8 - Update readme --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 3445e64..2f337b4 100644 --- a/README.md +++ b/README.md @@ -10,11 +10,23 @@ This mod is currently incompatible with the regular version of MojangFix. If you ## List of Changes: +* Note that all changes can be enabled/disabled in the config menu if you have ModMenu and GlassConfigAPI. + +### Modern Minecraft Changes * Adds `Left-Click + Drag` mechanic to evenly distribute held items over empty slots/slots with the same item as in modern Minecraft. * Adds `Right-Click + Drag` mechanic to distribute one item from held items over empty slots/slots with the same item as in modern Minecraft. * `LCtrl + DROP_KEY` to drop a whole stack of items. * Move items from player inventory to the hotbar by pressing the number key corresponding to the desired hotbar slot while hovering the cursor over the item to move. +### MouseTweaks Changes +* MouseTweaks `Right-Click + Drag` + * Very similar to the standard RMB dragging mechanic, with one difference: if you drag over a slot multiple times, an item will be put there multiple times. Replaces the standard mechanic if enabled. +* MouseTweaks `Left-Click + Drag` (with item) + * Lets you quickly pick up or move items of the same type. + * Move items to another inventory if holding `Shift` +* MouseTweaks `Left-Click + Drag + Shift` (without item) + * Quickly move items into another inventory. + ## Installation using Prism Launcher 1. Download an instance of Babric for Prism Launcher: https://github.com/babric/prism-instance From e2f0281bd9786b3ea919d4e2a25888c88cb3f5ba Mon Sep 17 00:00:00 2001 From: telontelvarost Date: Fri, 26 Jan 2024 19:23:59 -0500 Subject: [PATCH 10/13] ISSUE-8 - Create scroll wheel config screen and explain settings --- .../telvarost/inventorytweaks/Config.java | 40 ++++++++----- .../mixin/ContainerBaseMixin.java | 58 +++++++++++++++---- 2 files changed, 73 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/github/telvarost/inventorytweaks/Config.java b/src/main/java/com/github/telvarost/inventorytweaks/Config.java index 82b9e20..2552b31 100644 --- a/src/main/java/com/github/telvarost/inventorytweaks/Config.java +++ b/src/main/java/com/github/telvarost/inventorytweaks/Config.java @@ -50,19 +50,8 @@ public static class ModernMinecraftConfig { public static class MouseTweaksConfig { - /** @todo - All of the comments below */ - // Turn this into a category with submenus and implement the following - // - Invert scroll wheel direction -> default false - // - Position aware scrolling (inventory scroll action) -> default false - // - Slot position will determine scroll direction - // - Transfer between cursor and slot - // - Hit shift to transfer between inventories - // - Transfer between inventories without shift - // - If true disable transfer between cursor and slot - // - WheelSearchOrder true equals first to last - // - Make false for last to first - @ConfigName("Cursor/Slot [ScrollWheel] transfer") - public static Boolean ScrollWheelTransfer = true; + @ConfigCategory("Scroll Wheel Config") + public static final ScrollWheelConfig SCROLL_WHEEL_CONFIG = new ScrollWheelConfig(); @ConfigName("Empty cursor [Shift + Left-Click + Drag]") @Comment("[Shift-Click] items of any type") @@ -78,4 +67,29 @@ public static class MouseTweaksConfig { @ConfigName("[Left-Click + Drag] to pick up items") public static Boolean LMBTweakPickUp = true; } + + public static class ScrollWheelConfig { + + @ConfigName("Enable Scroll Wheel Tweaks") + public static Boolean enableScrollWheelTweaks = true; + + @ConfigName("Invert scroll wheel direction") + public static Boolean invertScrollWheelDirection = false; + + @ConfigName("Position aware scrolling (inventory transfer)") + @Comment("Slot position will determine scroll direction") + public static Boolean positionAwareScrolling = false; + + @ConfigName("Wheel slot search order (see comment)") + @Comment("true = first to last, false = last to first") + public static Boolean wheelSearchOrder = true; + + @ConfigName("[ScrollWheel] transfer (see comment)") + @Comment("true = cursor/slot, false = inventories") + public static Boolean scrollWheelBehavior = true; + + @ConfigName("[Shift + ScrollWheel] transfer (see comment)") + @Comment("true = inventories, false = cursor/slot") + public static Boolean shiftScrollWheelBehavior = true; + } } diff --git a/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java b/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java index ff29d81..6938573 100644 --- a/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java +++ b/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java @@ -144,7 +144,7 @@ private void inventoryTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, if (slot == null) return; - if (Config.MouseTweaksConfig.ScrollWheelTransfer) { + if (Config.ScrollWheelConfig.enableScrollWheelTweaks) { int currentWheelDegrees = Mouse.getDWheel(); if ( (0 != currentWheelDegrees) && (isLeftClickDragStarted == false) @@ -214,11 +214,16 @@ private void inventoryTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, || (null != slotItemToExamine) ) { + boolean isShiftKeyDown = (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)); float numberOfTurns = (float)wheelDegrees / 120.0f; int cursorStackAmount = 0; int slotStackAmount = 0; ItemInstance itemBeingTransfered = null; + if (Config.ScrollWheelConfig.invertScrollWheelDirection) { + numberOfTurns *= -1; + } + if (null != cursorStack) { itemBeingTransfered = cursorStack; cursorStackAmount = cursorStack.count; @@ -229,27 +234,56 @@ private void inventoryTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, slotStackAmount = slotItemToExamine.count; } - if (0 > numberOfTurns) { - if (0 != cursorStackAmount) { - if (slotStackAmount != itemBeingTransfered.getMaxStackSize()) { - for (int turnIndex = 0; turnIndex < abs(numberOfTurns); turnIndex++) { - this.minecraft.interactionManager.clickSlot(this.container.currentContainerId, slot.id, 1, false, this.minecraft.player); + if (isShiftKeyDown) { + if (Config.ScrollWheelConfig.shiftScrollWheelBehavior) { + + } else { + inventoryTweaks_scrollCursorSlotTransfer(numberOfTurns, cursorStackAmount, slotStackAmount, itemBeingTransfered); + } + } else { + if (Config.ScrollWheelConfig.scrollWheelBehavior) { + inventoryTweaks_scrollCursorSlotTransfer(numberOfTurns, cursorStackAmount, slotStackAmount, itemBeingTransfered); + } else { + + } + } + } + } + + @Unique private void inventoryTweaks_scrollCursorSlotTransfer(float numTurns, int cursorAmount, int slotAmount, ItemInstance transferItem) { + if (0 > numTurns) { + if (0 != cursorAmount) { + for (int turnIndex = 0; turnIndex < abs(numTurns); turnIndex++) { + if (slotAmount != transferItem.getMaxStackSize()) { + if (0 == (cursorAmount - 1)) { + minecraft.player.inventory.setCursorItem(null); + } else { + minecraft.player.inventory.setCursorItem(new ItemInstance(transferItem.itemId, (cursorAmount - 1), transferItem.getDamage())); } + slot.setStack(new ItemInstance(transferItem.itemId, (slotAmount + 1), transferItem.getDamage())); } } - } else { - if (0 != slotStackAmount) { - for (int turnIndex = 0; turnIndex < abs(numberOfTurns); turnIndex++) { - if (cursorStackAmount != itemBeingTransfered.getMaxStackSize()) { - slot.setStack(new ItemInstance(itemBeingTransfered.itemId, (slotStackAmount - 1), itemBeingTransfered.getDamage())); - minecraft.player.inventory.setCursorItem(new ItemInstance(itemBeingTransfered.itemId, (cursorStackAmount + 1), itemBeingTransfered.getDamage())); + } + } else { + if (0 != slotAmount) { + for (int turnIndex = 0; turnIndex < abs(numTurns); turnIndex++) { + if (cursorAmount != transferItem.getMaxStackSize()) { + if (0 == (slotAmount - 1)) { + slot.setStack(null); + } else { + slot.setStack(new ItemInstance(transferItem.itemId, (slotAmount - 1), transferItem.getDamage())); } + minecraft.player.inventory.setCursorItem(new ItemInstance(transferItem.itemId, (cursorAmount + 1), transferItem.getDamage())); } } } } } + @Unique private void inventoryTweaks_scrollInventoryTransfer() { + + } + @Unique private boolean inventoryTweaks_handleRightClick(int mouseX, int mouseY) { /** - Get held item */ ItemInstance cursorStack = minecraft.player.inventory.getCursorItem(); From 386f092ac7106468cecfb4deac0d5ff798f9c015 Mon Sep 17 00:00:00 2001 From: telontelvarost Date: Fri, 26 Jan 2024 19:49:31 -0500 Subject: [PATCH 11/13] ISSUE-8 - Even more configs and begin work on inventory transfer --- .../telvarost/inventorytweaks/Config.java | 11 +++++-- .../mixin/ContainerBaseMixin.java | 33 +++++++++++++++---- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/github/telvarost/inventorytweaks/Config.java b/src/main/java/com/github/telvarost/inventorytweaks/Config.java index 2552b31..7d2b0a1 100644 --- a/src/main/java/com/github/telvarost/inventorytweaks/Config.java +++ b/src/main/java/com/github/telvarost/inventorytweaks/Config.java @@ -73,10 +73,15 @@ public static class ScrollWheelConfig { @ConfigName("Enable Scroll Wheel Tweaks") public static Boolean enableScrollWheelTweaks = true; - @ConfigName("Invert scroll wheel direction") - public static Boolean invertScrollWheelDirection = false; + @ConfigName("Invert scroll direction: cursor/slot") + @Comment("For cursor/slot item transfer") + public static Boolean invertScrollCursorSlotDirection = false; - @ConfigName("Position aware scrolling (inventory transfer)") + @ConfigName("Invert scroll direction: inventories") + @Comment("For item transfer between inventories") + public static Boolean invertScrollInventoryDirection = false; + + @ConfigName("Position aware scrolling inventory transfer") @Comment("Slot position will determine scroll direction") public static Boolean positionAwareScrolling = false; diff --git a/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java b/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java index 6938573..37d9e82 100644 --- a/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java +++ b/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java @@ -220,10 +220,6 @@ private void inventoryTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, int slotStackAmount = 0; ItemInstance itemBeingTransfered = null; - if (Config.ScrollWheelConfig.invertScrollWheelDirection) { - numberOfTurns *= -1; - } - if (null != cursorStack) { itemBeingTransfered = cursorStack; cursorStackAmount = cursorStack.count; @@ -236,7 +232,7 @@ private void inventoryTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, if (isShiftKeyDown) { if (Config.ScrollWheelConfig.shiftScrollWheelBehavior) { - + inventoryTweaks_scrollInventoryTransfer(numberOfTurns, cursorStackAmount, slotStackAmount, itemBeingTransfered); } else { inventoryTweaks_scrollCursorSlotTransfer(numberOfTurns, cursorStackAmount, slotStackAmount, itemBeingTransfered); } @@ -244,14 +240,19 @@ private void inventoryTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, if (Config.ScrollWheelConfig.scrollWheelBehavior) { inventoryTweaks_scrollCursorSlotTransfer(numberOfTurns, cursorStackAmount, slotStackAmount, itemBeingTransfered); } else { - + inventoryTweaks_scrollInventoryTransfer(numberOfTurns, cursorStackAmount, slotStackAmount, itemBeingTransfered); } } } } @Unique private void inventoryTweaks_scrollCursorSlotTransfer(float numTurns, int cursorAmount, int slotAmount, ItemInstance transferItem) { + if (Config.ScrollWheelConfig.invertScrollCursorSlotDirection) { + numTurns *= -1; + } + if (0 > numTurns) { + /** - Transfer items to slot from cursor */ if (0 != cursorAmount) { for (int turnIndex = 0; turnIndex < abs(numTurns); turnIndex++) { if (slotAmount != transferItem.getMaxStackSize()) { @@ -265,6 +266,7 @@ private void inventoryTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, } } } else { + /** - Transfer items to cursor from slot */ if (0 != slotAmount) { for (int turnIndex = 0; turnIndex < abs(numTurns); turnIndex++) { if (cursorAmount != transferItem.getMaxStackSize()) { @@ -280,8 +282,25 @@ private void inventoryTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, } } - @Unique private void inventoryTweaks_scrollInventoryTransfer() { + @Unique private void inventoryTweaks_scrollInventoryTransfer(float numTurns, int cursorAmount, int slotAmount, ItemInstance transferItem) { + if (Config.ScrollWheelConfig.invertScrollInventoryDirection) { + numTurns *= -1; + } + if (0 > numTurns) { + /** - Transfer items out of slot */ + if (0 != slotAmount) { + for (int turnIndex = 0; turnIndex < abs(numTurns); turnIndex++) { + } + } + } else { + /** - Transfer items into slot */ + boolean itemExistsInContainer = false; + if (itemExistsInContainer) { + for (int turnIndex = 0; turnIndex < abs(numTurns); turnIndex++) { + } + } + } } @Unique private boolean inventoryTweaks_handleRightClick(int mouseX, int mouseY) { From e30bf97f870ed1629ab338abb5263c5091a63268 Mon Sep 17 00:00:00 2001 From: telontelvarost Date: Fri, 26 Jan 2024 22:14:13 -0500 Subject: [PATCH 12/13] ISSUE-8 - Implement simple wheel tweak --- .../telvarost/inventorytweaks/Config.java | 38 +++--- .../mixin/ContainerBaseMixin.java | 117 +++++++++++++----- 2 files changed, 102 insertions(+), 53 deletions(-) diff --git a/src/main/java/com/github/telvarost/inventorytweaks/Config.java b/src/main/java/com/github/telvarost/inventorytweaks/Config.java index 7d2b0a1..52afab9 100644 --- a/src/main/java/com/github/telvarost/inventorytweaks/Config.java +++ b/src/main/java/com/github/telvarost/inventorytweaks/Config.java @@ -77,24 +77,24 @@ public static class ScrollWheelConfig { @Comment("For cursor/slot item transfer") public static Boolean invertScrollCursorSlotDirection = false; - @ConfigName("Invert scroll direction: inventories") - @Comment("For item transfer between inventories") - public static Boolean invertScrollInventoryDirection = false; - - @ConfigName("Position aware scrolling inventory transfer") - @Comment("Slot position will determine scroll direction") - public static Boolean positionAwareScrolling = false; - - @ConfigName("Wheel slot search order (see comment)") - @Comment("true = first to last, false = last to first") - public static Boolean wheelSearchOrder = true; - - @ConfigName("[ScrollWheel] transfer (see comment)") - @Comment("true = cursor/slot, false = inventories") - public static Boolean scrollWheelBehavior = true; - - @ConfigName("[Shift + ScrollWheel] transfer (see comment)") - @Comment("true = inventories, false = cursor/slot") - public static Boolean shiftScrollWheelBehavior = true; +// @ConfigName("Invert scroll direction: inventories") +// @Comment("For item transfer between inventories") +// public static Boolean invertScrollInventoryDirection = false; +// +// @ConfigName("Position aware scrolling inventory transfer") +// @Comment("Slot position will determine scroll direction") +// public static Boolean positionAwareScrolling = false; +// +// @ConfigName("Wheel slot search order (see comment)") +// @Comment("true = first to last, false = last to first") +// public static Boolean wheelSearchOrder = true; +// +// @ConfigName("[ScrollWheel] transfer (see comment)") +// @Comment("true = cursor/slot, false = inventories") +// public static Boolean scrollWheelBehavior = true; +// +// @ConfigName("[Shift + ScrollWheel] transfer (see comment)") +// @Comment("true = inventories, false = cursor/slot") +// public static Boolean shiftScrollWheelBehavior = true; } } diff --git a/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java b/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java index 37d9e82..06e6936 100644 --- a/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java +++ b/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java @@ -214,7 +214,8 @@ private void inventoryTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, || (null != slotItemToExamine) ) { - boolean isShiftKeyDown = (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)); + //boolean isShiftKeyDown = (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)); + boolean transferAllowed = true; float numberOfTurns = (float)wheelDegrees / 120.0f; int cursorStackAmount = 0; int slotStackAmount = 0; @@ -230,19 +231,28 @@ private void inventoryTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, slotStackAmount = slotItemToExamine.count; } - if (isShiftKeyDown) { - if (Config.ScrollWheelConfig.shiftScrollWheelBehavior) { - inventoryTweaks_scrollInventoryTransfer(numberOfTurns, cursorStackAmount, slotStackAmount, itemBeingTransfered); - } else { - inventoryTweaks_scrollCursorSlotTransfer(numberOfTurns, cursorStackAmount, slotStackAmount, itemBeingTransfered); - } - } else { - if (Config.ScrollWheelConfig.scrollWheelBehavior) { - inventoryTweaks_scrollCursorSlotTransfer(numberOfTurns, cursorStackAmount, slotStackAmount, itemBeingTransfered); - } else { - inventoryTweaks_scrollInventoryTransfer(numberOfTurns, cursorStackAmount, slotStackAmount, itemBeingTransfered); - } - } + if ( (null != cursorStack) + && (null != slotItemToExamine) + ) { + transferAllowed = cursorStack.isDamageAndIDIdentical(slotItemToExamine); + } + + if (transferAllowed) { + inventoryTweaks_scrollCursorSlotTransfer(numberOfTurns, cursorStackAmount, slotStackAmount, itemBeingTransfered); + } +// if (isShiftKeyDown) { +// if (Config.ScrollWheelConfig.shiftScrollWheelBehavior) { +// inventoryTweaks_scrollInventoryTransfer(numberOfTurns, cursorStackAmount, slotStackAmount, itemBeingTransfered); +// } else { +// inventoryTweaks_scrollCursorSlotTransfer(numberOfTurns, cursorStackAmount, slotStackAmount, itemBeingTransfered); +// } +// } else { +// if (Config.ScrollWheelConfig.scrollWheelBehavior) { +// inventoryTweaks_scrollCursorSlotTransfer(numberOfTurns, cursorStackAmount, slotStackAmount, itemBeingTransfered); +// } else { +// inventoryTweaks_scrollInventoryTransfer(numberOfTurns, cursorStackAmount, slotStackAmount, itemBeingTransfered); +// } +// } } } @@ -282,26 +292,65 @@ private void inventoryTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, } } - @Unique private void inventoryTweaks_scrollInventoryTransfer(float numTurns, int cursorAmount, int slotAmount, ItemInstance transferItem) { - if (Config.ScrollWheelConfig.invertScrollInventoryDirection) { - numTurns *= -1; - } - - if (0 > numTurns) { - /** - Transfer items out of slot */ - if (0 != slotAmount) { - for (int turnIndex = 0; turnIndex < abs(numTurns); turnIndex++) { - } - } - } else { - /** - Transfer items into slot */ - boolean itemExistsInContainer = false; - if (itemExistsInContainer) { - for (int turnIndex = 0; turnIndex < abs(numTurns); turnIndex++) { - } - } - } - } +// @Unique private void inventoryTweaks_scrollInventoryTransfer(float numTurns, int cursorAmount, int slotAmount, ItemInstance transferItem) { +// int itemsLeftToAdd = 0; +// +// if (Config.ScrollWheelConfig.invertScrollInventoryDirection) { +// numTurns *= -1; +// } +// +// if (minecraft.player.container == minecraft.player.playerContainer) { +// System.out.println("Only one container exists"); +// } +// +// if (0 > numTurns) { +// /** - Transfer items out of slot */ +// if (0 != slotAmount) { +// for (int containerIndex = 0; containerIndex < minecraft.player.container.slots.lastIndexOf(Slot) - 1; containerIndex++) { +// Slot curSlot = (Slot)minecraft.player.playerContainer.slots.get(containerIndex); +//// ItemInstance curSlotItem = curSlot.getItem(); +//// int curSlotAmount = (null != curSlotItem) ? curSlotItem.count : 0; +//// +//// if ( (null == curSlotItem) +//// || ( (curSlotItem.isDamageAndIDIdentical(transferItem)) +//// && (curSlotAmount != transferItem.getMaxStackSize()) +//// ) +//// ) { +//// while ( (itemsLeftToAdd < abs(numTurns)) +//// && (curSlotAmount != transferItem.getMaxStackSize()) +//// ) { +//// if (0 == (slotAmount - 1)) { +//// slot.setStack(null); +//// } else { +//// slot.setStack(new ItemInstance(transferItem.itemId, (slotAmount - 1), transferItem.getDamage())); +//// } +//// +//// curSlot.setStack(new ItemInstance(transferItem.itemId, (curSlotAmount + 1), transferItem.getDamage())); +//// +//// curSlotItem = curSlot.getItem(); +//// curSlotAmount = (null != curSlotItem) ? curSlotItem.count : 0; +//// itemsLeftToAdd++; +//// } +//// +//// if (itemsLeftToAdd == numTurns) { +//// return; +//// } +//// } +// } +// } +// } else { +// /** - Transfer items into slot */ +// boolean itemExistsInContainer = true; +// if (itemExistsInContainer) { +//// for (int turnIndex = 0; turnIndex < abs(numTurns); turnIndex++) { +//// } +// System.out.println("Scroll up"); +// Slot slotToModify = (Slot)minecraft.player.container.slots.get(0); +// +// slotToModify.setStack(new ItemInstance(transferItem.itemId, 7, transferItem.getDamage())); +// } +// } +// } @Unique private boolean inventoryTweaks_handleRightClick(int mouseX, int mouseY) { /** - Get held item */ From 04ada8feec58dbbecc92001ae6dbd39b2265c0f1 Mon Sep 17 00:00:00 2001 From: telontelvarost Date: Fri, 26 Jan 2024 22:16:11 -0500 Subject: [PATCH 13/13] ISSUE-8 - Add note in readme about scroll wheel --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 2f337b4..d980319 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,9 @@ This mod is currently incompatible with the regular version of MojangFix. If you * Move items to another inventory if holding `Shift` * MouseTweaks `Left-Click + Drag + Shift` (without item) * Quickly move items into another inventory. +* Original take on the scroll wheel + * Scroll to move items between the cursor and the hovered slot + * Note: MouseTweaks scroll will eventually be added as well if I can figure it out ## Installation using Prism Launcher