Package org.spout.api.inventory

Examples of org.spout.api.inventory.ItemStack


   *
   * @return True if smelting can happen else false.
   */
  public boolean canSmelt() {
    FurnaceInventory inventory = getInventory();
    ItemStack output = inventory.getOutput();
    return inventory.hasIngredient() && (output == null || output.getMaterial() == ((TimedCraftable) inventory.getIngredient().getMaterial()).getResult().getMaterial());
  }
View Full Code Here


  public void smelt() {
    FurnaceInventory inventory = getInventory();
    if (!inventory.hasIngredient()) {
      return;
    }
    ItemStack ingredient = inventory.getIngredient();
    ItemStack result = ((TimedCraftable) ingredient.getMaterial()).getResult();
    FurnaceSmeltEvent event = VanillaPlugin.getInstance().getEngine().getEventManager().callEvent(new FurnaceSmeltEvent(this, new MaterialCause(ingredient.getMaterial(), this.getBlock()), ingredient, result));
    if (!event.isCancelled()) {
      if (inventory.getOutput() == null) {
        inventory.setOutput(event.getResult());
      } else {
        result = event.getResult();
        if (inventory.getOutput().getMaterial().getId() != result.getMaterial().getId()) {
          throw new UnsupportedOperationException("Smelt result must be the same material as the output slot.");
        }
        inventory.addAmount(FurnaceInventory.OUTPUT_SLOT, result.getAmount());
      }
      inventory.addAmount(FurnaceInventory.INGREDIENT_SLOT, -1);
    }

    setMaxSmeltTime(-1);
View Full Code Here

      return 0;
    }
  }

  public boolean hasSaddle() {
    ItemStack stack = get(SADDLE_SLOT);
    return stack != null && stack.getMaterial().isMaterial(VanillaMaterials.SADDLE);
  }
View Full Code Here

    if (getBrewTime() <= 0) {
      // Try to start brewing
      if (inventory.hasInput() && inventory.hasOutput()) {
        // Ensure the input is able to brew the three output items
        for (int i = 0; i < 3; i++) {
          ItemStack output = inventory.getOutput(i);
          if (output == null) {
            continue;
          }
          if (((PotionReagent) inventory.getInput().getMaterial()).getResult((PotionItem) output.getMaterial()) == null) {
            return;
          }
        }
        input = inventory.getInput(); // Store input just in case it is later removed during the brewing process
        setBrewTime(1);
        inventory.addAmount(BrewingStandInventory.INPUT_SLOT, -1);
      }
    } else {
      // Continue brewing
      float newBrewTime = getBrewTime() + dt;
      if (newBrewTime > BREW_TIME_INCREMENT) {
        // Brewing has finished
        newBrewTime = -1;

        // Set output
        if (inventory.hasOutput()) {
          for (int i = 0; i < 3; i++) {
            ItemStack output = inventory.getOutput(i);
            if (output == null) {
              continue;
            }
            ItemStack result = new ItemStack(((PotionReagent) input.getMaterial()).getResult((PotionItem) output.getMaterial()), 1);

            PotionBrewEvent event = new PotionBrewEvent(this, new MaterialCause(output.getMaterial(), this.getBlock()), input, output, result);

            VanillaPlugin.getInstance().getEngine().getEventManager().callEvent(event);
View Full Code Here

   * Sets the item that is currently being played by this Jukebox
   *
   * @param item to set to
   */
  public void setPlayedItem(ItemStack item) {
    ItemStack old = getData().put(VanillaData.JUKEBOX_ITEM, item);
    if (old != null) {
      // Drop the old item
      Item.drop(getPoint(), old, Vector3f.UP.mul(0.5));
    }
    setPlaying(item != null);
View Full Code Here

   * Gets the current music this Jukebox plays
   *
   * @return Music
   */
  public Music getMusic() {
    ItemStack current = this.getPlayedItem();
    if (canPlay(current.getMaterial())) {
      return ((MusicDisc) current.getMaterial()).getMusic();
    } else {
      return Music.NONE;
    }
  }
View Full Code Here

      MAX_ITEM_VALUE = inventory.size() * 64.0;

      InventoryIterator iter = inventory.iterator();
      while (iter.hasNext()) {
        ItemStack next = iter.next();
        if (next != null && !next.isEmpty()) {
          currentValue += getItemStackValue(next);
        }
      }
      updateRedstoneValue();
      inventory.addViewer(this);
View Full Code Here

    EngineFaker.setupEngine();
  }

  @Test
  public void testDamageModifier() {
    ItemStack test = new ItemStack(VanillaMaterials.DIAMOND_CHESTPLATE, 1);
    Enchantment.addEnchantment(test, VanillaEnchantments.PROTECTION, 4, false);
    assertTrue(Enchantment.hasEnchantment(test, VanillaEnchantments.PROTECTION));

    Armor armor = (Armor) test.getMaterial();
    assertTrue((int) Math.ceil(.04 * (armor.getBaseProtection() + armor.getProtection(test, new NullDamageCause(DamageType.CACTUS)))) == 1);
  }
View Full Code Here

  }

  @Test
  public void testAddEnchantmentPick() {
    assertTrue(VanillaEnchantments.UNBREAKING.canEnchant(VanillaMaterials.DIAMOND_PICKAXE));
    ItemStack itemStack = new ItemStack(VanillaMaterials.DIAMOND_PICKAXE, 1);
    Enchantment.addEnchantment(itemStack, VanillaEnchantments.EFFICIENCY, 3, false);
    Enchantment.addEnchantment(itemStack, VanillaEnchantments.FORTUNE, 2, false);
    TObjectIntMap<Enchantment> enchantments = Enchantment.getEnchantments(itemStack);
    assertTrue(enchantments.size() == 2);
    assertTrue(enchantments.containsKey(VanillaEnchantments.EFFICIENCY));
View Full Code Here

    assertTrue(Enchantment.getEnchantmentLevel(itemStack, VanillaEnchantments.FORTUNE) == 2);
  }

  @Test
  public void testEnchantmentBow() {
    ItemStack itemStack = new ItemStack(VanillaMaterials.BOW, 1);
    Enchantment.addEnchantment(itemStack, VanillaEnchantments.PUNCH, 2, false);
    Enchantment.addEnchantment(itemStack, VanillaEnchantments.FORTUNE, 2, false);
    assertTrue(!VanillaEnchantments.FORTUNE.canEnchant(VanillaMaterials.BOW));
    assertTrue(Enchantment.getEnchantmentLevel(itemStack, VanillaEnchantments.PUNCH) == 2);
    assertTrue(Enchantment.getEnchantmentLevel(itemStack, VanillaEnchantments.FORTUNE) == 0);
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.