@Override
  public ItemStack slotClick(int id, int button, ClickType clickType, EntityPlayer player) {
    Slot slot = id < 0 ? null : this.inventorySlots.get(id);
    if (!(slot instanceof IESlot.Ghost)) return super.slotClick(id, button, clickType, player);
    // Spooky Ghost Slots!!!!
    ItemStack stack = null;
    ItemStack stackSlot = slot.getStack();
    if (stackSlot != null) stack = stackSlot.copy();

    if (button == 2) slot.putStack(null);
    else if (button == 0 || button == 1) {
      InventoryPlayer playerInv = player.inventory;
      ItemStack stackHeld = playerInv.getItemStack();
      if (stackSlot == null) {
        if (stackHeld != null && slot.isItemValid(stackHeld)) {
          slot.putStack(Utils.copyStackWithAmount(stackHeld, 1));
        }
      } else if (stackHeld == null) {
        slot.putStack(null);
      } else if (slot.isItemValid(stackHeld)) {
        slot.putStack(Utils.copyStackWithAmount(stackHeld, 1));
      }
    } else if (button == 5) {
      InventoryPlayer playerInv = player.inventory;
      ItemStack stackHeld = playerInv.getItemStack();
      if (!slot.getHasStack()) {
        slot.putStack(Utils.copyStackWithAmount(stackHeld, 1));
      }
    }
    return stack;
  }
 private ItemStack slotClickPhantom(
     Slot slot, int mouseButton, int modifier, EntityPlayer player) {
   ItemStack stack = null;
   if (mouseButton == 2) {
     if (((IPhantomSlot) slot).canAdjust()) slot.putStack(null);
   } else if (mouseButton == 0 || mouseButton == 1) {
     InventoryPlayer playerInv = player.inventory;
     slot.onSlotChanged();
     ItemStack stackSlot = slot.getStack();
     ItemStack stackHeld = playerInv.getItemStack();
     if (stackSlot != null) stack = stackSlot.copy();
     if (stackSlot == null) {
       if (stackHeld != null && slot.isItemValid(stackHeld))
         fillPhantomSlot(slot, stackHeld, mouseButton);
     } else if (stackHeld == null) {
       adjustPhantomSlot(slot, mouseButton, modifier);
       slot.onPickupFromSlot(player, playerInv.getItemStack());
     } else if (slot.isItemValid(stackHeld)) {
       if (ItemUtil.canStacksMerge(stackSlot, stackHeld))
         adjustPhantomSlot(slot, mouseButton, modifier);
       else fillPhantomSlot(slot, stackHeld, mouseButton);
     }
   }
   return stack;
 }
Esempio n. 3
0
  /** Callback for when the crafting gui is closed. */
  public void onCraftGuiClosed(EntityPlayer par1EntityPlayer) {
    InventoryPlayer var2 = par1EntityPlayer.inventory;

    if (var2.getItemStack() != null) {
      par1EntityPlayer.dropPlayerItem(var2.getItemStack());
      var2.setItemStack((ItemStack) null);
    }
  }
Esempio n. 4
0
  public ItemStack handle(EntityPlayer player, int mouseButton, Slot slot) {
    if (mouseButton > 0) {
      slot.putStack(null);
    } else if (mouseButton == 0) {
      ItemStack stack;
      InventoryPlayer playerInv = player.inventory;
      slot.onSlotChanged();
      ItemStack stackSlot = slot.getStack();
      ItemStack stackHeld = playerInv.getItemStack();

      if (stackSlot == null && stackHeld != null && slot.slotNumber != 22) {
        if (isItemValid(stackHeld)) {
          ItemStack copy = stackHeld.copy();
          copy.stackSize = 1;
          slot.putStack(copy);
        }
      }

      if (stackHeld == null) {
        if (tile instanceof TileFishSorter) {
          ((TileFishSorter) tile).swapSide(slot.slotNumber);
        }
      }
    }

    return null;
  }
Esempio n. 5
0
  public ItemStack slotClick(int par1, int par2, int par3, EntityPlayer par4EntityPlayer) {
    ItemStack var5 = null;
    InventoryPlayer var6 = par4EntityPlayer.inventory;
    Slot var7;
    ItemStack var8;
    int var10;
    ItemStack var11;

    if ((par3 == 0 || par3 == 1) && (par2 == 0 || par2 == 1)) {
      if (par1 == -999) {
        if (var6.getItemStack() != null && par1 == -999) {
          if (par2 == 0) {
            par4EntityPlayer.dropPlayerItem(var6.getItemStack());
            var6.setItemStack((ItemStack) null);
          }

          if (par2 == 1) {
            // CraftBukkit start - store a reference
            ItemStack itemstack3 = var6.getItemStack();
            par4EntityPlayer.dropPlayerItem(itemstack3.splitStack(1));

            if (itemstack3.stackSize == 0) {
              // CraftBukkit end
              var6.setItemStack((ItemStack) null);
            }
          }
        }
      } else if (par3 == 1) {
        var7 = (Slot) this.inventorySlots.get(par1);

        if (var7 != null && var7.canTakeStack(par4EntityPlayer)) {
          var8 = this.transferStackInSlot(par4EntityPlayer, par1);

          if (var8 != null) {
            int var12 = var8.itemID;
            var5 = var8.copy();

            if (var7 != null && var7.getStack() != null && var7.getStack().itemID == var12) {
              this.retrySlotClick(par1, par2, true, par4EntityPlayer);
            }
          }
        }
      } else {
        if (par1 < 0) {
          return null;
        }

        var7 = (Slot) this.inventorySlots.get(par1);

        if (var7 != null) {
          var8 = var7.getStack();
          ItemStack var13 = var6.getItemStack();

          if (var8 != null) {
            var5 = var8.copy();
          }

          if (var8 == null) {
            if (var13 != null && var7.isItemValid(var13)) {
              var10 = par2 == 0 ? var13.stackSize : 1;

              if (var10 > var7.getSlotStackLimit()) {
                var10 = var7.getSlotStackLimit();
              }

              if (var13.stackSize >= var10) // CraftBukkit
              var7.putStack(var13.splitStack(var10));

              if (var13.stackSize == 0) {
                var6.setItemStack((ItemStack) null);
              }
            }
          } else if (var7.canTakeStack(par4EntityPlayer)) {
            if (var13 == null) {
              var10 = par2 == 0 ? var8.stackSize : (var8.stackSize + 1) / 2;
              var11 = var7.decrStackSize(var10);
              var6.setItemStack(var11);

              if (var8.stackSize == 0) {
                var7.putStack((ItemStack) null);
              }

              var7.onPickupFromSlot(par4EntityPlayer, var6.getItemStack());
            } else if (var7.isItemValid(var13)) {
              if (var8.itemID == var13.itemID
                  && var8.getItemDamage() == var13.getItemDamage()
                  && ItemStack.areItemStackTagsEqual(var8, var13)) {
                var10 = par2 == 0 ? var13.stackSize : 1;

                if (var10 > var7.getSlotStackLimit() - var8.stackSize) {
                  var10 = var7.getSlotStackLimit() - var8.stackSize;
                }

                if (var10 > var13.getMaxStackSize() - var8.stackSize) {
                  var10 = var13.getMaxStackSize() - var8.stackSize;
                }

                var13.splitStack(var10);

                if (var13.stackSize == 0) {
                  var6.setItemStack((ItemStack) null);
                }

                var8.stackSize += var10;
              } else if (var13.stackSize <= var7.getSlotStackLimit()) {
                var7.putStack(var13);
                var6.setItemStack(var8);
              }
            } else if (var8.itemID == var13.itemID
                && var13.getMaxStackSize() > 1
                && (!var8.getHasSubtypes() || var8.getItemDamage() == var13.getItemDamage())
                && ItemStack.areItemStackTagsEqual(var8, var13)) {
              var10 = var8.stackSize;

              if (var10 > 0 && var10 + var13.stackSize <= var13.getMaxStackSize()) {
                var13.stackSize += var10;
                var8 = var7.decrStackSize(var10);

                if (var8.stackSize == 0) {
                  var7.putStack((ItemStack) null);
                }

                var7.onPickupFromSlot(par4EntityPlayer, var6.getItemStack());
              }
            }
          }

          var7.onSlotChanged();
        }
      }
    } else if (par3 == 2 && par2 >= 0 && par2 < 9) {
      var7 = (Slot) this.inventorySlots.get(par1);

      if (var7.canTakeStack(par4EntityPlayer)) {
        var8 = var6.getStackInSlot(par2);
        boolean var9 = var8 == null || var7.inventory == var6 && var7.isItemValid(var8);
        var10 = -1;

        if (!var9) {
          var10 = var6.getFirstEmptyStack();
          var9 |= var10 > -1;
        }

        if (var7.getHasStack() && var9) {
          var11 = var7.getStack();
          var6.setInventorySlotContents(par2, var11);

          if ((var7.inventory != var6 || !var7.isItemValid(var8)) && var8 != null) {
            if (var10 > -1) {
              var6.addItemStackToInventory(var8);
              var7.decrStackSize(var11.stackSize);
              var7.putStack((ItemStack) null);
              var7.onPickupFromSlot(par4EntityPlayer, var11);
            }
          } else {
            var7.decrStackSize(var11.stackSize);
            var7.putStack(var8);
            var7.onPickupFromSlot(par4EntityPlayer, var11);
          }
        } else if (!var7.getHasStack() && var8 != null && var7.isItemValid(var8)) {
          var6.setInventorySlotContents(par2, (ItemStack) null);
          var7.putStack(var8);
        }
      }
    } else if (par3 == 3
        && par4EntityPlayer.capabilities.isCreativeMode
        && var6.getItemStack() == null
        && par1 >= 0) {
      var7 = (Slot) this.inventorySlots.get(par1);

      if (var7 != null && var7.getHasStack()) {
        var8 = var7.getStack().copy();
        var8.stackSize = var8.getMaxStackSize();
        var6.setItemStack(var8);
      }
    }

    return var5;
  }