Java 类org.bukkit.block.Furnace 实例源码

项目:Slimefun4-Chinese-Version    文件:FurnaceListener.java   
public void onSmelt(FurnaceSmeltEvent e)
{
    if(BlockStorage.check(e.getBlock()) != null && (BlockStorage.check(e.getBlock()) instanceof EnhancedFurnace))
    {
        EnhancedFurnace furnace = (EnhancedFurnace)BlockStorage.check(e.getBlock());
        Furnace f = (Furnace)e.getBlock().getState();
        int amount = f.getInventory().getSmelting().getType().toString().endsWith("_ORE") ? furnace.getOutput() : 1;
        ItemStack output = RecipeCalculator.getSmeltedOutput(f.getInventory().getSmelting().getType());
        ItemStack result = f.getInventory().getResult();
        if(result != null)
            result = result.clone();
        f.getInventory().setResult(null);
        if(result != null)
            f.getInventory().setResult(new CustomItem(result, result.getAmount() + amount <= result.getMaxStackSize() ? result.getAmount() + amount : result.getMaxStackSize()));
        else
            f.getInventory().setResult(new CustomItem(output, output.getAmount() + amount <= output.getType().getMaxStackSize() ? output.getAmount() + amount : output.getType().getMaxStackSize()));
    }
}
项目:OpenUHC    文件:Overcook.java   
/**
 * Handles the action of smelting all items at once, exploding the furnace, and dropping the smelted items on the
 * ground.
 *
 * @param event The event
 */
@EventHandler(ignoreCancelled = true)
public void onFurnaceSmelt(FurnaceSmeltEvent event) {
  ItemStack resultItem = event.getResult();
  final Material result = resultItem.getType();
  //TODO: Verify that the "smelting amount" contains any extra ingredients
  final int amount = ((Furnace) event.getBlock().getState()).getInventory().getSmelting().getAmount();

  event.getSource().setType(Material.AIR);
  resultItem.setType(Material.AIR);

  Block block = event.getBlock();
  block.setType(Material.AIR);
  Location location = block.getLocation().add(0.5, 0.5, 0.5);
  World world = location.getWorld();
  world.createExplosion(location, 7);
  world.dropItem(location, new ItemStack(result, amount));
}
项目:HCFCore    文件:FastBrewingListener.java   
private void startUpdate(final Furnace tile, final int increase)
{
    new BukkitRunnable()
    {
        public void run()
        {
            if ((tile.getCookTime() > 0) || (tile.getBurnTime() > 0))
            {
                tile.setCookTime((short)(tile.getCookTime() + increase));
                tile.update();
            }
            else
            {
                cancel();
            }
        }
    }.runTaskTimer(HCF.getPlugin(), 1L, 1L);
}
项目:HCFCore    文件:FastBrewingListener.java   
private void startUpdate(final Furnace tile, final int increase)
{
    new BukkitRunnable()
    {
        public void run()
        {
            if ((tile.getCookTime() > 0) || (tile.getBurnTime() > 0))
            {
                tile.setCookTime((short)(tile.getCookTime() + increase));
                tile.update();
            }
            else
            {
                cancel();
            }
        }
    }.runTaskTimer(HCF.getPlugin(), 1L, 1L);
}
项目:Skript    文件:ExprFurnaceSlot.java   
@Override
protected Slot[] get(final Event e, final Block[] source) {
    return get(source, new Getter<Slot, Block>() {
        @SuppressWarnings("null")
        @Override
        @Nullable
        public Slot get(final Block b) {
            if (b.getType() != Material.FURNACE && b.getType() != Material.BURNING_FURNACE)
                return null;
            if (getTime() >= 0 && (e instanceof FurnaceSmeltEvent && b.equals(((FurnaceSmeltEvent) e).getBlock()) || e instanceof FurnaceBurnEvent && b.equals(((FurnaceBurnEvent) e).getBlock())) && !Delay.isDelayed(e)) {
                return new FurnaceEventSlot(e, ((Furnace) b.getState()).getInventory());
            } else {
                return new InventorySlot(((Furnace) b.getState()).getInventory(), slot);
            }
        }
    });
}
项目:AnnihilationPro    文件:Furnace_V1_7_R4.java   
@Override
    public InventoryHolder getOwner()
    {
//      int x = 0;
//      org.bukkit.block.Block b = this.world.getWorld().getBlockAt(x, 0, 0);
//      while(b != null && b.getType() != Material.AIR)
//          b = this.world.getWorld().getBlockAt(++x,0,0);
//      Furnace furnace = new CraftFurnace(b);
        Furnace furnace = new CraftFurnace(this.world.getWorld().getBlockAt(0, 0, 0));
        try
        {
            ReflectionUtil.setValue(furnace, "furnace", this);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return furnace;
    }
项目:ExilePearl    文件:PlayerListener.java   
/**
 * Updates the pearl holder
 * @param pearl The pearl to update
 * @param holder The pearl holder
 * @param event The event
 */
private void updatePearlHolder(ExilePearl pearl, InventoryHolder holder, Cancellable event) {

    if (holder instanceof Chest) {
        updatePearl(pearl, (Chest)holder);
    } else if (holder instanceof DoubleChest) {
        updatePearl(pearl, (Chest) ((DoubleChest) holder).getLeftSide());
    } else if (holder instanceof Furnace) {
        updatePearl(pearl, (Furnace) holder);
    } else if (holder instanceof Dispenser) {
        updatePearl(pearl, (Dispenser) holder);
    } else if (holder instanceof Dropper) {
        updatePearl(pearl, (Dropper) holder);
    } else if (holder instanceof Hopper) {
        updatePearl(pearl, (Hopper) holder);
    } else if (holder instanceof BrewingStand) {
        updatePearl(pearl, (BrewingStand) holder);
    } else if (holder instanceof Player) {
        updatePearl(pearl, (Player) holder);
    }else {
        event.setCancelled(true);
    }
}
项目:StarQuestCode    文件:Fuel.java   
/**
 * Consumes fuel from the given Furnace.
 * 
 * @param furnace
 *            The furnace to consume fuel from
 * @return The burn time of the fuel consumed. Returns 0 on failure.
 */
public static int consume(final Furnace furnace) {
    try {
        FurnaceInventory furnaceInventory = furnace.getInventory();
        ItemStack fuelStack = furnaceInventory.getFuel();
        if (fuelStack == null)
            return 0;
        int burnTime = burnTime(fuelStack.getType().getId());
        if (burnTime > 0) {
            fuelStack.setAmount(fuelStack.getAmount() - 1);
            furnaceInventory.setFuel(fuelStack);
        }
        return burnTime;
    } catch (Exception e) {
        return 0;
    }
}
项目:StarQuestCode    文件:Fuel.java   
/**
 * Sets the given Block to a Furnace with the given burn state, and sets the
 * furnace contents to the given Inventory.
 * 
 * @param block
 *            The block to set as a Furnace
 * @param direction
 *            The direction to set the furnace to.
 * @param burning
 *            Whether the furnace is burning
 * @param inventory
 *            Inventory to copy over
 * @return True if the operation was a success, false if the existing block
 *         could not be cast to a furnace. In that case, this function does
 *         nothing.
 */
public static boolean setFurnace(final Block furnaceBlock, final BlockRotation direction, final boolean burning) {
    try {
        Inventory inventory = ((Furnace) furnaceBlock.getState()).getInventory();
        ItemStack[] contents = inventory.getContents();
        inventory.clear();

        if (burning) {
            furnaceBlock.setTypeIdAndData(Material.BURNING_FURNACE.getId(), direction.getYawData(), false);
        } else {
            furnaceBlock.setTypeIdAndData(Material.FURNACE.getId(), direction.getYawData(), false);
        }

        Inventory newInventory = ((Furnace) furnaceBlock.getState()).getInventory();
        newInventory.setContents(contents);
        return true;
    } catch (Exception e) {
        return false;
    }
}
项目:StarQuestCode    文件:Builder.java   
/**
 * Uses the given amount of energy and returns true if successful.
 * 
 * @param anchor
 *            The anchor of the Builder
 * @param energy
 *            The amount of energy needed for the next action
 * @return True if enough energy could be used up
 */
protected boolean useEnergy(final BlockLocation anchor, final int energy) {
    if (!useEnergy)
        return true;

    while (currentEnergy < energy) {
        int newFuel = Fuel.consume((Furnace) anchor.getRelative(furnace.vector(yaw)).getBlock().getState());
        if (newFuel > 0) {
            currentEnergy += newFuel;
        } else {
            return false;
        }
    }
    currentEnergy -= energy;
    return true;
}
项目:StarQuestCode    文件:Pump.java   
/**
 * Adds a drain block to the furnace's smelt slot for the deconstruction of
 * a drain.
 * 
 * @param data The data value of the tube material to check.
 * @return True if a drain block item could be added to the furnace smelt
 *         slot.
 */
boolean putDrainItem(byte data) {
    FurnaceInventory inventory = ((Furnace) anchor.getRelative(backward).getBlock().getState()).getInventory();
    ItemStack item = inventory.getSmelting();
    if (item == null) {
        inventory.setSmelting(new ItemStack(tubeMaterial, 1, data));
        return true;
    } else if (item.getType() == tubeMaterial && item.getDurability() == data) {
        int amount = item.getAmount();
        if (amount < tubeMaterial.getMaxStackSize()) {
            item.setAmount(amount + 1);
            inventory.setSmelting(item);
            return true;
        }
    }
    return false;
}
项目:StarQuestCode    文件:Pump.java   
private Stage stop() {
    if (tube.size() == 0)
        return null;
    // Check which mode the pump should operate in.
    FurnaceInventory inventory = ((Furnace) anchor.getRelative(backward).getBlock().getState()).getInventory();
    ItemStack item = inventory.getFuel();
    if (item != null && item.getType() == filledBucketMaterial) {
        if (filledBucketMaterial == Material.WATER_BUCKET && anchor.getWorld().getEnvironment() == World.Environment.NETHER && !player.hasPermission("machinapump.nether-water")) {
            player.sendMessage("You do not have permission to pour water with a pump in the nether.");
            return new Retract();
        } else if (filledBucketMaterial == Material.LAVA_BUCKET && !player.hasPermission("machinapump.lava.fill")) {
            player.sendMessage("You do not have permission to pour lava with a pump.");
            return new Retract();
        }
        return new Fill();
    }
    if (liquidMaterial == Material.LAVA && !player.hasPermission("machinapump.lava.drain")) {
        player.sendMessage("You do not have permission to drain lava with a pump.");
        return new Retract();
    }
    return new Drain();
}
项目:StarQuestCode    文件:Drill.java   
/**
 * Uses the given amount of energy and returns true if successful.
 * 
 * @param anchor
 *            The anchor of the Drill
 * @param energy
 *            The amount of energy needed for the next action
 * @return True if enough energy could be used up
 */
private boolean useEnergy(final BlockLocation anchor, final int energy) {
    if (!useEnergy)
        return true;

    while (currentEnergy < energy) {
        int newFuel = Fuel.consume((Furnace) anchor.getRelative(furnace.vector(yaw)).getBlock().getState());
        if (newFuel > 0) {
            currentEnergy += newFuel;
        } else {
            return false;
        }
    }
    currentEnergy -= energy;
    return true;
}
项目:StarQuestCode    文件:FurnaceRelay.java   
private boolean doSend(BlockLocation fromFurnace) throws PipelineException, PacketTypeUnsupportedException {
    FurnaceInventory inventory = (((Furnace) fromFurnace.getBlock().getState()).getInventory());
    ItemStack item = inventory.getResult();
    if (item == null || item.getType() == Material.AIR)
        return false;
    ItemStack toSend = new ItemStack(item);
    toSend.setAmount(1);

    if (pipeline.sendPacket(toSend)) {
        item.setAmount(item.getAmount() - 1);
        inventory.setResult(item);
        age = 0;
        return true;
    }
    return false;
}
项目:StarQuestCode    文件:FurnaceEndpoint.java   
/**
 * Handles a sending inventory for the furnace at the given location. Does
 * not check if the location has a valid furnace.<br>
 * Fuels: Added to the fuel slot if there is room.<br>
 * Items that can be burnt: Added to the burn slot.
 * 
 * @param location
 * @param inventory
 * @return True if the inventory was changed.
 */
public boolean handle(Inventory inventory) {
    FurnaceInventory furnaceInventory = ((Furnace) location.getBlock().getState()).getInventory();
    if (furnaceInventory == inventory) {
        return false;
    }
    updateLevels();

    if (fuelAmount < 2) {
        if (restockFuel(furnaceInventory, inventory))
            return true;
        return restockSmelting(furnaceInventory, inventory);
    } else {
        if (restockSmelting(furnaceInventory, inventory))
            return true;
        return restockFuel(furnaceInventory, inventory);
    }
}
项目:StarQuestCode    文件:FurnaceEndpoint.java   
/**
 * Updates the status of the furnace to the current amount of fuel and
 * smelting items.
 */
private final void updateLevels() {
    FurnaceInventory inventory = (((Furnace) location.getBlock().getState()).getInventory());
    final ItemStack fuelItem = inventory.getFuel();
    if (fuelItem == null || fuelItem.getType() == Material.AIR) {
        fuelAmount = 0;
    } else {
        fuelAmount = fuelItem.getAmount();
    }

    final ItemStack smeltItem = inventory.getSmelting();
    if (smeltItem == null || smeltItem.getType() == Material.AIR) {
        smeltingAmount = 0;
    } else {
        smeltingAmount = smeltItem.getAmount();
    }
}
项目:StarQuestCode    文件:Drill.java   
/**
 * Detects if a dropper or furnace is placed in the correct position and returns the Block or null if no correct Block was found.
 * @param base the GuiBlock
 * @param forward the forward BlockFace of the drill
 * @return the dropper or furnace Block
 */
public Block detectFuelInventory(Block base, BlockFace forward)
{
    for(BlockFace bf : diamond)
    {
        if(base.getRelative(bf).getState() instanceof Dropper || base.getRelative(bf).getState() instanceof Furnace)
            return base.getRelative(bf);
    }

    Block relativePossibleLoc = base.getRelative(BlockFace.DOWN).getRelative(getBlockFaceBack(forward));

    if(relativePossibleLoc.getState() instanceof Dropper || relativePossibleLoc.getState() instanceof Furnace)
            return relativePossibleLoc;

    return null;
}
项目:McMMOPlus    文件:InventoryListener.java   
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onFurnaceBurnEvent(FurnaceBurnEvent event) {
    Block furnaceBlock = event.getBlock();
    BlockState furnaceState = furnaceBlock.getState();
    ItemStack smelting = furnaceState instanceof Furnace ? ((Furnace) furnaceState).getInventory().getSmelting() : null;

    if (!ItemUtils.isSmeltable(smelting)) {
        return;
    }

    Player player = getPlayerFromFurnace(furnaceBlock);

    if (!UserManager.hasPlayerDataKey(player) || !Permissions.secondaryAbilityEnabled(player, SecondaryAbility.FUEL_EFFICIENCY)) {
        return;
    }

    event.setBurnTime(UserManager.getPlayer(player).getSmeltingManager().fuelEfficiency(event.getBurnTime()));
}
项目:McMMOPlus    文件:InventoryListener.java   
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onFurnaceExtractEvent(FurnaceExtractEvent event) {
    Block furnaceBlock = event.getBlock();
    BlockState furnaceState = furnaceBlock.getState();
    ItemStack result = furnaceState instanceof Furnace ? ((Furnace) furnaceState).getInventory().getResult() : null;

    if (!ItemUtils.isSmelted(result)) {
        return;
    }

    Player player = getPlayerFromFurnace(furnaceBlock);

    if (!UserManager.hasPlayerDataKey(player) || !Permissions.vanillaXpBoost(player, SkillType.SMELTING)) {
        return;
    }

    event.setExpToDrop(UserManager.getPlayer(player).getSmeltingManager().vanillaXPBoost(event.getExpToDrop()));
}
项目:TNE-Bukkit    文件:RewardsListener.java   
@EventHandler
public void onSmelt(final FurnaceSmeltEvent event) {
  if (TNE.instance().api().getBoolean("Materials.Enabled", TNE.instance().defaultWorld, "")) {
    if (event.getResult() != null && !event.getResult().getType().equals(Material.AIR)) {
      String name = event.getBlock().getType().name();
      if (event.getBlock().getState() instanceof Furnace) {
        Furnace f = (Furnace) event.getBlock().getState();

        int amount = (f.getInventory().getResult() != null) ? f.getInventory().getResult().getAmount() : 1;

        BigDecimal cost = InteractionType.SMELTING.getCost(name, event.getBlock().getWorld().toString(), "").multiply(new BigDecimal(amount));

        List<String> lore = new ArrayList<>();
        lore.add(ChatColor.WHITE + "Smelting Cost: " + ChatColor.GOLD + cost);

        ItemStack result = event.getResult();
        ItemMeta meta = result.getItemMeta();
        meta.setLore(lore);

        result.setItemMeta(meta);
        event.setResult(result);
      }
    }
  }
}
项目:FactoryMod    文件:FactoryObject.java   
/**
 * Initializes the inventory for this factory
 */
//Due to non-destructable factories this will not have been called on reconstructed factories
//however I am unable to find a use for this method in the current code, so it doesn't
//seem to be an issue right now, maybe  the calls in the constructor should be gotten rid of
//all methods that get the inventory reinitialize the contents.
public void initializeInventory()
{
    switch(factoryType)
    {
    case PRODUCTION:
        Chest chestBlock = (Chest)factoryInventoryLocation.getBlock().getState();
        factoryInventory = chestBlock.getInventory();
        Furnace furnaceBlock = (Furnace)factoryPowerSourceLocation.getBlock().getState();
        factoryPowerInventory = furnaceBlock.getInventory();
        break;
    default:
        break;
    }
}
项目:RoyalSurvivors    文件:SurvivorsListener.java   
@EventHandler
public void fastFurnaceBreak(BlockBreakEvent e) {
    Player p = e.getPlayer();
    if (!RUtils.isInInfectedWorld(p) || p.getGameMode() == GameMode.CREATIVE) return;
    Block b = e.getBlock();
    if (!(b.getState() instanceof Furnace)) return;
    Furnace f = (Furnace) b.getState();
    ConfManager cm = ConfManager.getConfManager("otherdata.yml");
    Location l = f.getLocation();
    String path = "furnaces." + l.getWorld().getName() + "," + l.getBlockX() + "," + l.getBlockY() + "," + l.getBlockZ();
    if (!cm.getBoolean(path, false)) return;
    cm.set(path, null);
    e.setCancelled(true);
    Collection<ItemStack> drops = e.getBlock().getDrops();
    e.getBlock().setType(Material.AIR);
    l.getWorld().dropItemNaturally(l, plugin.furnace);
    for (ItemStack is : drops) {
        if (is == null || is.getType() == Material.FURNACE) continue;
        l.getWorld().dropItemNaturally(l, is);
    }
}
项目:RoyalSurvivors    文件:SurvivorsListener.java   
@EventHandler
public void fastFurnacePlace(BlockPlaceEvent e) {
    Player p = e.getPlayer();
    if (!RUtils.isInInfectedWorld(p)) return;
    ItemStack hand = e.getItemInHand();
    if (hand == null || hand.getType() != Material.FURNACE) return;
    ItemMeta him = hand.getItemMeta();
    ItemMeta fim = plugin.furnace.getItemMeta();
    String hdn = him.getDisplayName();
    if (hdn == null || !hdn.equals(fim.getDisplayName())) return;
    List<String> hl = him.getLore();
    if (hl == null || !hl.containsAll(fim.getLore())) return;
    Block b = e.getBlockPlaced();
    if (!(b.getState() instanceof Furnace)) return;
    Furnace f = (Furnace) b.getState();
    ConfManager cm = ConfManager.getConfManager("otherdata.yml");
    Location l = f.getLocation();
    String path = "furnaces." + l.getWorld().getName() + "," + l.getBlockX() + "," + l.getBlockY() + "," + l.getBlockZ();
    cm.set(path, true);
}
项目:Transport-Pipes    文件:ContainerBlockUtils.java   
public TransportPipesContainer createContainerFromBlock(Block block) {
    if (block.getState() instanceof Furnace) {
        return new FurnaceContainer(block);
    } else if (block.getState() instanceof BrewingStand) {
        return new BrewingStandContainer(block);
    } else if (block.getState() instanceof InventoryHolder) {
        return new SimpleInventoryContainer(block);
    }
    return null;
}
项目:QuestManager    文件:CookingSkill.java   
@EventHandler
public void onPlayerCook(PlayerInteractEvent e) {   
    if (!QuestManagerPlugin.questManagerPlugin.getPluginConfiguration().getWorlds()
            .contains(e.getPlayer().getWorld().getName())) {
        return;
    }

    if (e.getHand() != EquipmentSlot.HAND)
        return;

    if (e.getClickedBlock() == null)
        return;

    if (e.getClickedBlock().getType() != Material.FURNACE &&
            e.getClickedBlock().getType() != Material.BURNING_FURNACE) {
        onPlayerCombine(e);
        return;
    }

    if (furnaceMap.containsKey(e.getClickedBlock().getLocation())) {
        e.getPlayer().sendMessage(IN_USE_MESSAGE);
        e.setCancelled(true);
        return;
    }

    QuestPlayer qp = QuestManagerPlugin.questManagerPlugin.getPlayerManager().getPlayer(e.getPlayer());
    furnaceMap.put(e.getClickedBlock().getLocation(), qp);


    CookingGui gui = new CookingGui(e.getPlayer(), (Furnace) e.getClickedBlock().getState(),
            bonusQuality, useItemQuality
            );
    InventoryMenu menu = new InventoryMenu(qp, gui);
    QuestManagerPlugin.questManagerPlugin.getInventoryGuiHandler().showMenu(e.getPlayer(), menu);

    e.setCancelled(true);
    return;
}
项目:QuestManager    文件:CookingGui.java   
public CookingGui(Player player, Furnace furnace, double bonusQuality, boolean useInputQuality) {
        this.player = player;
        this.furnace = furnace;
        this.bonusQuality = bonusQuality;
        this.useInputQuality = useInputQuality;

        this.gameState = State.STOPPED;

//      for (Fuel fuel : Fuel.values()) {
//          Bukkit.addRecipe(new FurnaceRecipe(new ItemStack(Material.FIRE), fuel.icon.getType()));
//      }

        Bukkit.getPluginManager().registerEvents(this, QuestManagerPlugin.questManagerPlugin);

    }
项目:civcraft    文件:Camp.java   
public void processFirepoints() {

    MultiInventory mInv = new MultiInventory();
    for (BlockCoord bcoord : this.fireFurnaceBlocks) {
        Furnace furnace = (Furnace)bcoord.getBlock().getState();
        mInv.addInventory(furnace.getInventory());
    }

    if (mInv.contains(null, CivData.COAL, (short)0, coal_per_firepoint)) {
        try {
            mInv.removeItem(CivData.COAL, coal_per_firepoint);
        } catch (CivException e) {
            e.printStackTrace();
        }

        this.firepoints++;
        if (firepoints > maxFirePoints) {
            firepoints = maxFirePoints;
        }
    } else {
        this.firepoints--;
        CivMessage.sendCamp(this, CivColor.Yellow+"Our campfire doesn't have enough coal to keep burning, its starting to go out! "+this.firepoints+" hours left.");

        double percentLeft = (double)this.firepoints / (double)this.maxFirePoints;
        if (percentLeft < 0.3) {
            CivMessage.sendCamp(this, CivColor.Yellow+ChatColor.BOLD+"Warning! Our campfire is less than 30% out! We need to stock it with more coal or our camp will be destroyed!");
        }

        if (this.firepoints < 0) {
                this.destroy();
        }
    }

    this.save();
    this.updateFirepit();
}
项目:civcraft    文件:WarRegen.java   
public static void destroyThisBlock(Block blk, Town town) {

    WarRegen.saveBlock(blk, town.getName(), false);

    switch (blk.getType()) {
    case TRAPPED_CHEST:
        ((Chest)blk.getState()).getBlockInventory().clear();
        break;
    case CHEST:
        ((Chest)blk.getState()).getBlockInventory().clear();
        break;
    case DISPENSER:
        ((Dispenser)blk.getState()).getInventory().clear();
        break;
    case BURNING_FURNACE:
    case FURNACE:
        ((Furnace)blk.getState()).getInventory().clear();
        break;
    case DROPPER:
        ((Dropper)blk.getState()).getInventory().clear();
        break;
    case HOPPER:
        ((Hopper)blk.getState()).getInventory().clear();
        break;
    default:
        break;
    }

    ItemManager.setTypeId(blk, CivData.AIR);
    ItemManager.setData(blk, 0x0, true);

}
项目:Slimefun4    文件:FurnaceListener.java   
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onSmelt(FurnaceSmeltEvent e) {
    if (BlockStorage.check(e.getBlock()) != null && BlockStorage.check(e.getBlock()) instanceof EnhancedFurnace) {
        EnhancedFurnace furnace = (EnhancedFurnace) BlockStorage.check(e.getBlock());
        Furnace f = (Furnace) e.getBlock().getState();
        int amount = f.getInventory().getSmelting().getType().toString().endsWith("_ORE") ? furnace.getOutput(): 1;
        ItemStack output = RecipeCalculator.getSmeltedOutput(f.getInventory().getSmelting().getType());
        ItemStack result = f.getInventory().getResult();
        if (result != null) result = result.clone();
        f.getInventory().setResult(null);
        if (result != null) f.getInventory().setResult(new CustomItem(result, result.getAmount() + amount > result.getMaxStackSize() ? result.getMaxStackSize(): result.getAmount() + amount));
        else f.getInventory().setResult(new CustomItem(output, output.getAmount() + amount > output.getType().getMaxStackSize() ? output.getType().getMaxStackSize(): output.getAmount() + amount));
    }
}
项目:StarQuestCode    文件:Pump.java   
public Stage run() {
    int size = tube.size();
    if (size == maxLength)
        return stop();

    BlockLocation target = anchor.getRelative(forward, size + 1);

    if (!target.isEmptyForCollision())
        return stop();

    // Try to take a drain block from the furnace.
    FurnaceInventory inventory = ((Furnace) anchor.getRelative(backward).getBlock().getState()).getInventory();
    ItemStack item = inventory.getSmelting();
    if (item != null && item.getType() == tubeMaterial) {
        byte data = (byte) item.getDurability();
        // Before taking, we have to simulate whether we can actually
        // place the block.
        if (!EventSimulator.blockPlace(target, tubeMaterial.getId(), (byte) 0, target.getRelative(backward, size), player))
            return stop();

        int newAmount = item.getAmount() - 1;
        if (newAmount < 1) {
            inventory.setSmelting(null);
        } else {
            item.setAmount(newAmount);
            inventory.setSmelting(item);
        }
        target.setTypeIdAndData(tubeMaterial.getId(), data, true);
        tube.add(target);
        return this;
    }
    return stop();
}
项目:StarQuestCode    文件:Planter.java   
private void useTool() throws NoToolException {
    if (!useTool)
        return;
    FurnaceInventory furnaceInventory = ((Furnace) furnace.getBlock().getState()).getInventory();
    if (!Tool.useInFurnace(furnaceInventory, planterTool, chestInventory())) {
        throw new NoToolException();
    }
}
项目:StarQuestCode    文件:Planter.java   
/**
 * Uses the given amount of energy and returns true if successful.
 * 
 * @param energy
 *            The amount of energy needed for the next action
 * @return True if enough energy could be used up
 */
protected void useEnergy(final int energy) throws NoEnergyException {
    if (!useEnergy)
        return;

    while (currentEnergy < energy) {
        int newFuel = Fuel.consume((Furnace) furnace.getBlock().getState());
        if (newFuel > 0) {
            currentEnergy += newFuel;
        } else {
            throw new NoEnergyException();
        }
    }
    currentEnergy -= energy;
}
项目:StarQuestCode    文件:BlockTranslation.java   
public BlockTranslation(List<Block> blocks, final BlockFace direction)
{
    this.blocks = blocks;
    this.direction = direction;

    blocksData = new ArrayList<BlockData>();

    for(Block b : blocks)
    {
        blocksData.add(new BlockData(b));
        if(b.getType() == Material.CHEST || b.getType() == Material.TRAPPED_CHEST)
        {
            this.chestItems = ((Chest) b.getState()).getInventory().getContents().clone();
            ((Chest) b.getState()).getInventory().clear();
        }
        else if(b.getState() instanceof Dropper)
        {
            this.dropperItems = ((Dropper) b.getState()).getInventory().getContents().clone();
            ((Dropper) b.getState()).getInventory().clear();
        }
        else if(b.getState() instanceof Furnace)
        {
            this.furnaceFuel = ((Furnace) b.getState()).getInventory().getFuel();
            this.furnaceBurnMaterial = ((Furnace) b.getState()).getInventory().getSmelting();
            this.furnaceResult = ((Furnace) b.getState()).getInventory().getResult();
            this.furnaceBurnTime = ((Furnace) b.getState()).getBurnTime();
            ((Furnace) b.getState()).getInventory().clear();
        }
    }
}
项目:McMMOPlus    文件:InventoryListener.java   
private Block processInventoryOpenOrCloseEvent(Inventory inventory) {
    if (!(inventory instanceof FurnaceInventory)) {
        return null;
    }

    Furnace furnace = (Furnace) inventory.getHolder();

    if (furnace == null || furnace.getBurnTime() != 0) {
        return null;
    }

    return furnace.getBlock();
}
项目:Mechanization-old    文件:WorldFactory.java   
public static boolean takeFurnaceFuel(Furnace f, int fuel){
    FurnaceInventory inv = f.getInventory();
    if (inv.getFuel().getAmount()>fuel){
        ItemStack is = inv.getFuel();
        is.setAmount(is.getAmount()-fuel);
        return true;
    } else if (inv.getFuel().getAmount()==fuel){
        inv.setFuel(new ItemStack(Material.AIR));
        return true;
    }
    return false;
}
项目:Mechanization-old    文件:WorldFactory.java   
public void activate(){
    new BukkitRunnable(){
        @Override
        public void run() {
            MechaFactoryRecipe rec = getInputRecipe();
            if (rec==null || running) return;
            int fuelOffset = 0;
            running = true;
            while (rec!=null && valid() && validFurnacesForRecipe(rec, fuelOffset) && rec.getRecipe().getFuelCost()>fuelOffset){
                try {
                    for (Furnace f : getFurnaces()){
                        ItemStack fuelIS = f.getInventory().getFuel();
                        if (fuelIS.getAmount()>1){
                            fuelIS.setAmount(fuelIS.getAmount()-1);
                        } else {
                            fuelIS.setType(Material.AIR);
                        }
                        f.getInventory().setFuel(fuelIS);
                        f.setBurnTime((short) (factory.getData().getFuelTime()*20));
                        f.update();
                    }
                    TimeUnit.SECONDS.sleep(factory.getData().getFuelTime());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    break;
                }
                rec = getInputRecipe();
                fuelOffset++;
            }
            System.out.println("finished");
            if (rec!=null && valid() && rec.getRecipe().getFuelCost()==fuelOffset){
                rec.updateInventoryToOutput(chest.getBlockInventory());
                System.out.println("set inventory");
            }
            running = false;
        }
    }.runTaskLaterAsynchronously(Mechanization.plugin, 1L);
}
项目:Mechanization-old    文件:WorldFactory.java   
public List<Furnace> getFurnaces(){
    List<Furnace> furnaces = new ArrayList<Furnace>();
    for (Vector3 loc : factory.getFurnaceLocations()){
        Vector3 fur = origin.add(loc.multiply(getRelativity()));
        Block b = world.getBlockAt((int) fur.x,(int) fur.y,(int) fur.z);
        if (b.getType()!=Material.FURNACE){
            Bukkit.getServer().getLogger().info("Failed to get furnace at "+b.getX()+","+b.getY()+","+b.getZ()+" from "+b.getType());
            Bukkit.getServer().getLogger().info("Furnace index "+loc.x+","+loc.y+","+loc.z+" missing.");
            break;
        }
        Furnace f = (Furnace) b.getState();
        furnaces.add(f);
    }
    return furnaces;
}
项目:Mechanization-old    文件:WorldFactory.java   
public boolean validFurnacesForRecipe(MechaFactoryRecipe recipe, int fuelOffset){
    if (getFurnaces().size()==0) return false;
    for (Furnace fur : getFurnaces()){
        FurnaceInventory inv = fur.getInventory();
        if (!(inv.getSmelting()==null || inv.getSmelting().getType()==Material.AIR)) return false; 
        ItemStack fuelIS = fur.getInventory().getFuel();
        if (fuelIS==null || fuelIS.getType()!=Material.COAL || fuelIS.getAmount()<recipe.getRecipe().getFuelCost()-fuelOffset) return false;
    }
    return true;
}
项目:CraftControl    文件:WorkerTask.java   
private void updateChunk(Chunk chunk) {
    BlockState[] tileEntities = chunk.getTileEntities();

    // update tile entities
    for (BlockState tileEntity : tileEntities) {
        if (tileEntity.getType() == Material.FURNACE || tileEntity.getType() == Material.BURNING_FURNACE) {
            updateFurnace((Furnace) tileEntity);
        }
    }
}
项目:CraftControl    文件:FurnaceListener.java   
@EventHandler
public void onFurnaceCookTick(FurnaceCookTickEvent event) {
    Furnace furnace = event.getFurnace();

    if (furnace.hasMetadata("currentPlayer")) {
        Player player = (Player) furnace.getMetadata("currentPlayer").get(0).value();
        ItemStack item = furnace.getInventory().getSmelting();
        if (item != null &&
            !permissionChecker.check(player, "smelt", item.getType()) &&
            !item.getType().equals(Material.AIR)
        ) {
            event.setCancelled(true);
        }
    }
}