Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add quickSwap() Action #3985

Merged
merged 3 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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