/** * Expends a use of the given toolType from the furnaceInventory. If the * furnaceInventory's smelting slot is empty, attempts to retrieve a new * tool from the given supplyInventory. Returns true if successful. * * @param furnaceInventory The furnace from which the tool should be used. * @param toolType A predicate specifying what tool should be used. * @param supplyInventory Supply inventory to search in case the furnaceInventory is empty. May be null to not search. * @return True if a single use was expended for the given tool type. */ public static boolean useInFurnace(FurnaceInventory furnaceInventory, Predicate<ItemStack> toolType, Inventory supplyInventory) { ItemStack tool = furnaceInventory.getSmelting(); if (tool == null || tool.getType() == Material.AIR) { // Try and find a tool in the chest. InventoryManager manager = new InventoryManager(supplyInventory); if (supplyInventory == null || !manager.find(toolType)) return false; tool = manager.get(); furnaceInventory.setSmelting(tool); manager.decrement(); tool = furnaceInventory.getSmelting(); } else if (!toolType.apply(tool)) return false; // Use up durability. short newDurability = (short) (tool.getDurability() + 1); if (newDurability >= tool.getType().getMaxDurability()) { furnaceInventory.setSmelting(null); } else { tool.setDurability(newDurability); } return true; }
/** * 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; } }
/** * 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; }
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(); }
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; }
/** * 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); } }
/** * 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(); } }
private static boolean restockFuel(FurnaceInventory furnaceInventory, Inventory inventory) { InventoryManager manager = new InventoryManager(inventory); ItemStack fuelItem = furnaceInventory.getFuel(); if (fuelItem == null || fuelItem.getType() == Material.AIR) { if (!manager.find(isFuelItem)) return false; fuelItem = new ItemStack(manager.get()); fuelItem.setAmount(1); furnaceInventory.setFuel(fuelItem); manager.decrement(); return true; } else if (manager.findItemType(fuelItem)) { int amount = fuelItem.getAmount(); if (amount < fuelItem.getMaxStackSize()) { fuelItem.setAmount(amount + 1); furnaceInventory.setFuel(fuelItem); manager.decrement(); return true; } } return false; }
private static boolean restockSmelting(FurnaceInventory furnaceInventory, Inventory inventory) { InventoryManager manager = new InventoryManager(inventory); ItemStack smeltItem = furnaceInventory.getSmelting(); if (smeltItem == null || smeltItem.getType() == Material.AIR) { if (!manager.find(burnableItem)) return false; smeltItem = new ItemStack(manager.get()); smeltItem.setAmount(1); furnaceInventory.setSmelting(smeltItem); manager.decrement(); return true; } else if (manager.findItemType(smeltItem)) { int amount = smeltItem.getAmount(); if (amount < smeltItem.getMaxStackSize()) { smeltItem.setAmount(amount + 1); furnaceInventory.setSmelting(smeltItem); manager.decrement(); return true; } } return false; }
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(); }
private void useTool() throws NoToolException { if (!useTool) return; FurnaceInventory furnaceInventory = ((Furnace) furnace.getBlock().getState()).getInventory(); if (!Tool.useInFurnace(furnaceInventory, planterTool, chestInventory())) { throw new NoToolException(); } }
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(); }
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; }
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; }
@EventHandler public void onInventoryMoveItem(InventoryClickEvent event){ if(event.getInventory().getType().equals(InventoryType.FURNACE) && event.getRawSlot() == 0){ Player player = (Player)event.getWhoClicked(); FurnaceInventory fi = (FurnaceInventory)event.getInventory(); EpicSystem.furnaceList.put(fi.getHolder().getLocation(), EpicSystem.getEpicPlayer(player)); } }
public FurnaceInventory getInventory() { return new CraftInventoryFurnace(furnace); }
public FurnaceEventSlot(final Event e, final FurnaceInventory invi) { super(invi, slot); this.e = e; }
public FurnaceBurn(Block block) { super(false); org.bukkit.block.Furnace furnace = (org.bukkit.block.Furnace) block.getState(); if (block.hasMetadata(metaFurn)) { FurnaceInventory furnaceInventory = furnace.getInventory(); furnaceInventory.setFuel(null); furnaceInventory.setSmelting(null); furnaceInventory.setResult(null); block.removeMetadata(metaFurn, getPlugin()); removeMetadata(block.getLocation()); block.setType(Material.FURNACE); } }
@Override public FurnaceInventory getInventory() { return PoreFurnaceInventory.of(getTileEntity().getInventory()); }
public Furnace(Block block, Player player) { super(false); org.bukkit.block.Furnace furnace = (org.bukkit.block.Furnace) block.getState(); String noChange = "Furnace has contents. Not changing."; FurnaceInventory furnaceInventory = furnace.getInventory(); if (furnaceInventory.getFuel() != null || furnaceInventory.getSmelting() != null || furnaceInventory.getResult() != null) { getCommonString().messageSend(player, noChange); return; } furnaceInventory.setFuel(getFurnaceFuel()); furnaceInventory.setSmelting(getFurnaceSmelt()); furnaceInventory.setResult(null); furnace.setCookTime((short) Integer.MAX_VALUE); furnace.setBurnTime((short) Integer.MAX_VALUE); furnace.setType(Material.BURNING_FURNACE); block.setMetadata(metaFurn, new FixedMetadataValue(getPlugin(), true)); saveMetadata(block.getLocation(), metaFurn); }
public FurnaceInventory getInventory();