/** * Handles removing & dropping the blocks from Tree Feller. * * @param toBeFelled List of Blocks to be removed from the tree * @param player The player using the ability * @param profile The PlayerProfile of the player */ private static void removeBlocks( ArrayList<Block> toBeFelled, Player player, PlayerProfile profile) { if (toBeFelled.size() >= Config.getInstance().getTreeFellerThreshold()) { player.sendMessage(LocaleLoader.getString("Woodcutting.Skills.TreeFellerThreshold")); return; } int xp = 0; ItemStack inHand = player.getItemInHand(); int level = 0; if (inHand.containsEnchantment(Enchantment.DURABILITY)) { level = inHand.getEnchantmentLevel(Enchantment.DURABILITY); } int durabilityLoss = durabilityLossCalulate(toBeFelled, level); /* This is to prevent using wood axes everytime you tree fell */ if (ModChecks.isCustomTool(inHand)) { if (inHand.getDurability() + durabilityLoss >= ModChecks.getToolFromItemStack(inHand).getDurability()) { player.sendMessage(LocaleLoader.getString("Woodcutting.Skills.TreeFeller.Splinter")); int health = player.getHealth(); if (health >= 2) { Combat.dealDamage(player, random.nextInt(health - 1)); } inHand.setDurability((short) (inHand.getType().getMaxDurability())); return; } } else if ((inHand.getDurability() + durabilityLoss >= inHand.getType().getMaxDurability()) || inHand.getType().equals(Material.AIR)) { player.sendMessage(LocaleLoader.getString("Woodcutting.Skills.TreeFeller.Splinter")); int health = player.getHealth(); if (health >= 2) { Combat.dealDamage(player, random.nextInt(health - 1)); } inHand.setDurability((short) (inHand.getType().getMaxDurability())); return; } /* Damage the tool */ inHand.setDurability((short) (inHand.getDurability() + durabilityLoss)); // Prepare ItemStacks ItemStack item = null; ItemStack oak = (new MaterialData(Material.LOG, TreeSpecies.GENERIC.getData())).toItemStack(1); ItemStack spruce = (new MaterialData(Material.LOG, TreeSpecies.REDWOOD.getData())).toItemStack(1); ItemStack birch = (new MaterialData(Material.LOG, TreeSpecies.BIRCH.getData())).toItemStack(1); ItemStack jungle = (new MaterialData(Material.LOG, TreeSpecies.JUNGLE.getData())).toItemStack(1); for (Block x : toBeFelled) { if (Misc.blockBreakSimulate(x, player, true)) { if (Config.getInstance().getBlockModsEnabled() && ModChecks.isCustomLogBlock(x)) { if (ModChecks.isCustomLogBlock(x)) { CustomBlock block = ModChecks.getCustomBlock(x); item = block.getItemDrop(); if (!mcMMO.placeStore.isTrue(x)) { WoodCutting.woodCuttingProcCheck(player, x); xp = block.getXpGain(); } /* Remove the block */ x.setData((byte) 0x0); x.setType(Material.AIR); int minimumDropAmount = block.getMinimumDropAmount(); int maximumDropAmount = block.getMaximumDropAmount(); item = block.getItemDrop(); if (minimumDropAmount != maximumDropAmount) { Misc.dropItems(x.getLocation(), item, minimumDropAmount); Misc.randomDropItems( x.getLocation(), item, 50, maximumDropAmount - minimumDropAmount); } else { Misc.dropItems(x.getLocation(), item, minimumDropAmount); } } else if (ModChecks.isCustomLeafBlock(x)) { CustomBlock block = ModChecks.getCustomBlock(x); item = block.getItemDrop(); final int SAPLING_DROP_CHANCE = 10; /* Remove the block */ x.setData((byte) 0x0); x.setType(Material.AIR); Misc.randomDropItem(x.getLocation(), item, SAPLING_DROP_CHANCE); } } else if (x.getType() == Material.LOG) { Tree tree = (Tree) x.getState().getData(); TreeSpecies species = tree.getSpecies(); switch (species) { case GENERIC: item = oak; break; case REDWOOD: item = spruce; break; case BIRCH: item = birch; break; case JUNGLE: item = jungle; break; default: break; } if (!mcMMO.placeStore.isTrue(x)) { WoodCutting.woodCuttingProcCheck(player, x); switch (species) { case GENERIC: xp += Config.getInstance().getWoodcuttingXPOak(); break; case REDWOOD: xp += Config.getInstance().getWoodcuttingXPSpruce(); break; case BIRCH: xp += Config.getInstance().getWoodcuttingXPBirch(); break; case JUNGLE: xp += Config.getInstance().getWoodcuttingXPJungle() / 2; // Nerf XP from Jungle Trees when using Tree Feller break; default: break; } } /* Remove the block */ x.setData((byte) 0x0); x.setType(Material.AIR); /* Drop the block */ Misc.dropItem(x.getLocation(), item); } else if (x.getType() == Material.LEAVES) { final int SAPLING_DROP_CHANCE = 10; // Drop the right type of sapling item = (new MaterialData(Material.SAPLING, (byte) (x.getData() & 3))).toItemStack(1); Misc.randomDropItem(x.getLocation(), item, SAPLING_DROP_CHANCE); // Remove the block x.setData((byte) 0); x.setType(Material.AIR); } } } if (Permissions.getInstance().woodcutting(player)) { Skills.xpProcessing(player, profile, SkillType.WOODCUTTING, xp); } }
/** * Check for double drops. * * @param player Player breaking the block * @param block The block being broken */ private static void woodCuttingProcCheck(Player player, Block block) { final int MAX_CHANCE = advancedConfig.getMiningDoubleDropChance(); final int MAX_BONUS_LEVEL = advancedConfig.getMiningDoubleDropMaxLevel(); int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.WOODCUTTING); byte type = block.getData(); if ((type & 0x4) == 0x4) type ^= 0x4; if ((type & 0x8) == 0x8) type ^= 0x8; Material mat = Material.getMaterial(block.getTypeId()); int randomChance = 100; int chance = (int) (((double) MAX_CHANCE / (double) MAX_BONUS_LEVEL) * skillLevel); if (chance > MAX_CHANCE) chance = MAX_CHANCE; if (player.hasPermission("mcmmo.perks.lucky.woodcutting")) { randomChance = (int) (randomChance * 0.75); } if (chance > random.nextInt(randomChance) && Permissions.getInstance().woodcuttingDoubleDrops(player)) { Config configInstance = Config.getInstance(); ItemStack item; Location location; if (configInstance.getBlockModsEnabled() && ModChecks.isCustomLogBlock(block)) { CustomBlock customBlock = ModChecks.getCustomBlock(block); int minimumDropAmount = customBlock.getMinimumDropAmount(); int maximumDropAmount = customBlock.getMaximumDropAmount(); item = customBlock.getItemDrop(); location = block.getLocation(); if (minimumDropAmount != maximumDropAmount) { Misc.dropItems(location, item, minimumDropAmount); Misc.randomDropItems(location, item, 50, maximumDropAmount - minimumDropAmount); } else { Misc.dropItems(location, item, minimumDropAmount); } } else { item = (new MaterialData(mat, type)).toItemStack(1); location = block.getLocation(); TreeSpecies species = TreeSpecies.getByData(type); /* Drop the block */ switch (species) { case GENERIC: if (configInstance.getOakDoubleDropsEnabled()) { Misc.dropItem(location, item); } break; case REDWOOD: if (configInstance.getSpruceDoubleDropsEnabled()) { Misc.dropItem(location, item); } break; case BIRCH: if (configInstance.getBirchDoubleDropsEnabled()) { Misc.dropItem(location, item); } break; case JUNGLE: if (configInstance.getJungleDoubleDropsEnabled()) { Misc.dropItem(location, item); } break; default: break; } } } }