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:
Darkere
2020-10-03 22:09:47 +02:00
committed by GitHub
parent a30205a541
commit 17b153d8b5
5 changed files with 38 additions and 58 deletions

View File

@@ -96,10 +96,9 @@ public interface IItemGridHandler {
* Called when a player shift or ctrl scrolls in the Grid View * Called when a player shift or ctrl scrolls in the Grid View
* *
* @param player player that is scrolling * @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 id UUID of the GridStack that the mouse is hovering over or null
* @param shift true if shift is pressed * @param shift if true shift is pressed, if false ctrl is pressed
* @param ctrl true if ctrl is pressed
* @param up whether the player is scrolling up or down * @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);
} }

View File

@@ -292,11 +292,11 @@ public class ItemGridHandler implements IItemGridHandler {
} }
@Override @Override
public void onGridScroll(ServerPlayerEntity player, UUID id, boolean shift, boolean ctrl, boolean up) { public void onGridScroll(ServerPlayerEntity player, @Nullable UUID id, boolean shift, boolean up) {
onGridScroll(this, player, id, shift, ctrl, up, network); 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)) { if (player == null || !(player.openContainer instanceof GridContainer)) {
return; return;
} }
@@ -309,43 +309,30 @@ public class ItemGridHandler implements IItemGridHandler {
int flags = EXTRACT_SINGLE; int flags = EXTRACT_SINGLE;
if (!id.equals(new UUID(0, 0))) { //isOverStack if (shift && id != null) {
if (shift && !ctrl) { //shift flags |= EXTRACT_SHIFT;
flags |= EXTRACT_SHIFT; if (up) { //scroll up, insert hovering stack pulled from Inventory
ItemStorageCache cache = (ItemStorageCache) grid.getStorageCache();
if (up) { //scroll up, insert hovering stack pulled from Inventory if (cache == null || cache.getList().get(id) == null) {
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);
return; return;
} }
} else if (!shift && ctrl) { //ctrl int slot = player.inventory.getSlotFor(cache.getList().get(id));
if (!up) { //scroll down, extract hovering item if (slot != -1) {
gridHandler.onExtract(player, id, -1, flags); gridHandler.onInsert(player, player.inventory.getStackInSlot(slot), true);
return;
} }
} 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 } else if (up && !player.inventory.getItemStack().isEmpty()) { // insert stack from cursor
gridHandler.onInsert(player, player.inventory.getItemStack(), true); gridHandler.onInsert(player, player.inventory.getItemStack(), true);
player.updateHeldItem(); player.updateHeldItem();
}
} }
} }
} }

View File

@@ -199,7 +199,7 @@ public class PortableItemGridHandler implements IItemGridHandler {
} }
@Override @Override
public void onGridScroll(ServerPlayerEntity player, UUID id, boolean shift, boolean ctrl, boolean up) { public void onGridScroll(ServerPlayerEntity player, @Nullable UUID id, boolean shift, boolean up) {
ItemGridHandler.onGridScroll(this, player, id, shift, ctrl, up, null); ItemGridHandler.onGridScroll(this, player, id, shift, up, null);
} }
} }

View File

@@ -11,30 +11,32 @@ public class GridItemGridScrollMessage {
private final UUID id; private final UUID id;
private final boolean shift; private final boolean shift;
private final boolean up; 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.id = id;
this.shift = shift; this.shift = shift;
this.ctrl = ctrl;
this.up = up; this.up = up;
} }
public static GridItemGridScrollMessage decode(PacketBuffer buf) { 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) { 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.shift);
buf.writeBoolean(message.ctrl);
buf.writeBoolean(message.up); buf.writeBoolean(message.up);
} }
public static void handle(GridItemGridScrollMessage message, Supplier<NetworkEvent.Context> ctx) { public static void handle(GridItemGridScrollMessage message, Supplier<NetworkEvent.Context> ctx) {
ctx.get().enqueueWork(() -> { ctx.get().enqueueWork(() -> {
if (ctx.get().getSender() != null && ctx.get().getSender().openContainer instanceof GridContainer) { 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); ctx.get().setPacketHandled(true);

View File

@@ -44,7 +44,6 @@ import yalter.mousetweaks.api.MouseTweaksDisableWheelTweak;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.UUID;
@MouseTweaksDisableWheelTweak @MouseTweaksDisableWheelTweak
public class GridScreen extends BaseScreen<GridContainer> implements IScreenInfoProvider { public class GridScreen extends BaseScreen<GridContainer> implements IScreenInfoProvider {
@@ -472,12 +471,9 @@ public class GridScreen extends BaseScreen<GridContainer> implements IScreenInfo
} }
if (isOverSlotWithStack()) { if (isOverSlotWithStack()) {
boolean isMiddleClickPulling = !held.isEmpty() && clickedButton == 2;
boolean isPulling = held.isEmpty() || isMiddleClickPulling;
IGridStack stack = view.getStacks().get(slotNumber); IGridStack stack = view.getStacks().get(slotNumber);
if (isPulling) { if (held.isEmpty()) {
if (view.canCraft() && stack.isCraftable()) { if (view.canCraft() && stack.isCraftable()) {
minecraft.displayGuiScreen(new CraftingSettingsScreen(this, playerInventory.player, stack)); minecraft.displayGuiScreen(new CraftingSettingsScreen(this, playerInventory.player, stack));
} else if (view.canCraft() && !stack.isCraftable() && stack.getOtherId() != null && hasShiftDown() && hasControlDown()) { } 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; flags |= IItemGridHandler.EXTRACT_SHIFT;
} }
if (clickedButton == 2) {
flags |= IItemGridHandler.EXTRACT_SINGLE;
}
RS.NETWORK_HANDLER.sendToServer(new GridItemPullMessage(stack.getId(), flags)); 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)) { } else if (isOverSlotArea(x - guiLeft, y - guiTop)) {
if (grid.getGridType() != GridType.FLUID) { 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() { public boolean canSort() {
return doSort || !hasShiftDown(); return doSort || !hasShiftDown() && !hasControlDown();
} }
public static List<IGridSorter> getSorters() { public static List<IGridSorter> getSorters() {