Fixes to scrollingpr (#2695)
* fix UUID comparison * prevent sorting when pressing ctrl as well * fix missed change * nullable * Revert "prevent sorting when pressing ctrl as well" This reverts commit b1e2932c * improve if statements * prevent sorting on ctrl fix isEmpty * remove middle mouse click extraction
This commit is contained in:
@@ -96,10 +96,9 @@ public interface IItemGridHandler {
|
||||
* 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 id UUID of the GridStack that the mouse is hovering over or null
|
||||
* @param shift if true shift is pressed, if false 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);
|
||||
void onGridScroll(ServerPlayerEntity player, @Nullable UUID id, boolean shift, boolean up);
|
||||
}
|
||||
|
@@ -292,11 +292,11 @@ public class ItemGridHandler implements IItemGridHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGridScroll(ServerPlayerEntity player, UUID id, boolean shift, boolean ctrl, boolean up) {
|
||||
onGridScroll(this, player, id, shift, ctrl, up, network);
|
||||
public void onGridScroll(ServerPlayerEntity player, @Nullable UUID id, boolean shift, boolean up) {
|
||||
onGridScroll(this, player, id, shift, up, network);
|
||||
}
|
||||
|
||||
public static void onGridScroll(IItemGridHandler gridHandler, ServerPlayerEntity player, UUID id, boolean shift, boolean ctrl, boolean up, @Nullable INetwork network) {
|
||||
public static void onGridScroll(IItemGridHandler gridHandler, ServerPlayerEntity player, @Nullable UUID id, boolean shift, boolean up, @Nullable INetwork network) {
|
||||
if (player == null || !(player.openContainer instanceof GridContainer)) {
|
||||
return;
|
||||
}
|
||||
@@ -309,43 +309,30 @@ public class ItemGridHandler implements IItemGridHandler {
|
||||
|
||||
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) {
|
||||
gridHandler.onInsert(player, player.inventory.getStackInSlot(slot), true);
|
||||
return;
|
||||
}
|
||||
|
||||
} else { //scroll down, extract hovering item
|
||||
gridHandler.onExtract(player, id, -1, flags);
|
||||
if (shift && id != null) {
|
||||
flags |= EXTRACT_SHIFT;
|
||||
if (up) { //scroll up, insert hovering stack pulled from Inventory
|
||||
ItemStorageCache cache = (ItemStorageCache) grid.getStorageCache();
|
||||
if (cache == null || cache.getList().get(id) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
} else if (!shift && ctrl) { //ctrl
|
||||
if (!up) { //scroll down, extract hovering item
|
||||
gridHandler.onExtract(player, id, -1, flags);
|
||||
return;
|
||||
int slot = player.inventory.getSlotFor(cache.getList().get(id));
|
||||
if (slot != -1) {
|
||||
gridHandler.onInsert(player, player.inventory.getStackInSlot(slot), true);
|
||||
}
|
||||
|
||||
} else { //scroll down, extract hovering item
|
||||
gridHandler.onExtract(player, id, -1, flags);
|
||||
}
|
||||
}
|
||||
} else { //ctrl
|
||||
if (!up && id != null) { //scroll down, extract hovering item
|
||||
gridHandler.onExtract(player, id, -1, flags);
|
||||
|
||||
if (up) { //scroll up, insert item from cursor
|
||||
gridHandler.onInsert(player, player.inventory.getItemStack(), true);
|
||||
player.updateHeldItem();
|
||||
} else if (up && !player.inventory.getItemStack().isEmpty()) { // insert stack from cursor
|
||||
gridHandler.onInsert(player, player.inventory.getItemStack(), true);
|
||||
player.updateHeldItem();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -199,7 +199,7 @@ public class PortableItemGridHandler implements IItemGridHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGridScroll(ServerPlayerEntity player, UUID id, boolean shift, boolean ctrl, boolean up) {
|
||||
ItemGridHandler.onGridScroll(this, player, id, shift, ctrl, up, null);
|
||||
public void onGridScroll(ServerPlayerEntity player, @Nullable UUID id, boolean shift, boolean up) {
|
||||
ItemGridHandler.onGridScroll(this, player, id, shift, up, null);
|
||||
}
|
||||
}
|
||||
|
@@ -11,30 +11,32 @@ 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) {
|
||||
public GridItemGridScrollMessage(UUID id, boolean shift, 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());
|
||||
return new GridItemGridScrollMessage(buf.readBoolean() ? buf.readUniqueId() : null, buf.readBoolean(), buf.readBoolean());
|
||||
}
|
||||
|
||||
public static void encode(GridItemGridScrollMessage message, PacketBuffer buf) {
|
||||
buf.writeUniqueId(message.id);
|
||||
boolean hasId = message.id != null;
|
||||
buf.writeBoolean(hasId);
|
||||
if (hasId) {
|
||||
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);
|
||||
((GridContainer) ctx.get().getSender().openContainer).getGrid().getItemHandler().onGridScroll(ctx.get().getSender(), message.id, message.shift, message.up);
|
||||
}
|
||||
});
|
||||
ctx.get().setPacketHandled(true);
|
||||
|
@@ -44,7 +44,6 @@ 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 {
|
||||
@@ -472,12 +471,9 @@ public class GridScreen extends BaseScreen<GridContainer> implements IScreenInfo
|
||||
}
|
||||
|
||||
if (isOverSlotWithStack()) {
|
||||
boolean isMiddleClickPulling = !held.isEmpty() && clickedButton == 2;
|
||||
boolean isPulling = held.isEmpty() || isMiddleClickPulling;
|
||||
|
||||
IGridStack stack = view.getStacks().get(slotNumber);
|
||||
|
||||
if (isPulling) {
|
||||
if (held.isEmpty()) {
|
||||
if (view.canCraft() && stack.isCraftable()) {
|
||||
minecraft.displayGuiScreen(new CraftingSettingsScreen(this, playerInventory.player, stack));
|
||||
} else if (view.canCraft() && !stack.isCraftable() && stack.getOtherId() != null && hasShiftDown() && hasControlDown()) {
|
||||
@@ -495,10 +491,6 @@ public class GridScreen extends BaseScreen<GridContainer> implements IScreenInfo
|
||||
flags |= IItemGridHandler.EXTRACT_SHIFT;
|
||||
}
|
||||
|
||||
if (clickedButton == 2) {
|
||||
flags |= IItemGridHandler.EXTRACT_SINGLE;
|
||||
}
|
||||
|
||||
RS.NETWORK_HANDLER.sendToServer(new GridItemPullMessage(stack.getId(), flags));
|
||||
}
|
||||
}
|
||||
@@ -542,7 +534,7 @@ public class GridScreen extends BaseScreen<GridContainer> implements IScreenInfo
|
||||
}
|
||||
} 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));
|
||||
RS.NETWORK_HANDLER.sendToServer(new GridItemGridScrollMessage(isOverSlotWithStack() ? view.getStacks().get(slotNumber).getId() : null, hasShiftDown(), delta > 0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -607,7 +599,7 @@ public class GridScreen extends BaseScreen<GridContainer> implements IScreenInfo
|
||||
}
|
||||
|
||||
public boolean canSort() {
|
||||
return doSort || !hasShiftDown();
|
||||
return doSort || !hasShiftDown() && !hasControlDown();
|
||||
}
|
||||
|
||||
public static List<IGridSorter> getSorters() {
|
||||
|
Reference in New Issue
Block a user