Skip to content

Commit

Permalink
Fixed desync on middle click drag
Browse files Browse the repository at this point in the history
Fixed desync on left/right click drag when colliding with other buttons
  • Loading branch information
landonjw committed Apr 2, 2021
1 parent 793f356 commit 24d4715
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import ca.landonjw.gooeylibs.api.template.TemplateType;
import ca.landonjw.gooeylibs.api.template.slot.TemplateSlot;
import ca.landonjw.gooeylibs.api.template.types.InventoryTemplate;
import ca.landonjw.gooeylibs.implementation.tasks.Task;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.ClickType;
Expand Down Expand Up @@ -212,6 +213,22 @@ public ItemStack slotClick(int slot, int dragType, ClickType clickType, EntityPl
lastClickTick = server.getTickCounter();
}

if (clickType == ClickType.QUICK_CRAFT && dragType == 8) {
/*
* If the user middle clicks and drags, this refreshes the container at the end of the tick.
* This is done because the click type propagates with the drag, yet does not always have a
* termination drag type. So we track the entry drag, and prevent the rest of the clicks from
* invoking.
*/
Task.builder()
.execute(() -> {
updateAllContainerContents();
setPlayersCursor((cursorButton != null) ? cursorButton.getDisplay() : ItemStack.EMPTY);
})
.build();
return ItemStack.EMPTY;
}

patchDesyncs(slot, clickType);

Button clickedButton = getButton(slot);
Expand Down Expand Up @@ -297,6 +314,10 @@ private ItemStack handleMoveableButton(int slot, int dragType, ClickType clickTy
if (clickedButton == null) {
return ItemStack.EMPTY;
}
if (clickType == ClickType.QUICK_CRAFT && dragType == 9) {
setPlayersCursor(ItemStack.EMPTY);
return ItemStack.EMPTY;
}

ButtonClick click = getButtonClickType(clickType, dragType);
MovableButtonAction action = new MovableButtonAction(player, click, clickedButton, template, page, targetTemplateSlot);
Expand Down Expand Up @@ -337,6 +358,9 @@ private ItemStack handleMoveableButton(int slot, int dragType, ClickType clickTy
*/
if (clickType == ClickType.QUICK_MOVE || clickType == ClickType.CLONE || clickType == ClickType.THROW) {
return ItemStack.EMPTY;
} else if (clickType == ClickType.QUICK_CRAFT) {
updateSlotStack(slot, getItemAtSlot(slot), isSlotInPlayerInventory(slot));
return ItemStack.EMPTY;
} else {
return cursorButton.getDisplay();
}
Expand Down

0 comments on commit 24d4715

Please sign in to comment.