From 22c9fca9157ad1a4faad0e8eb8d1ce5c87777e9e Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 22 Feb 2012 20:23:42 -0800 Subject: [PATCH] Reworked Tree Feller to take down entire tree. --- Changelog.txt | 2 + .../nossr50/listeners/mcBlockListener.java | 65 +------ .../java/com/gmail/nossr50/skills/Axes.java | 1 - .../com/gmail/nossr50/skills/WoodCutting.java | 173 +++++++++++------- 4 files changed, 115 insertions(+), 126 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 4e4a5df32..77a8c7640 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -16,9 +16,11 @@ Version 1.3.00-dev + Added framework for new Blast Mining skill + Added Fast Food Service subskill to Taming + Re-added mcMMO reporting damage events + = Fixed Tree Feller not giving proper XP for different kinds of trees = Fixed memory leak with mob spawner tracking = Fixed /mcability not respecting permissions = Prettied up new config files + ! Changed Tree Feller to take down entire trees ! Changed mob spawn tracking to use Unique Entity ID instead of Entity Object ! Changed stats command name to mcstats for better plugin compatibility ! Changed god mode to turn off if player enters world where he does not have mcgod permission diff --git a/src/main/java/com/gmail/nossr50/listeners/mcBlockListener.java b/src/main/java/com/gmail/nossr50/listeners/mcBlockListener.java index 4af370214..a45de7f85 100644 --- a/src/main/java/com/gmail/nossr50/listeners/mcBlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/mcBlockListener.java @@ -16,8 +16,6 @@ */ package com.gmail.nossr50.listeners; -import java.util.ArrayList; - import com.gmail.nossr50.Users; import com.gmail.nossr50.m; import com.gmail.nossr50.mcMMO; @@ -29,9 +27,7 @@ import com.gmail.nossr50.datatypes.SkillType; import org.bukkit.Bukkit; import org.bukkit.Material; -import org.bukkit.Statistic; import org.bukkit.block.Block; -import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -198,7 +194,7 @@ public class mcBlockListener implements Listener * WOOD CUTTING */ - if(mcPermissions.getInstance().woodcutting(player)) + if(mcPermissions.getInstance().woodcutting(player) && block.getTypeId() == 17) { if(LoadProperties.woodcuttingrequiresaxe) { @@ -210,62 +206,13 @@ public class mcBlockListener implements Listener { WoodCutting.woodcuttingBlockCheck(player, block, plugin); } - - /* - * IF PLAYER IS USING TREEFELLER - */ - if(mcPermissions.getInstance().woodCuttingAbility(player) - && PP.getTreeFellerMode() - && block.getTypeId() == 17 - && m.blockBreakSimulate(block, player)) + + if(PP.getTreeFellerMode()) { - if(LoadProperties.spoutEnabled) - SpoutStuff.playSoundForPlayer(SoundEffect.EXPLODE, player, block.getLocation()); - - PlayerAnimationEvent armswing = new PlayerAnimationEvent(player); - Bukkit.getPluginManager().callEvent(armswing); - - ArrayList fell = WoodCutting.treeFeller(block, player); - for(Block blockx : fell) - { - if(blockx != null) - { - Material mat = Material.getMaterial(block.getTypeId()); - byte type = 0; - if(block.getTypeId() == 17) - type = block.getData(); - ItemStack item = new ItemStack(mat, 1, (byte)0, type); - if(blockx.getTypeId() == 17) - { - m.mcDropItem(blockx.getLocation(), item); - //XP WOODCUTTING - if(!plugin.misc.blockWatchList.contains(block)) - { - WoodCutting.woodCuttingProcCheck(player, blockx); - PP.addXP(SkillType.WOODCUTTING, LoadProperties.mpine, player); - } - } - if(blockx.getTypeId() == 18) - { - mat = Material.SAPLING; - - item = new ItemStack(mat, 1, (short)0, (byte)(blockx.getData()-8)); - - if(Math.random() * 10 > 9) - m.mcDropItem(blockx.getLocation(), item); - } - if(blockx.getType() != Material.AIR) - player.incrementStatistic(Statistic.MINE_BLOCK, event.getBlock().getType()); - blockx.setType(Material.AIR); - } - } - if(LoadProperties.toolsLoseDurabilityFromAbilities) - { - if(!player.getItemInHand().containsEnchantment(Enchantment.DURABILITY)) - m.damageTool(player, (short) LoadProperties.abilityDurabilityLoss); - } - } + WoodCutting.treeFeller(event, plugin); + } } + /* * EXCAVATION */ diff --git a/src/main/java/com/gmail/nossr50/skills/Axes.java b/src/main/java/com/gmail/nossr50/skills/Axes.java index c189db207..f2a6a4852 100644 --- a/src/main/java/com/gmail/nossr50/skills/Axes.java +++ b/src/main/java/com/gmail/nossr50/skills/Axes.java @@ -170,7 +170,6 @@ public class Axes { continue; } } - else { LivingEntity target = (LivingEntity)derp; diff --git a/src/main/java/com/gmail/nossr50/skills/WoodCutting.java b/src/main/java/com/gmail/nossr50/skills/WoodCutting.java index f572afbb8..f336df2a5 100644 --- a/src/main/java/com/gmail/nossr50/skills/WoodCutting.java +++ b/src/main/java/com/gmail/nossr50/skills/WoodCutting.java @@ -18,12 +18,13 @@ package com.gmail.nossr50.skills; import java.util.ArrayList; import org.bukkit.ChatColor; -import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.enchantments.Enchantment; +import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.player.PlayerAnimationEvent; import org.bukkit.Bukkit; import com.gmail.nossr50.Users; @@ -40,7 +41,108 @@ import org.getspout.spoutapi.sound.SoundEffect; public class WoodCutting { - + public static void treeFeller(BlockBreakEvent event, mcMMO plugin) + { + //Setup vars + Player player = event.getPlayer(); + Block firstBlock = event.getBlock(); + PlayerProfile PP = Users.getProfile(player); + World world = firstBlock.getWorld(); + + //Prepare array + ArrayList toBeFelled = new ArrayList(); + + //NOTE: Tree Feller will cut upwards like how you actually fell trees + processTreeFelling(firstBlock, world, toBeFelled); + removeBlocks(toBeFelled, player, PP, plugin); + } + + private static void removeBlocks(ArrayList toBeFelled, Player player, PlayerProfile PP, mcMMO plugin) + { + for(Block x : toBeFelled) + { + //Stupid NoCheat compatibility stuff + PlayerAnimationEvent armswing = new PlayerAnimationEvent(player); + Bukkit.getPluginManager().callEvent(armswing); + + if(m.blockBreakSimulate(x, player)) + { + if(x.getType() == Material.LOG || x.getType() == Material.LEAVES) + { + if(x.getType() == Material.LOG) + { + byte type = x.getData(); + ItemStack item = new ItemStack(x.getType(), 1, (byte)0, type); + + if(!plugin.misc.blockWatchList.contains(x)) + { + WoodCutting.woodCuttingProcCheck(player, x); + PP.addXP(SkillType.WOODCUTTING, LoadProperties.mpine, player); + } + + //Drop the block + x.getWorld().dropItemNaturally(x.getLocation(), item); + + //Remove the block + x.setData((byte) 0); + x.setType(Material.AIR); + + } else if(x.getType() == Material.LEAVES) + { + Material mat = Material.SAPLING; + ItemStack item = new ItemStack(mat, 1, (short)0, (byte)(x.getData()-8)); + + //1 in 10 chance to drop sapling + if(Math.random() * 10 > 9) + m.mcDropItem(x.getLocation(), item); + + //Remove the block + x.setData((byte) 0); + x.setType(Material.AIR); + } + } + } + } + } + private static boolean treeFellerCompatible(Block block) + { + return block.getType() == Material.LOG || block.getType() == Material.LEAVES; + } + + private static void processTreeFelling(Block currentBlock, World world, ArrayList toBeFelled) + { + int x = currentBlock.getX(), y = currentBlock.getY(), z = currentBlock.getZ(); + + + toBeFelled.add(currentBlock); + + //ORDER = X+, Z+, Z-, X- + Block xPositive = world.getBlockAt(x+1, y, z); + Block xNegative = world.getBlockAt(x-1, y, z); + Block zPositive = world.getBlockAt(x, y, z+1); + Block zNegative = world.getBlockAt(x, y, z-1); + + if(treeFellerCompatible(xPositive) && !toBeFelled.contains(xPositive)) + processTreeFelling(xPositive, world, toBeFelled); + if(treeFellerCompatible(xNegative) && !toBeFelled.contains(xNegative)) + processTreeFelling(xNegative, world, toBeFelled); + if(treeFellerCompatible(zPositive) && !toBeFelled.contains(zPositive)) + processTreeFelling(zPositive, world, toBeFelled); + if(treeFellerCompatible(zNegative) && !toBeFelled.contains(zNegative)) + processTreeFelling(zNegative, world, toBeFelled); + + //Finally go Y+ + Block yPositive = world.getBlockAt(x, y+1, z); + + if(treeFellerCompatible(yPositive)) + { + if(!toBeFelled.contains(yPositive)) + { + processTreeFelling(yPositive, world, toBeFelled); + } + } + } + public static void woodCuttingProcCheck(Player player, Block block) { PlayerProfile PP = Users.getProfile(player); @@ -55,6 +157,7 @@ public class WoodCutting } } } + public static void treeFellerCheck(Player player, Block block) { PlayerProfile PP = Users.getProfile(player); @@ -72,8 +175,10 @@ public class WoodCutting { PP.setAxePreparationMode(false); } + int ticks = 2; int x = PP.getSkillLevel(SkillType.WOODCUTTING); + while(x >= 50) { x-=50; @@ -97,70 +202,6 @@ public class WoodCutting } } } - public static ArrayList treeFeller(Block block, Player player) { - PlayerProfile PP = Users.getProfile(player); - - int radius = 1; - if(PP.getSkillLevel(SkillType.WOODCUTTING) >= 500) - radius++; - if(PP.getSkillLevel(SkillType.WOODCUTTING) >= 950) - radius++; - - ArrayList blockList = new ArrayList(); - ArrayList returnList = new ArrayList(); - - if(block != null) - blockList.add(block); - - boolean isDone = false; - while(isDone == false){ - isDone = addBlocksToTreeFelling(blockList, returnList, radius); - } - - return returnList; - } - public static boolean addBlocksToTreeFelling(ArrayList blocklist, ArrayList toAdd, Integer radius) - { - int u = 0; - for (Block x : blocklist) - { - u++; - if(toAdd.contains(x)) - continue; - Location loc = x.getLocation(); - int vx = x.getX(); - int vy = x.getY(); - int vz = x.getZ(); - - /* - * Run through the blocks around the broken block to see if they qualify to be 'felled' - */ - for (int cx = -radius; cx <= radius; cx++) { - for (int cy = -radius; cy <= radius; cy++) { - for (int cz = -radius; cz <= radius; cz++) { - Block blocktarget = loc.getWorld().getBlockAt(vx + cx, vy + cy, vz + cz); - if (!blocklist.contains(blocktarget) && !toAdd.contains(blocktarget) && (blocktarget.getTypeId() == 17 || blocktarget.getTypeId() == 18)) { - toAdd.add(blocktarget); - } - } - } - } - } - /* - * Add more blocks to blocklist so they can be 'felled' - */ - for(Block xx : toAdd) - { - if(!blocklist.contains(xx)) - blocklist.add(xx); - } - if(u >= blocklist.size()) - { - return true; - } else { - return false; - } - } public static void woodcuttingBlockCheck(Player player, Block block, mcMMO plugin) {