本文整理匯總了Java中org.bukkit.block.Furnace類的典型用法代碼示例。如果您正苦於以下問題:Java Furnace類的具體用法?Java Furnace怎麽用?Java Furnace使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Furnace類屬於org.bukkit.block包,在下文中一共展示了Furnace類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onSmelt
import org.bukkit.block.Furnace; //導入依賴的package包/類
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()));
}
}
示例2: onFurnaceSmelt
import org.bukkit.block.Furnace; //導入依賴的package包/類
/**
* 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));
}
示例3: startUpdate
import org.bukkit.block.Furnace; //導入依賴的package包/類
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);
}
示例4: get
import org.bukkit.block.Furnace; //導入依賴的package包/類
@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);
}
}
});
}
示例5: getOwner
import org.bukkit.block.Furnace; //導入依賴的package包/類
@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;
}
示例6: updatePearlHolder
import org.bukkit.block.Furnace; //導入依賴的package包/類
/**
* 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);
}
}
示例7: consume
import org.bukkit.block.Furnace; //導入依賴的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;
}
}
示例8: setFurnace
import org.bukkit.block.Furnace; //導入依賴的package包/類
/**
* 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;
}
}
示例9: useEnergy
import org.bukkit.block.Furnace; //導入依賴的package包/類
/**
* 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;
}
示例10: putDrainItem
import org.bukkit.block.Furnace; //導入依賴的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;
}
示例11: stop
import org.bukkit.block.Furnace; //導入依賴的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();
}
示例12: useEnergy
import org.bukkit.block.Furnace; //導入依賴的package包/類
/**
* 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;
}
示例13: doSend
import org.bukkit.block.Furnace; //導入依賴的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;
}
示例14: handle
import org.bukkit.block.Furnace; //導入依賴的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);
}
}
示例15: updateLevels
import org.bukkit.block.Furnace; //導入依賴的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();
}
}