Add scrolling to support to grid (#2409)
* add an onExtract Method for extracting without knowing the ID onExtract now supports a preferred slot for insertion onInsert now supports single * add support for grid item movement via Scrolling * add MouseTweaks Compatibility fix item void bug * Add scrolling to amount specifying screens * fix reference and comment out mousetweaks integration * fix missing import * cleanup * more cleanup * changelog * fix reqeusted changes * fix method name fix accidental formatting errors
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
# Refined Storage Changelog
|
||||
|
||||
### 1.9.7
|
||||
- Added functionality to move items in the Grid with shift/ctrl + scrolling (Darkere)
|
||||
- Changed JEI transfer error mechanics (raoulvdberge)
|
||||
- Fixed crash when opening Controller GUI (Darkere)
|
||||
- Fixed dye being consumed without effect in some cases (Darkere)
|
||||
- Fixed dye being consumed without effect in some cases (Darkere)
|
||||
|
||||
### 1.9.6
|
||||
- Port to Minecraft 1.16.3 (raoulvdberge)
|
||||
|
||||
@@ -16,24 +16,36 @@ public interface IItemGridHandler {
|
||||
int EXTRACT_SINGLE = 2;
|
||||
int EXTRACT_SHIFT = 4;
|
||||
|
||||
/**
|
||||
* Called when a player tries to extract an item from the grid through the Inventory
|
||||
*
|
||||
* @param player the player that is attempting the extraction
|
||||
* @param stack the stack we're trying to extract
|
||||
* @param preferredSlot playerInventory slot to prefer when adding or -1
|
||||
* @param flags how we are extracting, see the flags in {@link IItemGridHandler}
|
||||
*/
|
||||
void onExtract(ServerPlayerEntity player, ItemStack stack, int preferredSlot, int flags);
|
||||
|
||||
/**
|
||||
* Called when a player tries to extract an item from the grid.
|
||||
*
|
||||
* @param player the player that is attempting the extraction
|
||||
* @param id the id of the item we're trying to extract, this id is the id from {@link StackListEntry}
|
||||
* @param flags how we are extracting, see the flags in {@link IItemGridHandler}
|
||||
* @param player the player that is attempting the extraction
|
||||
* @param id the id of the item we're trying to extract, this id is the id from {@link StackListEntry}
|
||||
* @param preferredSlot playerInventory slot to prefer when adding or -1
|
||||
* @param flags how we are extracting, see the flags in {@link IItemGridHandler}
|
||||
*/
|
||||
void onExtract(ServerPlayerEntity player, UUID id, int flags);
|
||||
void onExtract(ServerPlayerEntity player, UUID id, int preferredSlot, int flags);
|
||||
|
||||
/**
|
||||
* Called when a player tries to insert an item in the grid.
|
||||
*
|
||||
* @param player the player that is attempting the insert
|
||||
* @param stack the item we're trying to insert
|
||||
* @param single true if we are only inserting a single item, false otherwise
|
||||
* @return the remainder, or an empty stack if there is no remainder
|
||||
*/
|
||||
@Nonnull
|
||||
ItemStack onInsert(ServerPlayerEntity player, ItemStack stack);
|
||||
ItemStack onInsert(ServerPlayerEntity player, ItemStack stack, boolean single);
|
||||
|
||||
/**
|
||||
* Called when a player is trying to insert an item that it is holding in their hand in the GUI.
|
||||
@@ -69,4 +81,25 @@ public interface IItemGridHandler {
|
||||
* @param id the task id, or null to cancel all tasks that are in the network currently
|
||||
*/
|
||||
void onCraftingCancelRequested(ServerPlayerEntity player, @Nullable UUID id);
|
||||
|
||||
/**
|
||||
* Called when a player shift or ctrl scrolls in the player inventory
|
||||
*
|
||||
* @param player player that is scrolling
|
||||
* @param slot slot the mouse is hovering over
|
||||
* @param shift if true shift is pressed, if false ctrl is pressed
|
||||
* @param up whether the player is scrolling up or down
|
||||
*/
|
||||
void onInventoryScroll(ServerPlayerEntity player, int slot, boolean shift, boolean up);
|
||||
|
||||
/**
|
||||
* Called when a player shift or ctrl scrolls in the Grid View
|
||||
*
|
||||
* @param player player that is scrolling
|
||||
* @param id UUID of the GridStack that the mouse is hovering over or UUID(0,0) if not over a stack
|
||||
* @param shift true if shift is pressed
|
||||
* @param ctrl true if ctrl is pressed
|
||||
* @param up whether the player is scrolling up or down
|
||||
*/
|
||||
void onGridScroll(ServerPlayerEntity player, UUID id, boolean shift, boolean ctrl, boolean up);
|
||||
}
|
||||
|
||||
@@ -4,11 +4,16 @@ import com.refinedmods.refinedstorage.RS;
|
||||
import com.refinedmods.refinedstorage.api.autocrafting.task.CalculationResultType;
|
||||
import com.refinedmods.refinedstorage.api.autocrafting.task.ICalculationResult;
|
||||
import com.refinedmods.refinedstorage.api.network.INetwork;
|
||||
import com.refinedmods.refinedstorage.api.network.grid.IGrid;
|
||||
import com.refinedmods.refinedstorage.api.network.grid.handler.IItemGridHandler;
|
||||
import com.refinedmods.refinedstorage.api.network.security.Permission;
|
||||
import com.refinedmods.refinedstorage.api.util.Action;
|
||||
import com.refinedmods.refinedstorage.api.util.IComparer;
|
||||
import com.refinedmods.refinedstorage.api.util.StackListEntry;
|
||||
import com.refinedmods.refinedstorage.apiimpl.API;
|
||||
import com.refinedmods.refinedstorage.apiimpl.autocrafting.preview.ErrorCraftingPreviewElement;
|
||||
import com.refinedmods.refinedstorage.apiimpl.storage.cache.ItemStorageCache;
|
||||
import com.refinedmods.refinedstorage.container.GridContainer;
|
||||
import com.refinedmods.refinedstorage.network.grid.GridCraftingPreviewResponseMessage;
|
||||
import com.refinedmods.refinedstorage.network.grid.GridCraftingStartResponseMessage;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
@@ -21,6 +26,7 @@ import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ItemGridHandler implements IItemGridHandler {
|
||||
@@ -31,7 +37,15 @@ public class ItemGridHandler implements IItemGridHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExtract(ServerPlayerEntity player, UUID id, int flags) {
|
||||
public void onExtract(ServerPlayerEntity player, ItemStack stack, int preferredSlot, int flags) {
|
||||
StackListEntry<ItemStack> stackEntry = network.getItemStorageCache().getList().getEntry(stack, IComparer.COMPARE_NBT);
|
||||
if (stackEntry != null) {
|
||||
onExtract(player, stackEntry.getId(), preferredSlot, flags);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExtract(ServerPlayerEntity player, UUID id, int preferredSlot, int flags) {
|
||||
ItemStack item = network.getItemStorageCache().getList().get(id);
|
||||
|
||||
if (item == null || !network.getSecurityManager().hasPermission(Permission.EXTRACT, player)) {
|
||||
@@ -81,12 +95,23 @@ public class ItemGridHandler implements IItemGridHandler {
|
||||
|
||||
if (!took.isEmpty()) {
|
||||
if ((flags & EXTRACT_SHIFT) == EXTRACT_SHIFT) {
|
||||
IItemHandler playerInventory = player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, Direction.UP).orElse(null);
|
||||
Optional<IItemHandler> playerInventory = player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, Direction.UP).resolve();
|
||||
if (playerInventory.isPresent()) {
|
||||
if (preferredSlot != -1) {
|
||||
ItemStack remainder = playerInventory.get().insertItem(preferredSlot, took, true);
|
||||
if (remainder.getCount() != took.getCount()) {
|
||||
ItemStack inserted = network.extractItem(item, size - remainder.getCount(), Action.PERFORM);
|
||||
playerInventory.get().insertItem(preferredSlot, inserted, false);
|
||||
took.setCount(remainder.getCount());
|
||||
}
|
||||
}
|
||||
if (!took.isEmpty()) {
|
||||
if (ItemHandlerHelper.insertItemStacked(playerInventory.get(), took, true).isEmpty()) {
|
||||
took = network.extractItem(item, size, Action.PERFORM);
|
||||
|
||||
if (playerInventory != null && ItemHandlerHelper.insertItem(playerInventory, took, true).isEmpty()) {
|
||||
took = network.extractItem(item, size, Action.PERFORM);
|
||||
|
||||
ItemHandlerHelper.insertItem(playerInventory, took, false);
|
||||
ItemHandlerHelper.insertItemStacked(playerInventory.get(), took, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
took = network.extractItem(item, size, Action.PERFORM);
|
||||
@@ -108,14 +133,23 @@ public class ItemGridHandler implements IItemGridHandler {
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack onInsert(ServerPlayerEntity player, ItemStack stack) {
|
||||
public ItemStack onInsert(ServerPlayerEntity player, ItemStack stack, boolean single) {
|
||||
if (!network.getSecurityManager().hasPermission(Permission.INSERT, player)) {
|
||||
return stack;
|
||||
}
|
||||
|
||||
network.getItemStorageTracker().changed(player, stack.copy());
|
||||
|
||||
ItemStack remainder = network.insertItem(stack, stack.getCount(), Action.PERFORM);
|
||||
ItemStack remainder;
|
||||
if (single) {
|
||||
if (network.insertItem(stack, 1, Action.SIMULATE).isEmpty()) {
|
||||
network.insertItem(stack, 1, Action.PERFORM);
|
||||
stack.shrink(1);
|
||||
}
|
||||
remainder = stack;
|
||||
} else {
|
||||
remainder = network.insertItem(stack, stack.getCount(), Action.PERFORM);
|
||||
}
|
||||
|
||||
network.getNetworkItemManager().drainEnergy(player, RS.SERVER_CONFIG.getWirelessGrid().getInsertUsage());
|
||||
|
||||
@@ -217,4 +251,94 @@ public class ItemGridHandler implements IItemGridHandler {
|
||||
|
||||
network.getNetworkItemManager().drainEnergy(player, id == null ? RS.SERVER_CONFIG.getWirelessCraftingMonitor().getCancelAllUsage() : RS.SERVER_CONFIG.getWirelessCraftingMonitor().getCancelUsage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInventoryScroll(ServerPlayerEntity player, int slot, boolean shift, boolean up) {
|
||||
if (player == null || !(player.openContainer instanceof GridContainer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (up && !network.getSecurityManager().hasPermission(Permission.INSERT, player) || !up && !network.getSecurityManager().hasPermission(Permission.EXTRACT, player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int flags = EXTRACT_SINGLE;
|
||||
ItemStack stackInSlot = player.inventory.getStackInSlot(slot);
|
||||
ItemStack stackOnCursor = player.inventory.getItemStack();
|
||||
|
||||
if (shift) { // shift
|
||||
flags |= EXTRACT_SHIFT;
|
||||
if (up) { // scroll up
|
||||
player.inventory.setInventorySlotContents(slot, onInsert(player, stackInSlot, true));
|
||||
} else { // scroll down
|
||||
onExtract(player, stackInSlot, slot, flags);
|
||||
}
|
||||
|
||||
} else { //ctrl
|
||||
if (up) { // scroll up
|
||||
onInsert(player, stackOnCursor, true);
|
||||
player.updateHeldItem();
|
||||
} else { //scroll down
|
||||
if (stackOnCursor.isEmpty()) {
|
||||
onExtract(player, stackInSlot, -1, flags);
|
||||
} else {
|
||||
onExtract(player, stackOnCursor, -1, flags);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGridScroll(ServerPlayerEntity player, UUID id, boolean shift, boolean ctrl, boolean up) {
|
||||
if (player == null || !(player.openContainer instanceof GridContainer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (up && !network.getSecurityManager().hasPermission(Permission.INSERT, player) || !up && !network.getSecurityManager().hasPermission(Permission.EXTRACT, player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
IGrid grid = ((GridContainer) player.openContainer).getGrid();
|
||||
|
||||
int flags = EXTRACT_SINGLE;
|
||||
|
||||
if (!id.equals(new UUID(0, 0))) { //isOverStack
|
||||
if (shift && !ctrl) { //shift
|
||||
flags |= EXTRACT_SHIFT;
|
||||
|
||||
if (up) { //scroll up, insert hovering stack pulled from Inventory
|
||||
ItemStorageCache cache = (ItemStorageCache) grid.getStorageCache();
|
||||
if (cache == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack stack = cache.getList().get(id);
|
||||
if (stack == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int slot = player.inventory.getSlotFor(stack);
|
||||
if (slot != -1) {
|
||||
onInsert(player, player.inventory.getStackInSlot(slot), true);
|
||||
return;
|
||||
}
|
||||
|
||||
} else { //scroll down, extract hovering item
|
||||
onExtract(player, id, -1, flags);
|
||||
return;
|
||||
}
|
||||
|
||||
} else if (!shift && ctrl) { //ctrl
|
||||
if (!up) { //scroll down, extract hovering item
|
||||
onExtract(player, id, -1, flags);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (up) { //scroll up, insert item from cursor
|
||||
onInsert(player, player.inventory.getItemStack(), true);
|
||||
player.updateHeldItem();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,18 @@ public class PortableItemGridHandler implements IItemGridHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExtract(ServerPlayerEntity player, UUID id, int flags) {
|
||||
public void onExtract(ServerPlayerEntity player, ItemStack stack, int preferredSlot, int flags) {
|
||||
if (portableGrid.getStorage() == null || !grid.isGridActive()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (portableGrid.getItemCache().getList().getEntry(stack, IComparer.COMPARE_NBT) != null) {
|
||||
onExtract(player, portableGrid.getItemCache().getList().getEntry(stack, IComparer.COMPARE_NBT).getId(), preferredSlot, flags);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExtract(ServerPlayerEntity player, UUID id, int preferredSlot, int flags) {
|
||||
if (portableGrid.getStorage() == null || !grid.isGridActive()) {
|
||||
return;
|
||||
}
|
||||
@@ -83,11 +94,23 @@ public class PortableItemGridHandler implements IItemGridHandler {
|
||||
if (!took.isEmpty()) {
|
||||
if ((flags & EXTRACT_SHIFT) == EXTRACT_SHIFT) {
|
||||
IItemHandler playerInventory = player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, Direction.UP).orElse(null);
|
||||
if (playerInventory != null) {
|
||||
if (preferredSlot != -1) {
|
||||
ItemStack remainder = playerInventory.insertItem(preferredSlot, took, true);
|
||||
if (remainder.getCount() != took.getCount()) {
|
||||
ItemStack inserted = portableGrid.getItemStorage().extract(item, size - remainder.getCount(), IComparer.COMPARE_NBT, Action.PERFORM);
|
||||
playerInventory.insertItem(preferredSlot, inserted, false);
|
||||
took.setCount(remainder.getCount());
|
||||
}
|
||||
}
|
||||
|
||||
if (playerInventory != null && ItemHandlerHelper.insertItem(playerInventory, took, true).isEmpty()) {
|
||||
took = portableGrid.getItemStorage().extract(item, size, IComparer.COMPARE_NBT, Action.PERFORM);
|
||||
if (!took.isEmpty()) {
|
||||
if (ItemHandlerHelper.insertItemStacked(playerInventory, took, true).isEmpty()) {
|
||||
took = portableGrid.getItemStorage().extract(item, size, IComparer.COMPARE_NBT, Action.PERFORM);
|
||||
|
||||
ItemHandlerHelper.insertItem(playerInventory, took, false);
|
||||
ItemHandlerHelper.insertItemStacked(playerInventory, took, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
took = portableGrid.getItemStorage().extract(item, size, IComparer.COMPARE_NBT, Action.PERFORM);
|
||||
@@ -107,14 +130,22 @@ public class PortableItemGridHandler implements IItemGridHandler {
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack onInsert(ServerPlayerEntity player, ItemStack stack) {
|
||||
public ItemStack onInsert(ServerPlayerEntity player, ItemStack stack, boolean single) {
|
||||
if (portableGrid.getStorage() == null || !grid.isGridActive()) {
|
||||
return stack;
|
||||
}
|
||||
|
||||
portableGrid.getItemStorageTracker().changed(player, stack.copy());
|
||||
|
||||
ItemStack remainder = portableGrid.getItemStorage().insert(stack, stack.getCount(), Action.PERFORM);
|
||||
ItemStack remainder;
|
||||
if (single) {
|
||||
if (portableGrid.getItemStorage().insert(stack, 1, Action.SIMULATE).isEmpty()) {
|
||||
portableGrid.getItemStorage().insert(stack, 1, Action.PERFORM);
|
||||
stack.shrink(1);
|
||||
}
|
||||
remainder = stack;
|
||||
} else {
|
||||
remainder = portableGrid.getItemStorage().insert(stack, stack.getCount(), Action.PERFORM);
|
||||
}
|
||||
|
||||
portableGrid.drainEnergy(RS.SERVER_CONFIG.getPortableGrid().getInsertUsage());
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ public class GridContainer extends BaseContainer implements ICraftingGridListene
|
||||
IItemGridHandler itemHandler = grid.getItemHandler();
|
||||
|
||||
if (itemHandler != null) {
|
||||
slot.putStack(itemHandler.onInsert((ServerPlayerEntity) getPlayer(), stack));
|
||||
slot.putStack(itemHandler.onInsert((ServerPlayerEntity) getPlayer(), stack, false));
|
||||
} else if (slot instanceof CraftingGridSlot && mergeItemStack(stack, 14, 14 + (9 * 4), false)) {
|
||||
slot.onSlotChanged();
|
||||
|
||||
|
||||
@@ -37,6 +37,8 @@ public class NetworkHandler {
|
||||
handler.registerMessage(id++, GridItemUpdateMessage.class, GridItemUpdateMessage::encode, GridItemUpdateMessage::decode, GridItemUpdateMessage::handle);
|
||||
handler.registerMessage(id++, GridItemDeltaMessage.class, GridItemDeltaMessage::encode, GridItemDeltaMessage::decode, GridItemDeltaMessage::handle);
|
||||
handler.registerMessage(id++, GridItemPullMessage.class, GridItemPullMessage::encode, GridItemPullMessage::decode, GridItemPullMessage::handle);
|
||||
handler.registerMessage(id++, GridItemGridScrollMessage.class, GridItemGridScrollMessage::encode, GridItemGridScrollMessage::decode, GridItemGridScrollMessage::handle);
|
||||
handler.registerMessage(id++, GridItemInventoryScrollMessage.class, GridItemInventoryScrollMessage::encode, GridItemInventoryScrollMessage::decode, GridItemInventoryScrollMessage::handle);
|
||||
handler.registerMessage(id++, GridItemInsertHeldMessage.class, GridItemInsertHeldMessage::encode, GridItemInsertHeldMessage::decode, GridItemInsertHeldMessage::handle);
|
||||
handler.registerMessage(id++, GridClearMessage.class, GridClearMessage::encode, GridClearMessage::decode, GridClearMessage::handle);
|
||||
handler.registerMessage(id++, GridPatternCreateMessage.class, GridPatternCreateMessage::encode, GridPatternCreateMessage::decode, GridPatternCreateMessage::handle);
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.refinedmods.refinedstorage.network.grid;
|
||||
|
||||
import com.refinedmods.refinedstorage.container.GridContainer;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class GridItemGridScrollMessage {
|
||||
private final UUID id;
|
||||
private final boolean shift;
|
||||
private final boolean up;
|
||||
private final boolean ctrl;
|
||||
|
||||
public GridItemGridScrollMessage(UUID id, boolean shift, boolean ctrl, boolean up) {
|
||||
this.id = id;
|
||||
this.shift = shift;
|
||||
this.ctrl = ctrl;
|
||||
this.up = up;
|
||||
}
|
||||
|
||||
public static GridItemGridScrollMessage decode(PacketBuffer buf) {
|
||||
return new GridItemGridScrollMessage(buf.readUniqueId(), buf.readBoolean(), buf.readBoolean(), buf.readBoolean());
|
||||
}
|
||||
|
||||
public static void encode(GridItemGridScrollMessage message, PacketBuffer buf) {
|
||||
buf.writeUniqueId(message.id);
|
||||
buf.writeBoolean(message.shift);
|
||||
buf.writeBoolean(message.ctrl);
|
||||
buf.writeBoolean(message.up);
|
||||
}
|
||||
|
||||
public static void handle(GridItemGridScrollMessage message, Supplier<NetworkEvent.Context> ctx) {
|
||||
ctx.get().enqueueWork(() -> {
|
||||
if (ctx.get().getSender() != null && ctx.get().getSender().openContainer instanceof GridContainer) {
|
||||
((GridContainer) ctx.get().getSender().openContainer).getGrid().getItemHandler().onGridScroll(ctx.get().getSender(), message.id, message.shift, message.ctrl, message.up);
|
||||
}
|
||||
});
|
||||
ctx.get().setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.refinedmods.refinedstorage.network.grid;
|
||||
|
||||
import com.refinedmods.refinedstorage.container.GridContainer;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class GridItemInventoryScrollMessage {
|
||||
private final int slot;
|
||||
private final boolean shift;
|
||||
private final boolean up;
|
||||
|
||||
public GridItemInventoryScrollMessage(int slot, boolean shift, boolean up) {
|
||||
this.slot = slot;
|
||||
this.shift = shift;
|
||||
this.up = up;
|
||||
}
|
||||
|
||||
public static GridItemInventoryScrollMessage decode(PacketBuffer buf) {
|
||||
return new GridItemInventoryScrollMessage(buf.readInt(), buf.readBoolean(), buf.readBoolean());
|
||||
}
|
||||
|
||||
public static void encode(GridItemInventoryScrollMessage message, PacketBuffer buf) {
|
||||
buf.writeInt(message.slot);
|
||||
buf.writeBoolean(message.shift);
|
||||
buf.writeBoolean(message.up);
|
||||
}
|
||||
|
||||
public static void handle(GridItemInventoryScrollMessage message, Supplier<NetworkEvent.Context> ctx) {
|
||||
ctx.get().enqueueWork(() -> {
|
||||
if (ctx.get().getSender() != null && ctx.get().getSender().openContainer instanceof GridContainer) {
|
||||
((GridContainer) ctx.get().getSender().openContainer).getGrid().getItemHandler().onInventoryScroll(ctx.get().getSender(), message.slot, message.shift, message.up);
|
||||
}
|
||||
});
|
||||
ctx.get().setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ public class GridItemPullMessage {
|
||||
IGrid grid = ((GridContainer) container).getGrid();
|
||||
|
||||
if (grid.getItemHandler() != null) {
|
||||
grid.getItemHandler().onExtract(player, message.id, message.flags);
|
||||
grid.getItemHandler().onExtract(player, message.id, -1, message.flags);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -171,6 +171,17 @@ public abstract class AmountSpecifyingScreen<T extends Container> extends BaseSc
|
||||
// NO OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseScrolled(double x, double y, double delta) {
|
||||
if (delta > 0) {
|
||||
onIncrementButtonClicked(1);
|
||||
} else {
|
||||
onIncrementButtonClicked(-1);
|
||||
}
|
||||
|
||||
return super.mouseScrolled(x, y, delta);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
minecraft.displayGuiScreen(parent);
|
||||
}
|
||||
|
||||
@@ -40,10 +40,13 @@ import net.minecraft.util.SoundEvents;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import yalter.mousetweaks.api.MouseTweaksDisableWheelTweak;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@MouseTweaksDisableWheelTweak
|
||||
public class GridScreen extends BaseScreen<GridContainer> implements IScreenInfoProvider {
|
||||
private static String searchQuery = "";
|
||||
|
||||
@@ -528,7 +531,29 @@ public class GridScreen extends BaseScreen<GridContainer> implements IScreenInfo
|
||||
|
||||
@Override
|
||||
public boolean mouseScrolled(double x, double y, double delta) {
|
||||
return this.scrollbar.mouseScrolled(x, y, delta) || super.mouseScrolled(x, y, delta);
|
||||
if (hasShiftDown() || hasControlDown()) {
|
||||
if (RS.CLIENT_CONFIG.getGrid().getPreventSortingWhileShiftIsDown()) {
|
||||
doSort = !isOverSlotArea(x - guiLeft, y - guiTop) && !isOverCraftingOutputArea(x - guiLeft, y - guiTop);
|
||||
}
|
||||
|
||||
if (isOverInventory(x - guiLeft, y - guiTop)) {
|
||||
if (grid.getGridType() != GridType.FLUID && hoveredSlot != null) {
|
||||
RS.NETWORK_HANDLER.sendToServer(new GridItemInventoryScrollMessage(hoveredSlot.getSlotIndex(), hasShiftDown(), delta > 0));
|
||||
}
|
||||
} else if (isOverSlotArea(x - guiLeft, y - guiTop)) {
|
||||
if (grid.getGridType() != GridType.FLUID) {
|
||||
RS.NETWORK_HANDLER.sendToServer(new GridItemGridScrollMessage(isOverSlotWithStack() ? view.getStacks().get(slotNumber).getId() : new UUID(0, 0), hasShiftDown(), hasControlDown(), delta > 0));
|
||||
}
|
||||
}
|
||||
|
||||
return super.mouseScrolled(x, y, delta);
|
||||
} else {
|
||||
return this.scrollbar.mouseScrolled(x, y, delta) || super.mouseScrolled(x, y, delta);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isOverInventory(double x, double y) {
|
||||
return RenderUtils.inBounds(8, getYPlayerInventory(), 9 * 18 - 2, 4 * 18 + 2, x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user