Package org.spout.api.inventory

Examples of org.spout.api.inventory.ItemStack


    args.assertCompletelyParsed();
    PlayerInventory inventory = player.get(PlayerInventory.class);
    if (inventory == null) {
      throw new CommandException("Player has no inventory.");
    }
    ItemStack i = inventory.getQuickbar().getSelectedSlot().get();
    if (i == null || !(i.getMaterial() instanceof Map)) {
      throw new CommandException("Held item is not a map");
    }
    Map m = (Map) i.getMaterial();
    int col = args.popInteger("col");
    for (ProtocolEvent e : m.flood(i, col)) {
      player.getNetwork().callProtocolEvent(e);
    }
  }
View Full Code Here


      } else if (Substance.class.isAssignableFrom(clazz)) {
        final Substance substance = entity.get(Substance.class);
        switch (ObjectType.valueOf(name.toUpperCase())) {
          case ITEM:
            Material item = VanillaArgumentTypes.popMaterial("item", args);
            ((Item) substance).setItemStack(new ItemStack(item, 1));
            break;
          case FALLING_OBJECT:
            Material block = VanillaArgumentTypes.popMaterial("block", args);
            if (!(block instanceof BlockMaterial)) {
              throw new CommandException("Material " + block.getDisplayName() + " is not a block!");
View Full Code Here

  @Override
  public List<ItemStack> getDrops(Random random, Set<Flag> flags, List<ItemStack> drops) {
    if (this.canDrop(random, flags)) {
      int amount = amounts[random.nextInt(amounts.length)];
      if (amount > 0) {
        drops.add(new ItemStack(getMaterial(), amount));
      }
    }
    return drops;
  }
View Full Code Here

        }
        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;
              }
            }
          }
        }
        break;
      case DROP:
        ItemStack get = args.getSlot().get();
        if (get == null) {
          return true;
        }
        if (get.getAmount() == 1) {
          getHuman().dropItem(get);
          args.getSlot().set(null);
        } else {
          getHuman().dropItem(get.clone().setAmount(1));
          args.getSlot().addAmount(-1);
        }
        return true;
      case CTRL_DROP:
        if (args.getSlot().get() == null) {
View Full Code Here

  }

  @Override
  public List<ItemStack> getDrops(Random random, Set<Flag> flags, List<ItemStack> drops) {
    if (this.canDrop(random, flags)) {
      drops.add(new ItemStack(getMaterial(), getAmount()));
    }
    return drops;
  }
View Full Code Here

  @Override
  public List<ItemStack> getDrops(Random random, Set<Flag> flags, List<ItemStack> drops) {
    if (this.canDrop(random, flags)) {
      int amount = min + random.nextInt(max - min + 1);
      if (amount > 0) {
        drops.add(new ItemStack(getMaterial(), amount));
      }
    }
    return drops;
  }
View Full Code Here

  public void onAttached() {
    super.onAttached();
    setEntityProtocol(new CreatureProtocol(CreatureType.COW));
    DeathDrops dropComponent = getOwner().add(DeathDrops.class);
    Random random = getRandom();
    dropComponent.addDrop(new ItemStack(VanillaMaterials.RAW_BEEF, random.nextInt(2) + 1));
    dropComponent.addDrop(new ItemStack(VanillaMaterials.LEATHER, random.nextInt(2)));
    dropComponent.addXpDrop((short) (getRandom().nextInt(3) + 1));
    if (getAttachedCount() == 1) {
      getOwner().add(Health.class).setSpawnHealth(10);
    }
    NearbyMaterialHolderSensor materialHolderSensor = new NearbyMaterialHolderSensor(getAI(), VanillaMaterials.WHEAT);
View Full Code Here

          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 Creeper extends Living implements Hostile {
  @Override
  public void onAttached() {
    super.onAttached();
    setEntityProtocol(new CreatureProtocol(CreatureType.CREEPER));
    getOwner().add(DeathDrops.class).addDrop(new ItemStack(VanillaMaterials.GUNPOWDER, getRandom().nextInt(2))).addXpDrop((short) 5);
    PhysicsComponent physics = getOwner().getPhysics();
    physics.activate(2f, new BoxShape(1f, 2f, 1f), false, true);
    physics.setFriction(10f);
    physics.setRestitution(0f);
    if (getAttachedCount() == 1) {
View Full Code Here

    super(name, id, null, type);
  }

  @Override
  public ItemStack getResult() {
    return new ItemStack(VanillaMaterials.STEAK, 1);
  }
View Full Code Here

TOP

Related Classes of org.spout.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.