/**
* 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;
}
java类org.bukkit.inventory.FurnaceInventory的实例源码
Tool.java 文件源码
项目:StarQuestCode
阅读 24
收藏 0
点赞 0
评论 0
Fuel.java 文件源码
项目:StarQuestCode
阅读 20
收藏 0
点赞 0
评论 0
/**
* 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;
}
}
Pump.java 文件源码
项目:StarQuestCode
阅读 20
收藏 0
点赞 0
评论 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;
}
Pump.java 文件源码
项目:StarQuestCode
阅读 19
收藏 0
点赞 0
评论 0
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();
}
FurnaceRelay.java 文件源码
项目:StarQuestCode
阅读 19
收藏 0
点赞 0
评论 0
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;
}
FurnaceEndpoint.java 文件源码
项目:StarQuestCode
阅读 18
收藏 0
点赞 0
评论 0
/**
* 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);
}
}
FurnaceEndpoint.java 文件源码
项目:StarQuestCode
阅读 23
收藏 0
点赞 0
评论 0
/**
* 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();
}
}
FurnaceEndpoint.java 文件源码
项目:StarQuestCode
阅读 21
收藏 0
点赞 0
评论 0
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;
}
FurnaceEndpoint.java 文件源码
项目:StarQuestCode
阅读 21
收藏 0
点赞 0
评论 0
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;
}
Pump.java 文件源码
项目:StarQuestCode
阅读 20
收藏 0
点赞 0
评论 0
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();
}
Planter.java 文件源码
项目:StarQuestCode
阅读 19
收藏 0
点赞 0
评论 0
private void useTool() throws NoToolException {
if (!useTool)
return;
FurnaceInventory furnaceInventory = ((Furnace) furnace.getBlock().getState()).getInventory();
if (!Tool.useInFurnace(furnaceInventory, planterTool, chestInventory())) {
throw new NoToolException();
}
}
InventoryListener.java 文件源码
项目:McMMOPlus
阅读 20
收藏 0
点赞 0
评论 0
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();
}
WorldFactory.java 文件源码
项目:Mechanization-old
阅读 19
收藏 0
点赞 0
评论 0
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;
}
WorldFactory.java 文件源码
项目:Mechanization-old
阅读 19
收藏 0
点赞 0
评论 0
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;
}
InventoryDragListener.java 文件源码
项目:EpicQuest
阅读 21
收藏 0
点赞 0
评论 0
@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));
}
}
CraftFurnace.java 文件源码
项目:Uranium
阅读 31
收藏 0
点赞 0
评论 0
public FurnaceInventory getInventory() {
return new CraftInventoryFurnace(furnace);
}
ExprFurnaceSlot.java 文件源码
项目:Skript
阅读 22
收藏 0
点赞 0
评论 0
public FurnaceEventSlot(final Event e, final FurnaceInventory invi) {
super(invi, slot);
this.e = e;
}
CraftFurnace.java 文件源码
项目:ThermosRebased
阅读 17
收藏 0
点赞 0
评论 0
public FurnaceInventory getInventory() {
return new CraftInventoryFurnace(furnace);
}
FurnaceBurn.java 文件源码
项目:MinecraftPlugins
阅读 26
收藏 0
点赞 0
评论 0
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);
}
}
CraftFurnace.java 文件源码
项目:Thermos
阅读 19
收藏 0
点赞 0
评论 0
public FurnaceInventory getInventory() {
return new CraftInventoryFurnace(furnace);
}
CraftFurnace.java 文件源码
项目:KCauldron
阅读 20
收藏 0
点赞 0
评论 0
public FurnaceInventory getInventory() {
return new CraftInventoryFurnace(furnace);
}
CraftFurnace.java 文件源码
项目:CauldronGit
阅读 17
收藏 0
点赞 0
评论 0
public FurnaceInventory getInventory() {
return new CraftInventoryFurnace(furnace);
}
CraftFurnace.java 文件源码
项目:Cauldron-Old
阅读 23
收藏 0
点赞 0
评论 0
public FurnaceInventory getInventory() {
return new CraftInventoryFurnace(furnace);
}
CraftFurnace.java 文件源码
项目:Cauldron-Reloaded
阅读 20
收藏 0
点赞 0
评论 0
public FurnaceInventory getInventory() {
return new CraftInventoryFurnace(furnace);
}
CraftFurnace.java 文件源码
项目:FFoKC
阅读 19
收藏 0
点赞 0
评论 0
public FurnaceInventory getInventory() {
return new CraftInventoryFurnace(furnace);
}
CraftFurnace.java 文件源码
项目:CraftBukkit
阅读 21
收藏 0
点赞 0
评论 0
public FurnaceInventory getInventory() {
return new CraftInventoryFurnace(furnace);
}
CraftFurnace.java 文件源码
项目:Craftbukkit
阅读 22
收藏 0
点赞 0
评论 0
public FurnaceInventory getInventory() {
return new CraftInventoryFurnace(furnace);
}
CraftFurnace.java 文件源码
项目:Almura-Server
阅读 21
收藏 0
点赞 0
评论 0
public FurnaceInventory getInventory() {
return new CraftInventoryFurnace(furnace);
}
CraftFurnace.java 文件源码
项目:Tweakkit-Server
阅读 20
收藏 0
点赞 0
评论 0
public FurnaceInventory getInventory() {
return new CraftInventoryFurnace(furnace);
}
CraftFurnace.java 文件源码
项目:Cauldron
阅读 21
收藏 0
点赞 0
评论 0
public FurnaceInventory getInventory() {
return new CraftInventoryFurnace(furnace);
}