本文整理汇总了Java中org.bukkit.inventory.FurnaceInventory类的典型用法代码示例。如果您正苦于以下问题:Java FurnaceInventory类的具体用法?Java FurnaceInventory怎么用?Java FurnaceInventory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FurnaceInventory类属于org.bukkit.inventory包,在下文中一共展示了FurnaceInventory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: useInFurnace
import org.bukkit.inventory.FurnaceInventory; //导入依赖的package包/类
/**
* 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;
}
示例2: consume
import org.bukkit.inventory.FurnaceInventory; //导入依赖的package包/类
/**
* 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;
}
}
示例3: putDrainItem
import org.bukkit.inventory.FurnaceInventory; //导入依赖的package包/类
/**
* 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;
}
示例4: stop
import org.bukkit.inventory.FurnaceInventory; //导入依赖的package包/类
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();
}
示例5: doSend
import org.bukkit.inventory.FurnaceInventory; //导入依赖的package包/类
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;
}
示例6: handle
import org.bukkit.inventory.FurnaceInventory; //导入依赖的package包/类
/**
* 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);
}
}
示例7: updateLevels
import org.bukkit.inventory.FurnaceInventory; //导入依赖的package包/类
/**
* 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();
}
}
示例8: restockFuel
import org.bukkit.inventory.FurnaceInventory; //导入依赖的package包/类
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;
}
示例9: restockSmelting
import org.bukkit.inventory.FurnaceInventory; //导入依赖的package包/类
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;
}
示例10: run
import org.bukkit.inventory.FurnaceInventory; //导入依赖的package包/类
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();
}
示例11: useTool
import org.bukkit.inventory.FurnaceInventory; //导入依赖的package包/类
private void useTool() throws NoToolException {
if (!useTool)
return;
FurnaceInventory furnaceInventory = ((Furnace) furnace.getBlock().getState()).getInventory();
if (!Tool.useInFurnace(furnaceInventory, planterTool, chestInventory())) {
throw new NoToolException();
}
}
示例12: processInventoryOpenOrCloseEvent
import org.bukkit.inventory.FurnaceInventory; //导入依赖的package包/类
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();
}
示例13: takeFurnaceFuel
import org.bukkit.inventory.FurnaceInventory; //导入依赖的package包/类
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;
}
示例14: validFurnacesForRecipe
import org.bukkit.inventory.FurnaceInventory; //导入依赖的package包/类
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;
}
示例15: onInventoryMoveItem
import org.bukkit.inventory.FurnaceInventory; //导入依赖的package包/类
@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));
}
}