// test and verification private void testTreeCalcDrop( final Material itemInHand, final Material block, final int amount, final TreeSpecies species) { ItemStack stack = testTreeCalcDrop(itemInHand, block, species); // TODO correct this once new trees are implemented correctly TreeSpecies tree = null; switch (stack.getType()) { case WOOD: tree = TreeSpecies.getByData(stack.getData().getData()); break; case LOG: tree = ((Tree) stack.getData()).getSpecies(); break; case LOG_2: tree = TreeSpecies.getByData((byte) (4 + (stack.getData().getData() & 3))); break; default: break; } Assert.assertEquals(species, tree); Assert.assertEquals(block, stack.getType()); Assert.assertEquals(amount, stack.getAmount()); }
/** * Check XP gain for woodcutting. * * @param player The player breaking the block * @param block The block being broken */ public static void woodcuttingBlockCheck(Player player, Block block) { PlayerProfile profile = Users.getProfile(player); int xp = 0; if (mcMMO.placeStore.isTrue(block)) { return; } if (Config.getInstance().getBlockModsEnabled() && ModChecks.isCustomLogBlock(block)) { xp = ModChecks.getCustomBlock(block).getXpGain(); } else { byte type = block.getData(); if ((type & 0x4) == 0x4) type ^= 0x4; if ((type & 0x8) == 0x8) type ^= 0x8; TreeSpecies species = TreeSpecies.getByData(type); // Apparently species can be null in certain cases (custom server mods?) // https://github.com/mcMMO-Dev/mcMMO/issues/229 if (species == null) return; 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(); break; default: break; } } WoodCutting.woodCuttingProcCheck(player, block); 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; } } } }
/** * Handle the calculations from Tree Feller. * * @param currentBlock The current block to be removed * @param toBeFelled The list of blocks left to be removed */ private static void processTreeFelling(Block currentBlock, ArrayList<Block> toBeFelled) { Material type = currentBlock.getType(); if (toBeFelled.size() >= Config.getInstance().getTreeFellerThreshold()) { return; } if (type.equals(Material.LOG) || type.equals(Material.LEAVES)) { toBeFelled.add(currentBlock); } else if (Config.getInstance().getBlockModsEnabled() && (ModChecks.isCustomLogBlock(currentBlock) || ModChecks.isCustomLeafBlock(currentBlock))) { toBeFelled.add(currentBlock); } Block xPositive = currentBlock.getRelative(1, 0, 0); Block xNegative = currentBlock.getRelative(-1, 0, 0); Block zPositive = currentBlock.getRelative(0, 0, 1); Block zNegative = currentBlock.getRelative(0, 0, -1); Block yPositive = currentBlock.getRelative(0, 1, 0); if (!mcMMO.placeStore.isTrue(currentBlock)) { if (!isTooAggressive(currentBlock, xPositive) && BlockChecks.treeFellerCompatible(xPositive) && !toBeFelled.contains(xPositive)) { processTreeFelling(xPositive, toBeFelled); } if (!isTooAggressive(currentBlock, xNegative) && BlockChecks.treeFellerCompatible(xNegative) && !toBeFelled.contains(xNegative)) { processTreeFelling(xNegative, toBeFelled); } if (!isTooAggressive(currentBlock, zPositive) && BlockChecks.treeFellerCompatible(zPositive) && !toBeFelled.contains(zPositive)) { processTreeFelling(zPositive, toBeFelled); } if (!isTooAggressive(currentBlock, zNegative) && BlockChecks.treeFellerCompatible(zNegative) && !toBeFelled.contains(zNegative)) { processTreeFelling(zNegative, toBeFelled); } } byte data = currentBlock.getData(); if ((data & 0x4) == 0x4) data ^= 0x4; if ((data & 0x8) == 0x8) data ^= 0x8; if (TreeSpecies.getByData(data) == TreeSpecies.JUNGLE) { Block corner1 = currentBlock.getRelative(1, 0, 1); Block corner2 = currentBlock.getRelative(1, 0, -1); Block corner3 = currentBlock.getRelative(-1, 0, 1); Block corner4 = currentBlock.getRelative(-1, 0, -1); if (!mcMMO.placeStore.isTrue(currentBlock)) { if (!isTooAggressive(currentBlock, corner1) && BlockChecks.treeFellerCompatible(corner1) && !toBeFelled.contains(corner1)) { processTreeFelling(corner1, toBeFelled); } if (!isTooAggressive(currentBlock, corner2) && BlockChecks.treeFellerCompatible(corner2) && !toBeFelled.contains(corner2)) { processTreeFelling(corner2, toBeFelled); } if (!isTooAggressive(currentBlock, corner3) && BlockChecks.treeFellerCompatible(corner3) && !toBeFelled.contains(corner3)) { processTreeFelling(corner3, toBeFelled); } if (!isTooAggressive(currentBlock, corner4) && BlockChecks.treeFellerCompatible(corner4) && !toBeFelled.contains(corner4)) { processTreeFelling(corner4, toBeFelled); } } } if (BlockChecks.treeFellerCompatible(yPositive)) { if (!mcMMO.placeStore.isTrue(currentBlock) && !toBeFelled.contains(yPositive)) { processTreeFelling(yPositive, toBeFelled); } } }