From f1f1ce897c64217b0461fa850b228518c38a6aba Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Sat, 28 Aug 2021 15:23:44 +0700 Subject: [PATCH] Implement clone in drive menu --- .../mc/otm/menu/DriveViewerMenu.java | 19 +++++++++++++++++++ .../mc/otm/screen/DriveViewerScreen.java | 5 +++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/dbotthepony/mc/otm/menu/DriveViewerMenu.java b/src/main/java/ru/dbotthepony/mc/otm/menu/DriveViewerMenu.java index cf0d6e162..5f5262874 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/menu/DriveViewerMenu.java +++ b/src/main/java/ru/dbotthepony/mc/otm/menu/DriveViewerMenu.java @@ -303,6 +303,25 @@ public class DriveViewerMenu extends PoweredMatteryMenu { return; } + if (click == ClickType.CLONE) { + if (stack_id < 0 || !ply.getAbilities().instabuild) + return; + + var get_state = view.state.get(stack_id); + + if (get_state == null) { + return; + } + + var copy = get_state.stack.copy(); + copy.setCount(Math.min(copy.getCount(), copy.getMaxStackSize())); + + menu.setCarried(copy); + MatteryNetworking.send(ply, new SetCarriedPacket(menu.getCarried())); + menu.setRemoteCarried(menu.getCarried().copy()); + return; + } + if (!menu.getCarried().isEmpty() && click != ClickType.QUICK_MOVE) { // try to put if (action == ClickAction.PRIMARY) { diff --git a/src/main/java/ru/dbotthepony/mc/otm/screen/DriveViewerScreen.java b/src/main/java/ru/dbotthepony/mc/otm/screen/DriveViewerScreen.java index 29f0ae551..425df0015 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/screen/DriveViewerScreen.java +++ b/src/main/java/ru/dbotthepony/mc/otm/screen/DriveViewerScreen.java @@ -1,5 +1,6 @@ package ru.dbotthepony.mc.otm.screen; +import com.mojang.blaze3d.platform.InputConstants; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.inventory.ClickAction; @@ -79,9 +80,9 @@ public class DriveViewerScreen extends MatteryScreen implements protected boolean mouseClickedInner(double mouse_x, double mouse_y, int mouse_click_type) { int findex = index + scroll_bar.getScroll(GRID_WIDTH); var list = menu.view.getItems(); - var action = mouse_click_type == 0 ? ClickAction.PRIMARY : ClickAction.SECONDARY; + var action = mouse_click_type == InputConstants.MOUSE_BUTTON_LEFT ? ClickAction.PRIMARY : ClickAction.SECONDARY; - var type = hasShiftDown() ? ClickType.QUICK_MOVE : ClickType.PICKUP; + var type = mouse_click_type == InputConstants.MOUSE_BUTTON_MIDDLE ? ClickType.CLONE : hasShiftDown() ? ClickType.QUICK_MOVE : ClickType.PICKUP; MatteryNetworking.send(new DriveViewerMenu.InteractPacket(menu.containerId, findex >= list.size() ? -1 : list.get(findex).id(), type, action)); return true;