Package org.spoutcraft.api.inventory

Examples of org.spoutcraft.api.inventory.ItemStack


  }

  public int first(int materialId) {
    ItemStack[] inventory = getContents();
    for (int i = 0; i < inventory.length; i++) {
      ItemStack item = inventory[i];
      if (item != null && item.getTypeId() == materialId) {
        return i;
      }
    }
    return -1;
  }
View Full Code Here


  }

  public int firstPartial(int materialId) {
    ItemStack[] inventory = getContents();
    for (int i = 0; i < inventory.length; i++) {
      ItemStack item = inventory[i];
      if (item != null && item.getTypeId() == materialId && item.getAmount() < item.getMaxStackSize()) {
        return i;
      }
    }
    return -1;
  }
View Full Code Here

    ItemStack[] inventory = getContents();
    if (item == null) {
      return -1;
    }
    for (int i = 0; i < inventory.length; i++) {
      ItemStack cItem = inventory[i];
      if (cItem != null && cItem.getTypeId() == item.getTypeId() && cItem.getAmount() < cItem.getMaxStackSize() && cItem.getDurability() == item.getDurability()) {
        return i;
      }
    }
    return -1;
  }
View Full Code Here

     *  - Record the lastPartial per Material
     *  - Cache firstEmpty result
     */

    for (int i = 0; i < items.length; i++) {
      ItemStack item = items[i];
      while (true) {
        // Do we already have a stack of it?
        int firstPartial = firstPartial(item);

        // Drat! no partial stack
        if (firstPartial == -1) {
          // Find a free spot!
          int firstFree = firstEmpty();

          if (firstFree == -1) {
            // No space at all!
            leftover.put(i, item);
            break;
          } else {
            // More than a single stack!
            if (item.getAmount() > getMaxItemStack()) {
              setItem(firstFree, new CraftItemStack(item.getTypeId(), getMaxItemStack(), item.getDurability()));
              item.setAmount(item.getAmount() - getMaxItemStack());
            } else {
              // Just store it
              setItem(firstFree, item);
              break;
            }
          }
        } else {
          // So, apparently it might only partially fit, well lets do just that
          ItemStack partialItem = getItem(firstPartial);

          int amount = item.getAmount();
          int partialAmount = partialItem.getAmount();
          int maxAmount = partialItem.getMaxStackSize();

          // Check if it fully fits
          if (amount + partialAmount <= maxAmount) {
            partialItem.setAmount(amount + partialAmount);
            break;
          }

          // It fits partially
          partialItem.setAmount(maxAmount);
          item.setAmount(amount + partialAmount - maxAmount);
        }
      }
    }
    return leftover;
View Full Code Here

    HashMap<Integer, ItemStack> leftover = new HashMap<Integer, ItemStack>();

    // TODO Optimization

    for (int i = 0; i < items.length; i++) {
      ItemStack item = items[i];
      int toDelete = item.getAmount();

      while (true) {
        int first = first(item.getType());

        // Drat! we don't have this type in the inventory
        if (first == -1) {
          item.setAmount(toDelete);
          leftover.put(i, item);
          break;
        } else {
          ItemStack itemStack = getItem(first);
          int amount = itemStack.getAmount();

          if (amount <= toDelete) {
            toDelete -= amount;
            // clear the slot, all used up
            clear(first);
          } else {
            // split the stack and store
            itemStack.setAmount(amount - toDelete);
            setItem(first, itemStack);
            toDelete = 0;
          }
        }
View Full Code Here

    }
    return SpoutClient.getHandle().currentScreen.getScreen();
  }

  public ItemStack getItemStackOnCursor() {
    ItemStack ret = new ItemStack(0);
    if (SpoutClient.getHandle().thePlayer != null) {
      net.minecraft.src.ItemStack mcStack = SpoutClient.getHandle().thePlayer.inventory.getItemStack();
      if (mcStack != null) {
        ret = new ItemStack(mcStack.itemID, mcStack.stackSize, (short) mcStack.getItemDamage());
      }
    }
    return ret;
  }
View Full Code Here

  public void writeData(SpoutOutputStream output) throws IOException {
  }

  public void run(int playerId) {
    block.setItemDrop(new ItemStack(block, 1));
  }
View Full Code Here

      if (mc.thePlayer == null) {
        return;
      }
      PacketSlotClick packet = new PacketSlotClick(slot, button,Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT));
      SpoutClient.getInstance().getPacketManager().sendSpoutPacket(packet);
      ItemStack stackOnCursor = new ItemStack(0);
      if (mc.thePlayer.inventory.getItemStack() != null) {
        net.minecraft.src.ItemStack mcStack = mc.thePlayer.inventory.getItemStack();
        stackOnCursor = new ItemStack(mcStack.itemID, mcStack.stackSize, (short) mcStack.getItemDamage());
      }
      ItemStack stackInSlot = slot.getItem();
      if ((stackOnCursor == null || stackOnCursor.getTypeId() == 0) && stackInSlot.getTypeId() == 0) {
        return; // Nothing to do
      }
      if (stackOnCursor.getTypeId() == 0 && stackInSlot.getTypeId() != 0 && button == 1) { // Split item
        int amountSlot = stackInSlot.getAmount() / 2;
        int amountCursor = stackInSlot.getAmount() - amountSlot;
        if (stackInSlot.getAmount() == 1) {
          amountSlot = 0;
          amountCursor = 1;
        }
        stackOnCursor = stackInSlot.clone();
        stackOnCursor.setAmount(amountCursor);
        stackInSlot.setAmount(amountSlot);
        if (amountSlot == 0) {
          stackInSlot = new ItemStack(0);
        }
        boolean success = slot.onItemTake(stackOnCursor);
        if (success) {
          slot.setItem(stackInSlot);
        } else {
          return;
        }
      } else if (stackOnCursor != null && (stackInSlot.getTypeId() == 0 || (stackInSlot.getTypeId() == stackOnCursor.getTypeId() && stackInSlot.getDurability() == stackOnCursor.getDurability()))) { //Put item
        ItemStack toPut = stackOnCursor.clone();
        int putAmount = toPut.getAmount();
        if (button == 1) {
          putAmount = 1;
        }
        int amount = stackInSlot.getTypeId() == 0 ? 0 : stackInSlot.getAmount();
        amount += putAmount;
        int maxStackSize = toPut.getMaxStackSize();
        if (maxStackSize == -1) {
          maxStackSize = 64;
        }
        if (amount > maxStackSize) {
          putAmount -= amount - maxStackSize;
          amount = maxStackSize;
        }
        if (putAmount <= 0) {
          return;
        }
        toPut.setAmount(putAmount);
        boolean success = slot.onItemPut(toPut);
        if (success) {
          stackOnCursor.setAmount(stackOnCursor.getAmount() - putAmount);
          if (stackOnCursor.getAmount() == 0) {
            stackOnCursor = new ItemStack(0);
          }
          ItemStack put = toPut.clone();
          put.setAmount(amount);
          slot.setItem(put);
        }
      } else if (stackOnCursor == null || stackOnCursor.getTypeId() == 0) { // Take item or shift click
        if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) {
          slot.onItemShiftClicked();
        } else { // Take item
          boolean success = slot.onItemTake(stackInSlot);
          if (success) {
            stackOnCursor = stackInSlot;
            slot.setItem(new ItemStack(0));
          }
        }
      } else if (stackOnCursor.getTypeId() != stackInSlot.getTypeId() || stackOnCursor.getDurability() != stackInSlot.getDurability()) { // Exchange slot stack and cursor stack
        boolean success = slot.onItemExchange(stackInSlot, stackOnCursor.clone());
        if (success) {
View Full Code Here

TOP

Related Classes of org.spoutcraft.api.inventory.ItemStack

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.