예제 #1
0
 @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
 public void onEntityExplode(EntityExplodeEvent e) {
   Iterator<Block> blocks = e.blockList().iterator();
   while (blocks.hasNext()) {
     Block block = blocks.next();
     SlimefunItem item = BlockStorage.check(block);
     if (item != null && item.getName().equalsIgnoreCase("HARDENED_GLASS")) blocks.remove();
     else if (item != null) BlockStorage.retrieve(block);
   }
 }
예제 #2
0
  @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
  public void onBlockBreak(BlockBreakEvent e) {
    List<ItemStack> drops = new ArrayList<ItemStack>();
    SlimefunItem sfItem = BlockStorage.check(e.getBlock());
    ItemStack item = e.getPlayer().getItemInHand();
    int fortune = 1;
    if (sfItem != null && !(sfItem instanceof HandledBlock))
      drops.add(BlockStorage.retrieve(e.getBlock()));
    else if (item != null) {
      if (item.getEnchantments().containsKey(Enchantment.LOOT_BONUS_BLOCKS)
          && !item.getEnchantments().containsKey(Enchantment.SILK_TOUCH)) {
        fortune = main.randomize(item.getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) + 2) - 1;
        if (fortune <= 0) fortune = 1;
        fortune =
            (e.getBlock().getType() == Material.LAPIS_ORE ? 4 + main.randomize(5) : 1)
                * (fortune + 1);
      }

      for (ItemHandler handler : SlimefunItem.getHandlers("BlockBreakHandler")) {
        if (((BlockBreakHandler) handler).onBlockBreak(e, item, fortune, drops)) break;
      }
    }

    if (!item.getEnchantments().containsKey(Enchantment.SILK_TOUCH)
        && e.getBlock().getType().toString().endsWith("_ORE")) {
      if (Talisman.checkFor(e, SlimefunItem.getByName("MINER_TALISMAN"))) {
        if (drops.isEmpty()) drops = (List<ItemStack>) e.getBlock().getDrops();
        for (ItemStack drop : new ArrayList<ItemStack>(drops)) {
          if (!drop.getType().isBlock()) drops.add(new CustomItem(drop, fortune * 2));
        }
      }
    }

    if (!drops.isEmpty()) {
      e.getBlock().setType(Material.AIR);
      for (ItemStack drop : drops) {
        e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), drop);
      }
    }
  }