Package org.spout.api.inventory

Examples of org.spout.api.inventory.Inventory


  @Override
  public boolean onDestroy(Block block, Cause<?> cause) {
    Block input = block.translate(this.getFacing(block).getOpposite());
    if (input.getMaterial().isMaterial(inputs)) {
      Inventory inventory = input.getType(Container.class).getInventory();
      ComparableViewer cViewer = null;
      for (InventoryViewer viewer : inventory.getViewers()) {
        if (viewer instanceof ComparableViewer) {
          cViewer = (ComparableViewer) viewer;
        }
      }
      if (cViewer != null) {
View Full Code Here


  }

  private short getInputAStrength(Block block) {
    Block input = block.translate(this.getFacing(block).getOpposite());
    if (input.getMaterial().isMaterial(inputs)) {
      Inventory inv = input.getType(Container.class).getInventory();
      ComparableViewer view = null;
      for (InventoryViewer viewer : inv.getViewers()) {
        if (viewer instanceof ComparableViewer) {
          view = (ComparableViewer) viewer;
        }
      }
      if (view != null) {
View Full Code Here

  public void onPlacement(Block block, short data, BlockFace against, Vector3f clickedPos, boolean isClickedBlock, Cause<?> cause) {
    super.onPlacement(block, data, against, clickedPos, isClickedBlock, cause);
    this.setFacing(block, PlayerUtil.getFacing(cause));
    Block input = block.translate(this.getFacing(block).getOpposite());
    if (input.getMaterial().isMaterial(inputs)) {
      Inventory inventory = input.getType(Container.class).getInventory();
      boolean viewed = false;
      for (InventoryViewer viewer : inventory.getViewers()) {
        if (viewer instanceof ComparableViewer) {
          viewed = true;
          ((ComparableViewer) viewer).addViewer(block);
          break;
        }
      }
      if (!viewed) {
        inventory.addViewer(new ComparableViewer(block, inventory));
      }
    }
  }
View Full Code Here

      }
    }

    // Transferring to the main inventory, top to bottom
    if (!(from instanceof PlayerMainInventory)) {
      final Inventory main = inventory.getMain();
      for (int row = PlayerMainInventory.HEIGHT - 1; row >= 0; row--) {
        int startSlot = PlayerMainInventory.LENGTH * row;
        int endSlot = startSlot + PlayerMainInventory.LENGTH - 1;
        main.add(startSlot, endSlot, stack);
        from.set(slot, stack);
        if (stack.isEmpty()) {
          return true;
        }
      }
View Full Code Here

    return false;
  }

  private boolean handleClick(ClickArguments args) {
    Slot s = args.getSlot();
    Inventory inventory = s.getInventory();
    int slot = s.getIndex();
    // First check if we have a situtation where s's inventory is null
    switch (args.getAction()) {
      case START_LEFT_PAINT:
        if (paintType != NOPAINT || cursorItem == null) {
          resetPaint();
          return false;
        }
        debug("[Window] Beginning left paint");
        paintType = LEFTPAINT;
        painting = cursorItem.clone();
        return true;
      case START_RIGHT_PAINT:
        if (paintType != NOPAINT || cursorItem == null) {
          resetPaint();
          return false;
        }
        debug("[Window] Beginning right paint");
        paintType = RIGHTPAINT;
        painting = cursorItem.clone();
        return true;
      case LEFT_PAINT_PROGRESS:
        if (paintType != LEFTPAINT || cursorItem == null) {
          resetPaint();
          return false;
        }
        if (paintedSlotSet.size() == painting.getAmount()) {// Can't split item anymore
          return false;
        }
        debug("[Window] Progessing left paint");
        if (s.get() != null) {
          if (!s.get().equalsIgnoreSize(painting)) {// Materials don't match
            return false;
          }
          if (s.get().getAmount() >= s.get().getMaxStackSize()) {// Can't stack anymore
            return true;
          }
        }
        paintedSlotSet.add(s);
        return true;
      case RIGHT_PAINT_PROGRESS:
        if (paintType != RIGHTPAINT || cursorItem == null) {
          resetPaint();
          return false;
        }
        if (paintedSlotSet.size() == painting.getAmount()) {// Can't split item anymore
          return false;
        }
        debug("[Window] Progessing right paint");
        if (s.get() != null) {
          if (!s.get().equalsIgnoreSize(painting)) {// Materials don't match
            return false;
          }
          if (s.get().getAmount() >= s.get().getMaxStackSize()) {// Can't stack anymore
            return true;
          }
        }
        paintedSlotSet.add(s);
        return true;
      case END_LEFT_PAINT:
        if (paintType != LEFTPAINT || cursorItem == null) {
          resetPaint();
          return false;
        }
        debug("[Window] Ending left paint");
        final int divide = painting.getAmount() / paintedSlotSet.size();
        int extra = 0;
        for (Slot pSlot : paintedSlotSet) {
          int newSize = (pSlot.get() == null ? 0 : pSlot.get().getAmount()) + divide;
          if (newSize > painting.getMaxStackSize()) {
            extra += painting.getMaxStackSize() - newSize;
            newSize = painting.getMaxStackSize();
          }
          pSlot.set(painting.clone().setAmount(newSize));
        }
        cursorItem.setAmount(extra + (painting.getAmount() % paintedSlotSet.size()));
        resetPaint();
        return true;
      case END_RIGHT_PAINT:
        if (paintType != RIGHTPAINT || cursorItem == null) {
          resetPaint();
          return false;
        }
        debug("[Window] Ending right paint");
        for (Slot pSlot : paintedSlotSet) {
          int newSize = (pSlot.get() == null ? 0 : pSlot.get().getAmount()) + 1;
          pSlot.set(painting.clone().setAmount(newSize));
        }
        cursorItem.setAmount(cursorItem.getAmount() - paintedSlotSet.size());
        resetPaint();
        return true;
    }
    ItemStack clicked = s.get();
    if (args.isShiftClick()) {
      debug("[Window] Shift-Clicked slot " + slot);
      if (clicked != null) {
        return onShiftClick(clicked, slot, inventory);
      } else {
        return true;
      }
    }
    switch (args.getAction()) {
      case RIGHT_CLICK:
        debug("[Window - " + title + "] Right-Clicked slot " + slot + " using Cursor: " + cursorItem);
        debug("[Window] Item at clicked slot: " + (clicked == null ? "Empty" : clicked.getMaterial().getName()));
        if (clicked == null) {
          if (cursorItem != null) {
            debug("[Window] Add one");
            // slot is empty with a not empty cursor
            // add one
            clicked = cursorItem.clone();
            clicked.setAmount(1);
            // Can it be set?
            if (canSet(inventory, slot, clicked)) {
              inventory.set(slot, clicked);
              // remove from cursor
              cursorItem.setAmount(cursorItem.getAmount() - 1);
              if (cursorItem.isEmpty()) {
                cursorItem = null;
              }
              return true;
            }
          }
        } else if (cursorItem != null) {
          // slot is not empty with not empty cursor
          if (cursorItem.equalsIgnoreSize(clicked)) {
            // only stack materials that are the same
            if (clicked.getMaxStackSize() > clicked.getAmount()) {
              debug("[Window] Stacking");
              // add one if can fit
              clicked.setAmount(clicked.getAmount() + 1);
              if (canSet(inventory, slot, clicked)) {
                inventory.set(slot, clicked);
                cursorItem.setAmount(cursorItem.getAmount() - 1);
                if (cursorItem.isEmpty()) {
                  cursorItem = null;
                }
                return true;
              } else {
                //Crafting result slot?
                //Reset state
                clicked.setAmount(clicked.getAmount() - 1);
                cursorItem.stack(clicked);
                if (clicked.isEmpty()) {
                  clicked = null;
                  inventory.set(slot, null, true); //will trigger crafting table to create new result if possible
                } else {
                  inventory.set(slot, clicked, false);//will not trigger crafting table to create new result (some result still left in slot)
                }
              }
            }
          } else {
            // Can it be set?
            if (canSet(inventory, slot, cursorItem)) {
              debug("[Window] Materials don't match. Swapping stacks.");
              // materials don't match
              // swap stacks
              ItemStack newCursor = clicked.clone();
              inventory.set(slot, cursorItem);
              cursorItem = newCursor;
              return true;
            }
          }
        } else {
          // slot is not empty with an empty cursor
          // split the stack
          int x = clicked.getAmount();
          int y = x / 2;
          int z = x % 2;
          clicked.setAmount(y);
          inventory.set(slot, clicked);
          // cursor gets any remainder
          cursorItem = clicked.clone();
          cursorItem.setAmount(y + z);
        }
        return true;
      case LEFT_CLICK:
        debug("[Window - " + title + "] Left-Clicked slot " + slot + " using Cursor: " + cursorItem);
        debug("[Window] Item at clicked slot: " + (clicked == null ? "Empty" : clicked.getMaterial().getName()));
        if (clicked == null) {
          if (cursorItem != null) {
            debug("[Window] Put whole stack in slot");
            // slot is empty; cursor is not empty.
            // put whole stack down
            clicked = cursorItem.clone();
            // Can it be set?
            if (canSet(inventory, slot, clicked)) {
              inventory.set(slot, clicked);
              cursorItem = null;
              return true;
            }
          }
        } else if (cursorItem != null) {
          // slot is not empty; cursor is not empty.
          // stack
          if (cursorItem.equalsIgnoreSize(clicked)) {
            debug("[Window] Stacking");
            //Try to set items
            if (canSet(inventory, slot, clicked)) {
              clicked.stack(cursorItem);
              inventory.set(slot, clicked);
              if (cursorItem.isEmpty()) {
                cursorItem = null;
              }
              //Else try to pick them up (crafting)
            } else {
              cursorItem.stack(clicked);
              if (clicked.isEmpty()) {
                clicked = null;
                inventory.set(slot, null, true);//will trigger crafting table to create new result if possible
              } else {
                inventory.set(slot, clicked, false);//will not trigger crafting table to create new result (some result still left in slot)
              }
            }
            return true;
          } else {
            // Can it be set?
            if (canSet(inventory, slot, clicked)) {
              debug("[Window] Materials don't match. Swapping stacks.");
              // materials don't match
              // swap stacks
              ItemStack newCursor = clicked.clone();
              inventory.set(slot, cursorItem);
              cursorItem = newCursor;
            }
          }
        } else {
          // slot is not empty; cursor is empty.
          // pick up stack
          cursorItem = clicked.clone();
          inventory.set(slot, null);
        }
        return true;
      case DOUBLE_CLICK:
        if (cursorItem == null || cursorItem.getAmount() >= cursorItem.getMaxStackSize()) {
          return true;
View Full Code Here

  }

  @Override
  public boolean onDestroy(Block block, Cause<?> cause) {
    Chest c = block.get(Chest.class);
    Inventory inventory;
    if (c != null) {
      inventory = c.getInventory();
    } else {
      return false;
    }
View Full Code Here

    return getOtherHalf(block) != null;
  }

  @Override
  public boolean onDestroy(Block block, Cause<?> cause) {
    Inventory inventory = block.get(Chest.class).getInventory();
    boolean shouldD = super.onDestroy(block, cause);
    if (shouldD) {
      Point position = block.getPosition();
      for (ItemStack item : inventory) {
        if (item == null) {
View Full Code Here

    final PlayerInventory inventory = getPlayerInventory();

    // From main inventory/quickbar to the dispenser
    if (from instanceof PlayerMainInventory || from instanceof PlayerQuickbar) {
      for (InventoryConverter conv : this.getInventoryConverters()) {
        Inventory inv = conv.getInventory();
        if (inv instanceof DropperInventory) {
          Grid grid = inv.grid(3);
          final int height = grid.getHeight();
          final int length = grid.getLength();
          for (int y = height - 1; y >= 0; y--) {
            int x1 = length * y;
            int x2 = x1 + length - 1;
            inv.add(x1, x2, stack);
            from.set(slot, stack);
            if (stack.isEmpty()) {
              return true;
            }
          }
        }
      }
    }

    // From chest to inventory/quickbar
    if (from instanceof DropperInventory) {
      // To quickbar (reversed)
      final QuickbarInventory qbar = inventory.getQuickbar();
      qbar.add(qbar.size() - 1, 0, stack);
      from.set(slot, stack);
      if (stack.isEmpty()) {
        return true;
      }

      // To main inventory (reversed)
      final Inventory main = inventory.getMain();
      final int height = 3;
      final int length = 9;
      for (int y = 0; y < height; y++) {
        int x1 = length * y;
        int x2 = x1 + length - 1;
        main.add(x2, x1, stack);
        from.set(slot, stack);
        if (stack.isEmpty()) {
          return true;
        }
      }
View Full Code Here

    final PlayerInventory inventory = getPlayerInventory();

    // From main inventory/quickbar to the dispenser
    if (from instanceof PlayerMainInventory || from instanceof QuickbarInventory) {
      for (InventoryConverter conv : this.getInventoryConverters()) {
        Inventory inv = conv.getInventory();
        if (inv instanceof DispenserInventory) {
          Grid grid = inv.grid(3);
          final int height = grid.getHeight();
          final int length = grid.getLength();
          for (int row = height - 1; row >= 0; row--) {
            int startSlot = length * row;
            int endSlot = startSlot + length - 1;
            inv.add(startSlot, endSlot, stack);
            from.set(slot, stack);
            if (stack.isEmpty()) {
              return true;
            }
          }
        }
      }
    }

    // From chest to inventory/quickbar
    if (from instanceof DispenserInventory) {
      // To quickbar (reversed)
      final QuickbarInventory qbar = inventory.getQuickbar();
      qbar.add(qbar.size() - 1, 0, stack);
      from.set(slot, stack);
      if (stack.isEmpty()) {
        return true;
      }

      // To main inventory (reversed)
      final Inventory main = inventory.getMain();
      for (int row = 0; row < PlayerMainInventory.HEIGHT; row++) {
        int startSlot = PlayerMainInventory.LENGTH * row;
        int endSlot = startSlot + PlayerMainInventory.LENGTH - 1;
        main.add(endSlot, startSlot, stack);
        from.set(slot, stack);
        if (stack.isEmpty()) {
          return true;
        }
      }
View Full Code Here

    final PlayerInventory inventory = getPlayerInventory();

    // From main inventory/quickbar to the chest
    if (from instanceof PlayerMainInventory || from instanceof PlayerQuickbar) {
      for (InventoryConverter conv : this.getInventoryConverters()) {
        Inventory inv = conv.getInventory();
        if (inv instanceof ChestInventory) {
          Grid grid = inv.grid(ChestInventory.LENGTH);
          for (int row = grid.getHeight() - 1; row >= 0; row--) {
            int startSlot = ChestInventory.LENGTH * row;
            int endSlot = startSlot + ChestInventory.LENGTH - 1;
            inv.add(startSlot, endSlot, stack);
            from.set(slot, stack);
            if (stack.isEmpty()) {
              return true;
            }
          }
        }
      }
    }

    // From chest to inventory/quickbar
    if (from instanceof ChestInventory) {
      // To quickbar (reversed)
      final QuickbarInventory qbar = inventory.getQuickbar();
      qbar.add(qbar.size() - 1, 0, stack);
      from.set(slot, stack);
      if (stack.isEmpty()) {
        return true;
      }

      // To main inventory (reversed)
      final Inventory main = inventory.getMain();
      for (int row = 0; row < PlayerMainInventory.HEIGHT; row++) {
        int startSlot = PlayerMainInventory.LENGTH * row;
        int endSlot = startSlot + PlayerMainInventory.LENGTH - 1;
        main.add(endSlot, startSlot, stack);
        from.set(slot, stack);
        if (stack.isEmpty()) {
          return true;
        }
      }
View Full Code Here

TOP

Related Classes of org.spout.api.inventory.Inventory

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.