Skip to content

Commit

Permalink
Add quickSwap() Action (MeteorDevelopment#3985)
Browse files Browse the repository at this point in the history
  • Loading branch information
RaccTheRicky authored Aug 25, 2023
1 parent cf6e9b4 commit ce32561
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ private void moveSlots(ScreenHandler handler, int start, int end, boolean steal)
int iCopy = i;
Rotations.rotate(mc.player.getYaw() - 180, mc.player.getPitch(), () -> InvUtils.drop().slotId(iCopy));
}
} else InvUtils.quickMove().slotId(i);
} else InvUtils.shiftClick().slotId(i);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private boolean insertWaterBottles(BrewingStandScreenHandler c) {

private boolean takePotions(BrewingStandScreenHandler c) {
for (int i = 0; i < 3; i++) {
InvUtils.quickMove().slotId(i);
InvUtils.shiftClick().slotId(i);

if (!c.slots.get(i).getStack().isEmpty()) {
error("You do not have a sufficient amount of inventory space... disabling.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ private void takeResults(AbstractFurnaceScreenHandler c) {
ItemStack resultStack = c.slots.get(2).getStack();
if (resultStack.isEmpty()) return;

InvUtils.quickMove().slotId(2);
InvUtils.shiftClick().slotId(2);

if (!resultStack.isEmpty()) {
error("Your inventory is full. Disabling.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private boolean findPickaxe() {
&& !Utils.hasEnchantments(stack, Enchantments.SILK_TOUCH));
FindItemResult bestPick = InvUtils.findInHotbar(pickaxePredicate);

if (bestPick.isOffhand()) InvUtils.quickMove().fromOffhand().toHotbar(mc.player.getInventory().selectedSlot);
if (bestPick.isOffhand()) InvUtils.shiftClick().fromOffhand().toHotbar(mc.player.getInventory().selectedSlot);
else if (bestPick.isHotbar()) InvUtils.swap(bestPick.slot(), false);

return InvUtils.testInMainHand(pickaxePredicate);
Expand Down Expand Up @@ -233,7 +233,7 @@ private boolean isFull() {
for (int i = 0; i <= 35; i++) {
ItemStack itemStack = mc.player.getInventory().getStack(i);
if (itemStack.isEmpty()) return false;

for (Item item : targetItems.get()) {
if (itemStack.getItem() == item && itemStack.getCount() < itemStack.getMaxCount()) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,17 @@ public static Action click() {
return ACTION;
}

public static Action quickMove() {
/**
* When writing code with quickSwap, both to and from should provide the ID of a slot, not the index.
* From should be the slot in the hotbar, to should be the slot you're switching an item from.
*/

public static Action quickSwap() {
ACTION.type = SlotActionType.SWAP;
return ACTION;
}

public static Action shiftClick() {
ACTION.type = SlotActionType.QUICK_MOVE;
return ACTION;
}
Expand Down Expand Up @@ -290,6 +300,11 @@ public void slotArmor(int i) {
private void run() {
boolean hadEmptyCursor = mc.player.currentScreenHandler.getCursorStack().isEmpty();

if (type == SlotActionType.SWAP) {
data = from;
from = to;
}

if (type != null && from != -1 && to != -1) {
click(from);
if (two) click(to);
Expand Down

0 comments on commit ce32561

Please sign in to comment.