Skip to content

Commit eb43be9

Browse files
committed
implement dragging for input slots
1 parent fb29c8f commit eb43be9

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/main/java/gregtech/common/mui/widget/workbench/CraftingInputSlot.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import net.minecraftforge.items.IItemHandlerModifiable;
1010
import net.minecraftforge.items.ItemHandlerHelper;
1111

12+
import com.cleanroommc.modularui.api.widget.IGuiAction;
1213
import com.cleanroommc.modularui.api.widget.Interactable;
1314
import com.cleanroommc.modularui.integration.jei.JeiGhostIngredientSlot;
1415
import com.cleanroommc.modularui.integration.jei.JeiIngredientProvider;
@@ -29,6 +30,7 @@ public class CraftingInputSlot extends Widget<CraftingOutputSlot> implements Int
2930

3031
private final InputSyncHandler syncHandler;
3132
public boolean hasIngredients = true;
33+
private static boolean dragging = false;
3234

3335
private CraftingInputSlot(IItemHandlerModifiable handler, int index) {
3436
this.syncHandler = new InputSyncHandler(handler, index);
@@ -40,6 +42,21 @@ private CraftingInputSlot(IItemHandlerModifiable handler, int index) {
4042
if (stack.isEmpty()) return;
4143
tooltip.addFromItem(stack);
4244
});
45+
46+
listenGuiAction((IGuiAction.MouseDrag) (m, t) -> {
47+
if (isHovering() && dragging && syncHandler.isValid()) {
48+
var player = syncHandler.getSyncManager().getCursorItem();
49+
if (!ItemHandlerHelper.canItemStacksStack(player, getStack()))
50+
syncHandler.syncStack();
51+
return true;
52+
}
53+
return false;
54+
});
55+
56+
listenGuiAction((IGuiAction.MouseReleased) mouseButton -> {
57+
dragging = false;
58+
return true;
59+
});
4360
}
4461

4562
public static CraftingInputSlot create(CraftingRecipeLogic logic, IItemHandlerModifiable handler, int index) {
@@ -66,13 +83,20 @@ public CraftingInputSlot changeListener(IOnSlotChanged listener) {
6683
@NotNull
6784
@Override
6885
public Result onMousePressed(int mouseButton) {
69-
if (!this.syncHandler.isValid())
86+
if (!this.syncHandler.isValid() || dragging)
7087
return Result.IGNORE;
7188

7289
this.syncHandler.syncStack();
7390
return Result.SUCCESS;
7491
}
7592

93+
@Override
94+
public void onMouseDrag(int mouseButton, long timeSinceClick) {
95+
if (!dragging && timeSinceClick > 100) {
96+
dragging = true;
97+
}
98+
}
99+
76100
@Override
77101
public void draw(ModularGuiContext context, WidgetTheme widgetTheme) {
78102
ItemStack itemstack = this.syncHandler.getStack();

0 commit comments

Comments
 (0)