Package org.spout.vanilla.inventory.block

Examples of org.spout.vanilla.inventory.block.FurnaceInventory


   * Check if all the criteria for smelting is met.
   *
   * @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


  /**
   * Activate the smelting process.
   */
  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);
    setSmeltTime(-1);
  }
View Full Code Here

  }

  @Override
  public void onTick(float dt) {
    final float fuel = getFuel();
    final FurnaceInventory inventory = getInventory();

    // Not burning
    if (fuel <= 0) {
      // Reset any progress
      if (getSmeltTime() > 0) {
        setSmeltTime(-1);
        setMaxSmeltTime(-1);
      }

      // Try to light the furnace
      if (inventory.hasFuel() && inventory.hasIngredient()) {
        float newFuel = ((Fuel) inventory.getFuel().getMaterial()).getFuelTime();
        FurnaceBurnEvent event = VanillaPlugin.getInstance().getEngine().getEventManager().callEvent(new FurnaceBurnEvent(this, inventory.getFuel(), newFuel));

        if (event.isCancelled()) {
          return;
        }
        newFuel = event.getBurnTime();
        setMaxFuel(newFuel);
        setFuel(newFuel);
        inventory.addAmount(FurnaceInventory.FUEL_SLOT, -1);
        setBurning(true);
        return;
      }

      setBurning(false);
    }
    // Burning
    else if (fuel > 0) {
      setBurning(true);
      pulseFuel(dt);
      final float smeltTime = getSmeltTime();
      if (smeltTime == -1) {
        // Try to start smelting
        if (inventory.hasIngredient()) {
          if (!canSmelt()) {
            return;
          }
          float newSmeltTime = ((TimedCraftable) inventory.getIngredient().getMaterial()).getCraftTime();
          setMaxSmeltTime(newSmeltTime);
          setSmeltTime(newSmeltTime);
          return;
        }
      }

      if (smeltTime <= 0) {
        // Try to smelt the current ingredient
        if (inventory.hasIngredient()) {
          smelt();
          return;
        }
      }

      if (smeltTime > 0) {
        // Reset progress if ingredient is gone
        if (!inventory.hasIngredient()) {
          setSmeltTime(-1);

          return;
        }
        pulseSmeltTime(dt);
View Full Code Here

        break;
      case CRAFTING_TABLE:
        player.get(WindowHolder.class).openWindow(new CraftingTableWindow(player));
        break;
      case FURNACE:
        player.get(WindowHolder.class).openWindow(new FurnaceWindow(player, null, new FurnaceInventory()));
        break;
      case DISPENSER:
        player.get(WindowHolder.class).openWindow(new DispenserWindow(player, new DispenserInventory()));
        break;
      case ENCHANTMENT_TABLE:
View Full Code Here

  }

  @Override
  public boolean onShiftClick(ItemStack stack, int slot, Inventory from) {
    if (!(from instanceof FurnaceInventory)) {
      final FurnaceInventory furnace = this.getFurnace().getInventory();
      Material material = stack.getMaterial();
      // Try to put the item into the furnace, fuel first (!)
      if (material instanceof Fuel && ((Fuel) material).getFuelTime() > 0.0f) {
        // Put into fuel slot
        furnace.getFuelSlot().add(stack);
        from.set(slot, stack);
        if (stack.isEmpty()) {
          return true;
        }
      } else if (material instanceof TimedCraftable) {
        // Put into ingredient slot
        furnace.getIngredientSlot().add(stack);
        from.set(slot, stack);
        if (stack.isEmpty()) {
          return true;
        }
      }
View Full Code Here

        break;
      case CRAFTING_TABLE:
        player.get(WindowHolder.class).openWindow(new CraftingTableWindow(player, title));
        break;
      case FURNACE:
        player.get(WindowHolder.class).openWindow(new FurnaceWindow(player, new FurnaceInventory(), title));
        break;
      case DISPENSER:
        player.get(WindowHolder.class).openWindow(new DispenserWindow(player, new DispenserInventory(), title));
        break;
      case ENCHANTMENT_TABLE:
View Full Code Here

TOP

Related Classes of org.spout.vanilla.inventory.block.FurnaceInventory

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.