It is now possible to use middle click multiple times for the same item in grid, fixes #134

This commit is contained in:
Raoul Van den Berge
2016-07-01 19:36:09 +02:00
parent 7906edf91f
commit 785cd77b81
4 changed files with 25 additions and 7 deletions

View File

@@ -4,6 +4,9 @@
**Bugfixes** **Bugfixes**
- Fixed not being able to take items sometimes - Fixed not being able to take items sometimes
**Features**
- It is now possible to use middle click multiple times for the same item in grid
### 0.8.1 ### 0.8.1
**Bugfixes** **Bugfixes**
- Fixed upgrades from interface not dropping - Fixed upgrades from interface not dropping

View File

@@ -5,6 +5,6 @@ package refinedstorage.api.network;
*/ */
public class GridPullFlags { public class GridPullFlags {
public static final int PULL_HALF = 1; public static final int PULL_HALF = 1;
public static final int PULL_ONE = 2; public static final int PULL_SINGLE = 2;
public static final int PULL_SHIFT = 4; public static final int PULL_SHIFT = 4;
} }

View File

@@ -22,7 +22,15 @@ public class GridHandler implements IGridHandler {
@Override @Override
public void onPull(ItemStack stack, int flags, EntityPlayerMP player) { public void onPull(ItemStack stack, int flags, EntityPlayerMP player) {
if (player.inventory.getItemStack() != null) { boolean single = (flags & GridPullFlags.PULL_SINGLE) == GridPullFlags.PULL_SINGLE;
ItemStack held = player.inventory.getItemStack();
if (single) {
if (held != null && (!RefinedStorageUtils.compareStackNoQuantity(stack, held) || held.stackSize + 1 > held.getMaxStackSize())) {
return;
}
} else if (player.inventory.getItemStack() != null) {
return; return;
} }
@@ -34,7 +42,7 @@ public class GridHandler implements IGridHandler {
if (size > 32) { if (size > 32) {
size = 32; size = 32;
} }
} else if ((flags & GridPullFlags.PULL_ONE) == GridPullFlags.PULL_ONE) { } else if (single) {
size = 1; size = 1;
} else if ((flags & GridPullFlags.PULL_SHIFT) == GridPullFlags.PULL_SHIFT) { } else if ((flags & GridPullFlags.PULL_SHIFT) == GridPullFlags.PULL_SHIFT) {
// NO OP, the quantity already set (64) is needed for shift // NO OP, the quantity already set (64) is needed for shift
@@ -49,8 +57,13 @@ public class GridHandler implements IGridHandler {
if (!player.inventory.addItemStackToInventory(took.copy())) { if (!player.inventory.addItemStackToInventory(took.copy())) {
InventoryHelper.spawnItemStack(player.worldObj, player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), took); InventoryHelper.spawnItemStack(player.worldObj, player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), took);
} }
} else {
if (held != null) {
held.stackSize++;
} else { } else {
player.inventory.setItemStack(took); player.inventory.setItemStack(took);
}
player.updateHeldItem(); player.updateHeldItem();
} }

View File

@@ -357,11 +357,13 @@ public class GuiGrid extends GuiBase {
RefinedStorage.NETWORK.sendToServer(new MessageGridCraftingClear((TileGrid) grid)); RefinedStorage.NETWORK.sendToServer(new MessageGridCraftingClear((TileGrid) grid));
} }
if (isOverSlotArea(mouseX - guiLeft, mouseY - guiTop) && container.getPlayer().inventory.getItemStack() != null && (clickedButton == 0 || clickedButton == 1)) { ItemStack held = container.getPlayer().inventory.getItemStack();
if (isOverSlotArea(mouseX - guiLeft, mouseY - guiTop) && held != null && (clickedButton == 0 || clickedButton == 1)) {
RefinedStorage.NETWORK.sendToServer(new MessageGridHeldPush(clickedButton == 1)); RefinedStorage.NETWORK.sendToServer(new MessageGridHeldPush(clickedButton == 1));
} }
if (isOverSlotWithItem() && container.getPlayer().inventory.getItemStack() == null) { if (isOverSlotWithItem() && (held == null || (held != null && clickedButton == 2))) {
if (items.get(slotNumber).stackSize == 0 || (GuiScreen.isShiftKeyDown() && GuiScreen.isCtrlKeyDown())) { if (items.get(slotNumber).stackSize == 0 || (GuiScreen.isShiftKeyDown() && GuiScreen.isCtrlKeyDown())) {
FMLCommonHandler.instance().showGuiScreen(new GuiCraftingSettings(this, container.getPlayer(), items.get(slotNumber))); FMLCommonHandler.instance().showGuiScreen(new GuiCraftingSettings(this, container.getPlayer(), items.get(slotNumber)));
} else { } else {
@@ -376,7 +378,7 @@ public class GuiGrid extends GuiBase {
} }
if (clickedButton == 2) { if (clickedButton == 2) {
flags |= GridPullFlags.PULL_ONE; flags |= GridPullFlags.PULL_SINGLE;
} }
RefinedStorage.NETWORK.sendToServer(new MessageGridPull(items.get(slotNumber), flags)); RefinedStorage.NETWORK.sendToServer(new MessageGridPull(items.get(slotNumber), flags));