org.bukkit.block.Furnace Java Examples
The following examples show how to use
org.bukkit.block.Furnace.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DisplayProtectionListener.java From QuickShop-Reremake with GNU General Public License v3.0 | 6 votes |
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void block(FurnaceBurnEvent event) { if (!useEnhanceProtection) { return; } if (DisplayItem.getNowUsing() != DisplayType.REALITEM) { return; } final ItemStack itemStack = event.getFuel(); if (DisplayItem.checkIsGuardItemStack(itemStack)) { event.setCancelled(true); Block furnace = event.getBlock(); if (furnace.getState() instanceof Furnace) { Furnace furnace1 = (Furnace) furnace.getState(); sendAlert( "[DisplayGuard] Block " + event.getBlock().getLocation() + " trying burn with DisplayItem."); Util.inventoryCheck(furnace1.getInventory()); } } }
Example #2
Source File: EnhancedFurnaceListener.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onItemSmelt(FurnaceSmeltEvent e) { SlimefunItem sfItem = BlockStorage.check(e.getBlock()); if (sfItem instanceof EnhancedFurnace) { Furnace furnace = (Furnace) e.getBlock().getState(); int amount = furnace.getInventory().getSmelting().getType().toString().endsWith("_ORE") ? ((EnhancedFurnace) sfItem).getOutput() : 1; Optional<ItemStack> result = Optional.ofNullable(furnace.getInventory().getResult()); if (!result.isPresent()) { result = SlimefunPlugin.getMinecraftRecipeService().getFurnaceOutput(furnace.getInventory().getSmelting()); } if (result.isPresent()) { ItemStack item = result.get(); furnace.getInventory().setResult(new CustomItem(item, Math.min(item.getAmount() + amount, item.getMaxStackSize()))); } } }
Example #3
Source File: Furnace_V1_7_R4.java From AnnihilationPro with MIT License | 6 votes |
@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; }
Example #4
Source File: EnhancedFurnace.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
@Override public BlockTicker getItemHandler() { return new BlockTicker() { @Override public void tick(Block b, SlimefunItem item, Config data) { if (b.getType() != Material.FURNACE) { // The Furnace has been destroyed, we can clear the block data BlockStorage.clearBlockInfo(b); } else { Furnace furnace = (Furnace) b.getState(); if (furnace.getCookTime() > 0) { int cookTime = furnace.getCookTime() + getSpeed() * 10; furnace.setCookTime((short) Math.min(cookTime, furnace.getCookTimeTotal() - 1)); furnace.update(true, false); } } } @Override public boolean isSynchronized() { return true; } }; }
Example #5
Source File: TPContainerListener.java From Transport-Pipes with MIT License | 5 votes |
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; }
Example #6
Source File: WarRegen.java From civcraft with GNU General Public License v2.0 | 5 votes |
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); }
Example #7
Source File: FastSmeltingListener.java From UhcCore with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onFurnaceBurn(FurnaceBurnEvent e){ Block block = e.getBlock(); Bukkit.getScheduler().runTaskLater(UhcCore.getPlugin(), new Runnable() { @Override public void run() { // If the furnace is broken stop thread. if (block.getType() == Material.AIR){ return; } Furnace furnace = (Furnace) block.getState(); // If furnace almost stopped burning stop thread. A new FurnaceBurnEvent will be called. if (furnace.getBurnTime() <= 10) { return; } // If no item is cooking don't speed up cooking time but show down thread while waiting for the burning to stop. if (furnace.getCookTime() <= 0){ Bukkit.getScheduler().runTaskLater(UhcCore.getPlugin(), this, 5); return; } // Speed up cooking time by 10 ticks, this happens every 2 ticks (5x the default speed). short newCookTime = (short) (furnace.getCookTime() + speed); // If new cook time is greater than the max cook time of item set to 199. if (newCookTime >= 200){ newCookTime = 199; } furnace.setCookTime(newCookTime); furnace.update(); Bukkit.getScheduler().runTaskLater(UhcCore.getPlugin(), this, 2); } }, 1); }
Example #8
Source File: Kitchen.java From ExoticGarden with GNU General Public License v3.0 | 5 votes |
private static Furnace locateFurnace(Block b) { if (b.getRelative(BlockFace.EAST).getType() == Material.FURNACE) { return (Furnace) b.getRelative(BlockFace.EAST).getState(); } else if (b.getRelative(BlockFace.WEST).getType() == Material.FURNACE) { return (Furnace) b.getRelative(BlockFace.WEST).getState(); } else if (b.getRelative(BlockFace.NORTH).getType() == Material.FURNACE) { return (Furnace) b.getRelative(BlockFace.NORTH).getState(); } else { return (Furnace) b.getRelative(BlockFace.SOUTH).getState(); } }
Example #9
Source File: Camp.java From civcraft with GNU General Public License v2.0 | 5 votes |
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(); }
Example #10
Source File: ObserverModule.java From CardinalPGM with MIT License | 4 votes |
@EventHandler public void onInteraction(PlayerInteractEvent event) { if (testObserver(event.getPlayer())) { event.setCancelled(true); if ((event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) && (event.getPlayer().getInventory().getItemInMainHand() != null && event.getPlayer().getInventory().getItemInMainHand().getType().equals(Material.WRITTEN_BOOK))){ event.setUseInteractedBlock(Event.Result.DENY); event.setUseItemInHand(Event.Result.ALLOW); } if (event.getClickedBlock() != null && !event.getPlayer().isSneaking() && event.getAction() == Action.RIGHT_CLICK_BLOCK) { if (event.getClickedBlock().getType().equals(Material.CHEST) || event.getClickedBlock().getType().equals(Material.TRAPPED_CHEST)) { Inventory chest = Bukkit.createInventory(null, ((Chest) event.getClickedBlock().getState()).getInventory().getSize()); for (int i = 0; i < ((Chest) event.getClickedBlock().getState()).getInventory().getSize(); i++) { chest.setItem(i, ((Chest) event.getClickedBlock().getState()).getInventory().getItem(i)); } event.getPlayer().openInventory(chest); } if (event.getClickedBlock().getType().equals(Material.FURNACE) || event.getClickedBlock().getType().equals(Material.BURNING_FURNACE)) { Inventory furnace = Bukkit.createInventory(null, InventoryType.FURNACE); for (int i = 0; i < ((Furnace) event.getClickedBlock().getState()).getInventory().getSize(); i++) { furnace.setItem(i, ((Furnace) event.getClickedBlock().getState()).getInventory().getItem(i)); } event.getPlayer().openInventory(furnace); } if (event.getClickedBlock().getType().equals(Material.DISPENSER)) { Inventory dispenser = Bukkit.createInventory(null, InventoryType.DISPENSER); for (int i = 0; i < ((Dispenser) event.getClickedBlock().getState()).getInventory().getSize(); i++) { dispenser.setItem(i, ((Dispenser) event.getClickedBlock().getState()).getInventory().getItem(i)); } event.getPlayer().openInventory(dispenser); } if (event.getClickedBlock().getType().equals(Material.DROPPER)) { Inventory dropper = Bukkit.createInventory(null, InventoryType.DROPPER); for (int i = 0; i < ((Dropper) event.getClickedBlock().getState()).getInventory().getSize(); i++) { dropper.setItem(i, ((Dropper) event.getClickedBlock().getState()).getInventory().getItem(i)); } event.getPlayer().openInventory(dropper); } if (event.getClickedBlock().getType().equals(Material.HOPPER)) { Inventory hopper = Bukkit.createInventory(null, InventoryType.HOPPER); for (int i = 0; i < ((Hopper) event.getClickedBlock().getState()).getInventory().getSize(); i++) { hopper.setItem(i, ((Hopper) event.getClickedBlock().getState()).getInventory().getItem(i)); } event.getPlayer().openInventory(hopper); } if (event.getClickedBlock().getType().equals(Material.BREWING_STAND)) { Inventory brewingStand = Bukkit.createInventory(null, InventoryType.BREWING); for (int i = 0; i < ((BrewingStand) event.getClickedBlock().getState()).getInventory().getSize(); i++) { brewingStand.setItem(i, ((BrewingStand) event.getClickedBlock().getState()).getInventory().getItem(i)); } event.getPlayer().openInventory(brewingStand); } if (event.getClickedBlock().getType().equals(Material.BEACON)) { Inventory beacon = Bukkit.createInventory(null, InventoryType.BEACON); for (int i = 0; i < ((Beacon) event.getClickedBlock().getState()).getInventory().getSize(); i++) { beacon.setItem(i, ((Beacon) event.getClickedBlock().getState()).getInventory().getItem(i)); } event.getPlayer().openInventory(beacon); } } } }
Example #11
Source File: WarRegen.java From civcraft with GNU General Public License v2.0 | 4 votes |
private static void restoreBlockFromString(String line) { String[] split = line.split(":"); int type = Integer.valueOf(split[0]); byte data = Byte.valueOf(split[1]); int x = Integer.valueOf(split[2]); int y = Integer.valueOf(split[3]); int z = Integer.valueOf(split[4]); String world = split[5]; Block block = BukkitObjects.getWorld(world).getBlockAt(x,y,z); ItemManager.setTypeId(block, type); ItemManager.setData(block, data, false); // End of basic block info, try to get more now. Inventory inv = null; switch (block.getType()) { case TRAPPED_CHEST: inv = ((Chest)block.getState()).getBlockInventory(); InventorySerializer.StringToInventory(inv, split[6]); break; case CHEST: inv = ((Chest)block.getState()).getBlockInventory(); InventorySerializer.StringToInventory(inv, split[6]); break; case DISPENSER: inv = ((Dispenser)block.getState()).getInventory(); InventorySerializer.StringToInventory(inv, split[6]); break; case BURNING_FURNACE: case FURNACE: inv = ((Furnace)block.getState()).getInventory(); InventorySerializer.StringToInventory(inv, split[6]); break; case DROPPER: inv = ((Dropper)block.getState()).getInventory(); InventorySerializer.StringToInventory(inv, split[6]); break; case HOPPER: inv = ((Hopper)block.getState()).getInventory(); InventorySerializer.StringToInventory(inv, split[6]); break; case SIGN: case SIGN_POST: case WALL_SIGN: Sign sign = (Sign)block.getState(); String[] messages = split[6].split(","); for (int i = 0; i < 4; i++) { if (messages[i] != null) { sign.setLine(i, messages[i]); } } sign.update(); break; default: break; } }
Example #12
Source File: WarRegen.java From civcraft with GNU General Public License v2.0 | 4 votes |
private static String blockToString(Block blk, boolean save_as_air) { if (save_as_air) { return blockAsAir(blk); } else { String str = blockBasicString(blk); Inventory inv = null; switch (blk.getType()) { case TRAPPED_CHEST: case CHEST: inv = ((Chest)blk.getState()).getBlockInventory(); str += blockInventoryString(inv); break; case DISPENSER: inv = ((Dispenser)blk.getState()).getInventory(); str += blockInventoryString(inv); break; case BURNING_FURNACE: case FURNACE: inv = ((Furnace)blk.getState()).getInventory(); str += blockInventoryString(inv); break; case DROPPER: inv = ((Dropper)blk.getState()).getInventory(); str += blockInventoryString(inv); break; case HOPPER: inv = ((Hopper)blk.getState()).getInventory(); str += blockInventoryString(inv); break; case SIGN: case SIGN_POST: case WALL_SIGN: Sign sign = (Sign)blk.getState(); str += blockSignString(sign); break; default: break; } return str; } }
Example #13
Source File: CraftInventoryFurnace.java From Thermos with GNU General Public License v3.0 | 4 votes |
@Override public Furnace getHolder() { return (Furnace) inventory.getOwner(); }
Example #14
Source File: Kitchen.java From ExoticGarden with GNU General Public License v3.0 | 4 votes |
@Override public void onInteract(Player p, Block b) { Block dispenser = b.getRelative(BlockFace.DOWN); Furnace furnace = locateFurnace(dispenser); FurnaceInventory furnaceInventory = furnace.getInventory(); Inventory inv = ((Dispenser) dispenser.getState()).getInventory(); List<ItemStack[]> inputs = RecipeType.getRecipeInputList(this); recipe: for (ItemStack[] input : inputs) { for (int i = 0; i < inv.getContents().length; i++) { if (!SlimefunUtils.isItemSimilar(inv.getContents()[i], input[i], true)) continue recipe; } ItemStack adding = RecipeType.getRecipeOutputList(this, input); if (Slimefun.hasUnlocked(p, adding, true)) { boolean canFit = furnaceInventory.getResult() == null || (furnaceInventory.getResult().getAmount() + adding.getAmount() <= 64 && SlimefunUtils.isItemSimilar(furnaceInventory.getResult(), adding, true)); if (!canFit) { SlimefunPlugin.getLocal().sendMessage(p, "machines.full-inventory", true); return; } for (int i = 0; i < inv.getContents().length; i++) { ItemStack item = inv.getItem(i); if (item != null) { ItemUtils.consumeItem(item, item.getType() == Material.MILK_BUCKET); } } Bukkit.getScheduler().runTaskLater(plugin, () -> p.getWorld().playSound(furnace.getLocation(), Sound.BLOCK_LAVA_EXTINGUISH, 1F, 1F), 55L); for (int i = 1; i < 7; i++) { Bukkit.getScheduler().runTaskLater(plugin, () -> p.getWorld().playSound(furnace.getLocation(), Sound.BLOCK_METAL_PLACE, 7F, 1F), i * 5L); } if (furnaceInventory.getResult() == null) { furnaceInventory.setResult(adding); } else { furnaceInventory.getResult().setAmount(furnaceInventory.getResult().getAmount() + adding.getAmount()); } } return; } SlimefunPlugin.getLocal().sendMessage(p, "machines.pattern-not-found", true); }
Example #15
Source File: Recipes.java From ProRecipes with GNU General Public License v2.0 | 4 votes |
@EventHandler(priority=EventPriority.MONITOR) public void onSmelt(final FurnaceSmeltEvent event){ for(RecipeFurnace rec : fur){ if(rec.toBurn.getType().equals(event.getSource().getType())){ if(rec.match(event.getSource())){ ////System.out.println("Matched"); ////System.out.println("1"); Furnace f = ((Furnace)event.getBlock().getState()); Inventory inv = f.getInventory(); //f.update(); ////System.out.println(rec.result.toString()); FurnaceCraftEvent eventFurnace = new FurnaceCraftEvent(ProRecipes.getAPI().getRecipe(RecipeType.FURNACE, fur.indexOf(rec)), inv, rec.getResult(), event.getSource()); ProRecipes.getPlugin().getServer().getPluginManager().callEvent(eventFurnace); //System.out.println("1"); event.setCancelled(true); break; }else if(!rec.def){ ////System.out.println("2"); ////System.out.println("It doesnt match and it doesn't have an original"); ////////////System.out.println("Doesn't"); event.setResult(null); event.setCancelled(true); ///return; //return; //System.out.println("2"); }else{ ////System.out.println("3"); //////System.out.println("It has an original"); event.setResult(rec.original.getResult()); event.setCancelled(false); //System.out.println("3"); // return; } } } if(event.getSource().getAmount()-1 > 0){ //Check if there's source, then set a timer for the amount of time for new one to finish, then add the old one on after that. ProRecipes.getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(ProRecipes.getPlugin(), new Runnable(){ @Override public void run() { //refreshCraft(((Furnace)event.getBlock().getState()).getInventory()); } }, 1); } ////System.out.println("Cancelled: " + event.isCancelled()); ////System.out.println("Done"); }
Example #16
Source File: FurnaceContainer.java From Transport-Pipes with MIT License | 4 votes |
@Override public void updateBlock() { this.cachedFurnace = ((Furnace) block.getState()); this.cachedInv = cachedFurnace.getInventory(); }
Example #17
Source File: FurnaceContainer.java From Transport-Pipes with MIT License | 4 votes |
public FurnaceContainer(Block block) { super(block); this.chunk = block.getChunk(); this.cachedFurnace = (Furnace) block.getState(); this.cachedInv = cachedFurnace.getInventory(); }
Example #18
Source File: CraftInventoryFurnace.java From Kettle with GNU General Public License v3.0 | 4 votes |
@Override public Furnace getHolder() { return (Furnace) inventory.getOwner(); }
Example #19
Source File: FurnaceInventory.java From Kettle with GNU General Public License v3.0 | votes |
Furnace getHolder();