protected void fillPhantomSlot(Slot slot, ItemStack stackHeld, int mouseButton) {
   if (!((IPhantomSlot) slot).canAdjust()) return;
   int stackSize = mouseButton == 0 ? stackHeld.stackSize : 1;
   if (stackSize > slot.getSlotStackLimit()) stackSize = slot.getSlotStackLimit();
   ItemStack phantomStack = stackHeld.copy();
   phantomStack.stackSize = stackSize;
   slot.putStack(phantomStack);
 }
 protected void adjustPhantomSlot(Slot slot, int mouseButton, int modifier) {
   if (!((IPhantomSlot) slot).canAdjust()) return;
   ItemStack stackSlot = slot.getStack();
   int stackSize;
   if (modifier == 1)
     stackSize = mouseButton == 0 ? (stackSlot.stackSize + 1) / 2 : stackSlot.stackSize * 2;
   else stackSize = mouseButton == 0 ? stackSlot.stackSize - 1 : stackSlot.stackSize + 1;
   if (stackSize > slot.getSlotStackLimit()) stackSize = slot.getSlotStackLimit();
   stackSlot.stackSize = stackSize;
   if (stackSlot.stackSize <= 0) slot.putStack(null);
 }
  @Override
  protected boolean checkHotbarKeys(final int keyCode) {
    final Slot theSlot;

    try {
      theSlot =
          ObfuscationReflectionHelper.getPrivateValue(
              GuiContainer.class, this, "theSlot", "field_147006_u", "f");
    } catch (final Throwable t) {
      return false;
    }

    if (this.mc.thePlayer.inventory.getItemStack() == null && theSlot != null) {
      for (int j = 0; j < 9; ++j) {
        if (keyCode == this.mc.gameSettings.keyBindsHotbar[j].getKeyCode()) {
          final List<Slot> slots = this.getInventorySlots();
          for (final Slot s : slots) {
            if (s.getSlotIndex() == j
                && s.inventory == ((AEBaseContainer) this.inventorySlots).getPlayerInv()) {
              if (!s.canTakeStack(((AEBaseContainer) this.inventorySlots).getPlayerInv().player)) {
                return false;
              }
            }
          }

          if (theSlot.getSlotStackLimit() == 64) {
            this.handleMouseClick(theSlot, theSlot.slotNumber, j, 2);
            return true;
          } else {
            for (final Slot s : slots) {
              if (s.getSlotIndex() == j
                  && s.inventory == ((AEBaseContainer) this.inventorySlots).getPlayerInv()) {
                NetworkHandler.instance.sendToServer(
                    new PacketSwapSlots(s.slotNumber, theSlot.slotNumber));
                return true;
              }
            }
          }
        }
      }
    }

    return false;
  }
Exemplo n.º 4
0
  @Override
  protected boolean mergeItemStack(ItemStack is, int slotStart, int slotFinish, boolean par4) {
    boolean merged = false;
    int slotIndex = slotStart;

    if (par4) slotIndex = slotFinish - 1;

    Slot slot;
    ItemStack slotstack;

    if (is.isStackable()) {
      while (is.stackSize > 0
          && (!par4 && slotIndex < slotFinish || par4 && slotIndex >= slotStart)) {
        slot = (Slot) this.inventorySlots.get(slotIndex);
        slotstack = slot.getStack();

        if (slotstack != null
            && slotstack.getItem() == is.getItem()
            // && !is.getHasSubtypes()
            && is.getItemDamage() == slotstack.getItemDamage()
            && ItemStack.areItemStackTagsEqual(is, slotstack)
            && slotstack.stackSize < slot.getSlotStackLimit()) {
          int mergedStackSize =
              is.stackSize + getSmaller(slotstack.stackSize, slot.getSlotStackLimit());

          // First we check if we can add the two stacks together and the resulting stack is smaller
          // than the maximum size for the slot or the stack
          if (mergedStackSize <= is.getMaxStackSize()
              && mergedStackSize <= slot.getSlotStackLimit()) {
            is.stackSize = 0;
            slotstack.stackSize = mergedStackSize;
            slot.onSlotChanged();
            merged = true;
          } else if (slotstack.stackSize < is.getMaxStackSize()
              && slotstack.stackSize < slot.getSlotStackLimit()) {
            // Slot stack size is greater than or equal to the item's max stack size. Most
            // containers are this case.
            if (slot.getSlotStackLimit() >= is.getMaxStackSize()) {
              is.stackSize -= is.getMaxStackSize() - slotstack.stackSize;
              slotstack.stackSize = is.getMaxStackSize();
              slot.onSlotChanged();
              merged = true;
            }
            // Slot stack size is smaller than the item's normal max stack size. Example: Log Piles
            else if (slot.getSlotStackLimit() < is.getMaxStackSize()) {
              is.stackSize -= slot.getSlotStackLimit() - slotstack.stackSize;
              slotstack.stackSize = slot.getSlotStackLimit();
              slot.onSlotChanged();
              merged = true;
            }
          }
        }

        if (par4) --slotIndex;
        else ++slotIndex;
      }
    }

    if (is.stackSize > 0) {
      if (par4) slotIndex = slotFinish - 1;
      else slotIndex = slotStart;

      while (!par4 && slotIndex < slotFinish || par4 && slotIndex >= slotStart) {
        slot = (Slot) this.inventorySlots.get(slotIndex);
        slotstack = slot.getStack();
        if (slotstack == null && slot.isItemValid(is) && slot.getSlotStackLimit() < is.stackSize) {
          ItemStack copy = is.copy();
          copy.stackSize = slot.getSlotStackLimit();
          is.stackSize -= slot.getSlotStackLimit();
          slot.putStack(copy);
          slot.onSlotChanged();
          merged = true;
          // this.bagsSlotNum = slotIndex;
          break;
        } else if (slotstack == null && slot.isItemValid(is)) {
          slot.putStack(is.copy());
          slot.onSlotChanged();
          is.stackSize = 0;
          merged = true;
          break;
        }

        if (par4) --slotIndex;
        else ++slotIndex;
      }
    }

    return merged;
  }
Exemplo 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;
  }
  @Override
  protected boolean mergeItemStack(ItemStack stack, int start, int end, boolean backwards) {
    boolean flag1 = false;
    int k = (backwards ? end - 1 : start);
    Slot slot;
    ItemStack itemstack1;

    if (stack.isStackable()) {
      while (stack.stackSize > 0 && (!backwards && k < end || backwards && k >= start)) {
        slot = (Slot) inventorySlots.get(k);
        itemstack1 = slot.getStack();

        if (!slot.isItemValid(stack)) {
          continue;
        }

        if (itemstack1 != null
            && itemstack1.getItem() == stack.getItem()
            && (!stack.getHasSubtypes() || stack.getItemDamage() == itemstack1.getItemDamage())
            && ItemStack.areItemStackTagsEqual(stack, itemstack1)) {
          int l = itemstack1.stackSize + stack.stackSize;

          if (l <= stack.getMaxStackSize() && l <= slot.getSlotStackLimit()) {
            stack.stackSize = 0;
            itemstack1.stackSize = l;
            tileEntity.markDirty();
            flag1 = true;
          } else if (itemstack1.stackSize < stack.getMaxStackSize()
              && l < slot.getSlotStackLimit()) {
            stack.stackSize -= stack.getMaxStackSize() - itemstack1.stackSize;
            itemstack1.stackSize = stack.getMaxStackSize();
            tileEntity.markDirty();
            flag1 = true;
          }
        }

        k += (backwards ? -1 : 1);
      }
    }

    if (stack.stackSize > 0) {
      k = (backwards ? end - 1 : start);

      while (!backwards && k < end || backwards && k >= start) {
        slot = (Slot) inventorySlots.get(k);
        itemstack1 = slot.getStack();

        if (!slot.isItemValid(stack)) {
          continue;
        }

        if (itemstack1 == null) {
          int l = stack.stackSize;

          if (l <= slot.getSlotStackLimit()) {
            slot.putStack(stack.copy());
            stack.stackSize = 0;
            tileEntity.markDirty();
            flag1 = true;
            break;
          } else {
            putStackInSlot(
                k, new ItemStack(stack.getItem(), slot.getSlotStackLimit(), stack.getItemDamage()));
            stack.stackSize -= slot.getSlotStackLimit();
            tileEntity.markDirty();
            flag1 = true;
          }
        }

        k += (backwards ? -1 : 1);
      }
    }

    return flag1;
  }