Package org.spout.api.inventory

Examples of org.spout.api.inventory.Slot


  @Override
  public void onInteract(Entity entity, Block block, Action type, BlockFace face) {
    super.onInteract(entity, block, type, face);
    if (type == Action.RIGHT_CLICK) {
      Slot inv = PlayerUtil.getHeldSlot(entity);
      if (inv != null && !PlayerUtil.isCostSuppressed(entity)) {
        inv.set(new ItemStack(VanillaMaterials.BUCKET, 1));
      }
    }
  }
View Full Code Here


  }

  @Override
  public void onInteractBy(Entity entity, Block block, Action type, BlockFace clickedFace) {
    super.onInteractBy(entity, block, type, clickedFace);
    Slot inv = PlayerUtil.getHeldSlot(entity);
    if (inv != null && inv.get() != null && type.equals(Action.RIGHT_CLICK)) {
      if (grow(block, inv.get().getMaterial()) && !PlayerUtil.isCostSuppressed(entity)) {
        inv.addAmount(-1);
      }
    }
  }
View Full Code Here

  }

  @Override
  public void onInteractBy(Entity entity, Block block, Action type, BlockFace clickedFace) {
    super.onInteractBy(entity, block, type, clickedFace);
    Slot inv = PlayerUtil.getHeldSlot(entity);
    if (inv != null && inv.get() != null && type.equals(Action.RIGHT_CLICK)) {
      if (grow(block, inv.get().getMaterial()) && !PlayerUtil.isCostSuppressed(entity)) {
        inv.addAmount(-1);
      }
    }
  }
View Full Code Here

  public void onInteractBy(Entity entity, Block block, Action type, BlockFace clickedFace) {
    super.onInteractBy(entity, block, type, clickedFace);
    if (type != Action.RIGHT_CLICK) {
      return;
    }
    Slot inv = PlayerUtil.getHeldSlot(entity);
    if (inv != null && inv.get() != null && inv.get().isMaterial(Dye.BONE_MEAL)) {
      if (GenericMath.getRandom().nextDouble() < 0.45D && grow(block, inv.get().getMaterial()) && !PlayerUtil.isCostSuppressed(entity)) {
        inv.addAmount(-1);
      }
    }
  }
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;
        }
        debug("[Window] Combining similar materials.");
        for (int i = 0; i < getSize(); i++) {
          Slot spoutSlot = getSlot(i);
          ItemStack get = spoutSlot.get();
          if (get == null || get.getAmount() >= get.getMaxStackSize()) {
            continue;
          }
          if (cursorItem.stack(get)) {
            if (get.isEmpty()) {
              spoutSlot.set(null);
              if (cursorItem.getAmount() >= cursorItem.getMaxStackSize()) {// Done
                return true;
              }
            }
          }
View Full Code Here

  }

  @Override
  public Slot getSlot(int nativeSlot) {
    if (nativeSlot == 64537) {
      return new Slot(null, -999);
    }
    int slot;
    for (InventoryConverter converter : converters) {
      slot = converter.convert(nativeSlot);
      if (slot != -1) {
        return new Slot(converter.getInventory(), slot);
      }
    }
    debug("[MC=" + nativeSlot + "] -> Converted -> NOT FOUND!");
    return null;
  }
View Full Code Here

    return null;
  }

  @Override
  public ClickArguments getClickArguments(int nativeSlot, ClickArguments.ClickAction action) {
    Slot entry = getSlot(nativeSlot);
    if (entry != null) {
      return new ClickArguments(entry.getInventory(), entry.getIndex(), action);
    }
    return null;
  }
View Full Code Here

        case RIGHT_CLICK:
          final QuickbarInventory playerQuickbar = PlayerUtil.getQuickbar(player);
          if (playerQuickbar == null) {
            return;
          }
          final Slot selected = playerQuickbar.getSelectedSlot();
          if (selected.get() != null && selected.get().equalsIgnoreSize(new ItemStack(VanillaMaterials.BUCKET, 0))) {
            selected.addAmount(-1);
            playerQuickbar.add(new ItemStack(VanillaMaterials.MILK_BUCKET, 1));
          }
      }
    }
  }
View Full Code Here

public class ClickArguments {
  private final Slot slot;
  private final ClickAction action;

  public ClickArguments(Inventory inventory, int slot, ClickAction action) {
    this(new Slot(inventory, slot), action);
  }
View Full Code Here

  }

  @Override
  public void onInteractBy(Entity entity, Block block, Action type, BlockFace clickedFace) {
    super.onInteractBy(entity, block, type, clickedFace);
    Slot inv = PlayerUtil.getHeldSlot(entity);
    if (inv != null && inv.get() != null && type.equals(Action.RIGHT_CLICK)) {
      if (grow(block, inv.get().getMaterial()) && !PlayerUtil.isCostSuppressed(entity)) {
        inv.addAmount(-1);
      }
    }
  }
View Full Code Here

TOP

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

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.