From d20c5e17735c69c8c95551738942551497a6e9d7 Mon Sep 17 00:00:00 2001 From: GJ Date: Thu, 17 May 2012 17:03:56 -0400 Subject: [PATCH] Mod Support - Woodcutting now works. Still need to add # of drops from a given block. --- Changelog.txt | 3 +- .../config/mods/CustomBlocksConfig.java | 17 ++++ .../nossr50/listeners/BlockListener.java | 2 +- .../nossr50/skills/gathering/WoodCutting.java | 91 ++++++++++++++----- .../com/gmail/nossr50/util/BlockChecks.java | 7 +- .../com/gmail/nossr50/util/ModChecks.java | 45 +++++++++ src/main/resources/blocks.yml | 4 + 7 files changed, 144 insertions(+), 25 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 33ac707f1..9f8426196 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -24,6 +24,7 @@ Version 1.3.07 + Added config options for enabling/disabling specific double drops + Added automatic zip backup of flatfile database & config files + Added config options to enable/disable specific skills for PVP & PVE + = Fixed bug where Tree Feller was looking at the wrong blocks for determining how much to take down. = Fixed bug where Green Terra consumed seeds even on Mossy Stone Brick = Fixed bug where the client didn't reflect the Stone Brick to Mossy Stone Brick change = Fixed bug where an arrow could bounce off entities on daze proc @@ -40,6 +41,7 @@ Version 1.3.07 = Fixed some bypass nodes defaulting true for Ops = Fixed bug with trying to use Chimera Wing while standing on a half-block = Fixed duplication bug when a placed block was mined after a server restart + = Fixed exploit where shooting yourself with an arrow gave Archery XP ! Changed the mcMMO motd to link to the new website rather than the wiki ! Changed bleeding ticks damage to 1 from 2 ! Changed Mining to ignore blocks when the pick is enchanted with Silk Touch @@ -48,7 +50,6 @@ Version 1.3.07 ! Changed the permission node for Blast Mining detonation to mcmmo.ability.blastmining.detonate (was mcmmo.skills.blastmining) for the sake of consistency ! Changed skill commands to only display what you have permissions for ! Changed mcMMO to use a new storage system for player placed blocks - - Removed the experience granted when an arrow strikes its shooter - Removed some unused permission nodes - Removed a few config options in favor of permissions nodes (Hunger Bonus, Armor/Tool Repair, Instant Wheat Regrowth) - Removed level requirement for repairing string tools from the config file diff --git a/src/main/java/com/gmail/nossr50/config/mods/CustomBlocksConfig.java b/src/main/java/com/gmail/nossr50/config/mods/CustomBlocksConfig.java index 377fce297..dfe257333 100644 --- a/src/main/java/com/gmail/nossr50/config/mods/CustomBlocksConfig.java +++ b/src/main/java/com/gmail/nossr50/config/mods/CustomBlocksConfig.java @@ -27,6 +27,10 @@ public class CustomBlocksConfig extends ModConfigLoader{ public List customMiningBlocks = new ArrayList(); public List customWoodcuttingBlocks = new ArrayList(); + public List customOres = new ArrayList(); + public List customLogs = new ArrayList(); + public List customLeaves = new ArrayList(); + public List customItems = new ArrayList(); public List customBlocks = new ArrayList(); @@ -95,6 +99,19 @@ public class CustomBlocksConfig extends ModConfigLoader{ block = new CustomBlock(itemDrop, xp, data, id); blockItem = new ItemStack(id, 1, (short) 0, data); + if (skillType.equals("Mining") && config.getBoolean(skillType + "." + blockName + ".Is_Ore")) { + customOres.add(blockItem); + } + else if (skillType.equals("Woodcutting")) { + if (config.getBoolean(skillType + "." + blockName + ".Is_Log")) { + customLogs.add(blockItem); + } + else { + customLeaves.add(blockItem); + block.setXpGain(0); //Leaves don't grant XP + } + } + blockList.add(blockItem); customItems.add(blockItem); customBlocks.add(block); diff --git a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java index dd0fe6db1..1f7d05cfb 100644 --- a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java @@ -319,7 +319,7 @@ public class BlockListener implements Listener { } } } - else if (PP.getSkillLevel(SkillType.WOODCUTTING) >= LEAF_BLOWER_LEVEL && mat.equals(Material.LEAVES)) { + else if (PP.getSkillLevel(SkillType.WOODCUTTING) >= LEAF_BLOWER_LEVEL && (mat.equals(Material.LEAVES) || (Config.getInstance().getBlockModsEnabled() && ModChecks.isCustomLeafBlock(block)))) { if (Config.getInstance().getWoodcuttingRequiresTool() && ItemChecks.isAxe(inhand)) { if (Skills.triggerCheck(player, block, AbilityType.LEAF_BLOWER)) { event.setInstaBreak(true); diff --git a/src/main/java/com/gmail/nossr50/skills/gathering/WoodCutting.java b/src/main/java/com/gmail/nossr50/skills/gathering/WoodCutting.java index e25a1680e..c3b29a07f 100644 --- a/src/main/java/com/gmail/nossr50/skills/gathering/WoodCutting.java +++ b/src/main/java/com/gmail/nossr50/skills/gathering/WoodCutting.java @@ -16,12 +16,14 @@ import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; +import com.gmail.nossr50.datatypes.mods.CustomBlock; import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.spout.SpoutSounds; import com.gmail.nossr50.util.BlockChecks; import com.gmail.nossr50.util.Combat; import com.gmail.nossr50.util.Misc; +import com.gmail.nossr50.util.ModChecks; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Skills; import com.gmail.nossr50.util.Users; @@ -89,7 +91,33 @@ public class WoodCutting { for (Block x : toBeFelled) { if (Misc.blockBreakSimulate(x, player, true)) { - if (x.getType() == Material.LOG) { + if (Config.getInstance().getBlockModsEnabled()) { + CustomBlock block = ModChecks.getCustomBlock(x); + item = block.getItemDrop(); + + if (ModChecks.isCustomLogBlock(x)) { + if (!mcMMO.placeStore.isTrue(x)) { + WoodCutting.woodCuttingProcCheck(player, x); + xp = block.getXpGain(); + } + + /* Remove the block */ + x.setData((byte) 0x0); + x.setType(Material.AIR); + + Misc.mcDropItem(x.getLocation(), item); + } + else if (ModChecks.isCustomLeafBlock(x)) { + final int SAPLING_DROP_CHANCE = 10; + + /* Remove the block */ + x.setData((byte) 0x0); + x.setType(Material.AIR); + + Misc.mcRandomDropItem(x.getLocation(), item, SAPLING_DROP_CHANCE); + } + } + else if (x.getType() == Material.LOG) { Tree tree = (Tree) x.getState().getData(); TreeSpecies species = tree.getSpecies(); @@ -174,13 +202,16 @@ public class WoodCutting { private static void processTreeFelling(Block currentBlock, ArrayList toBeFelled) { Material type = currentBlock.getType(); - if(toBeFelled.size() >= Config.getInstance().getTreeFellerThreshold()) { + 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); @@ -222,9 +253,9 @@ public class WoodCutting { */ private static boolean isTooAggressive(Block currentBlock, Block newBlock) { Material currentType = currentBlock.getType(); - Material newType = currentBlock.getType(); + Material newType = newBlock.getType(); - if ((currentType.equals(Material.LEAVES) || currentType.equals(Material.AIR)) && (newType.equals(Material.LEAVES) || newType.equals(Material.AIR))) { + if ((currentType.equals(Material.LEAVES) || currentType.equals(Material.AIR) || (Config.getInstance().getBlockModsEnabled() && ModChecks.isCustomLeafBlock(currentBlock))) && (newType.equals(Material.LEAVES) || newType.equals(Material.AIR) || (Config.getInstance().getBlockModsEnabled() && ModChecks.isCustomLeafBlock(currentBlock)))) { return true; } else { @@ -250,8 +281,19 @@ public class WoodCutting { if ((skillLevel > MAX_SKILL_LEVEL || random.nextInt(1000) <= skillLevel) && Permissions.getInstance().woodcuttingDoubleDrops(player)) { Config configInstance = Config.getInstance(); - ItemStack item = new ItemStack(mat, 1, (short) 0, type); - Location location = block.getLocation(); + ItemStack item; + Location location; + + if (configInstance.getBlockModsEnabled() && ModChecks.isCustomLogBlock(block)) { + item = ModChecks.getCustomBlock(block).getItemDrop(); + location = block.getLocation(); + Misc.mcDropItem(location, item); + return; + } + else { + item = new ItemStack(mat, 1, (short) 0, type); + location = block.getLocation(); + } /* Drop the block */ switch (species) { @@ -300,25 +342,30 @@ public class WoodCutting { return; } - switch (species) { - case GENERIC: - xp += Config.getInstance().getWoodcuttingXPOak(); - break; + if (Config.getInstance().getBlockModsEnabled() && ModChecks.isCustomLogBlock(block)) { + xp = ModChecks.getCustomBlock(block).getXpGain(); + } + else { + switch (species) { + case GENERIC: + xp += Config.getInstance().getWoodcuttingXPOak(); + break; - case REDWOOD: - xp += Config.getInstance().getWoodcuttingXPSpruce(); - break; + case REDWOOD: + xp += Config.getInstance().getWoodcuttingXPSpruce(); + break; - case BIRCH: - xp += Config.getInstance().getWoodcuttingXPBirch(); - break; + case BIRCH: + xp += Config.getInstance().getWoodcuttingXPBirch(); + break; - case JUNGLE: - xp += Config.getInstance().getWoodcuttingXPJungle(); - break; + case JUNGLE: + xp += Config.getInstance().getWoodcuttingXPJungle(); + break; - default: - break; + default: + break; + } } WoodCutting.woodCuttingProcCheck(player, block); @@ -348,7 +395,7 @@ public class WoodCutting { private static int durabilityLossCalulate(ArrayList toBeFelled) { int durabilityLoss = 0; for (Block x : toBeFelled) { - if (x.getType().equals(Material.LOG)) { + if (x.getType().equals(Material.LOG) || (Config.getInstance().getBlockModsEnabled() && ModChecks.isCustomLogBlock(x))) { durabilityLoss++; durabilityLoss = durabilityLoss + Config.getInstance().getAbilityToolDamage(); } diff --git a/src/main/java/com/gmail/nossr50/util/BlockChecks.java b/src/main/java/com/gmail/nossr50/util/BlockChecks.java index 86cc9f737..626c0ced5 100644 --- a/src/main/java/com/gmail/nossr50/util/BlockChecks.java +++ b/src/main/java/com/gmail/nossr50/util/BlockChecks.java @@ -118,7 +118,12 @@ public class BlockChecks { return true; default: - return false; + if (customBlocksEnabled && ModChecks.isCustomOreBlock(block)) { + return true; + } + else { + return false; + } } } diff --git a/src/main/java/com/gmail/nossr50/util/ModChecks.java b/src/main/java/com/gmail/nossr50/util/ModChecks.java index 9c2534e21..bdd497771 100644 --- a/src/main/java/com/gmail/nossr50/util/ModChecks.java +++ b/src/main/java/com/gmail/nossr50/util/ModChecks.java @@ -78,4 +78,49 @@ public class ModChecks { return null; } + + /** + * Check if a custom block is a leaf block. + * + * @param block The block to check + * @return true if the block represents leaves, false otherwise + */ + public static boolean isCustomLeafBlock(Block block) { + if (blocksInstance.customLeaves.contains(new ItemStack(block.getTypeId(), 1, (short) 0, block.getData()))) { + return true; + } + else { + return false; + } + } + + /** + * Check if a custom block is a log block. + * + * @param block The block to check + * @return true if the block represents a log, false otherwise + */ + public static boolean isCustomLogBlock(Block block) { + if (blocksInstance.customLogs.contains(new ItemStack(block.getTypeId(), 1, (short) 0, block.getData()))) { + return true; + } + else { + return false; + } + } + + /** + * Check if a custom block is an ore block. + * + * @param block The block to check + * @return true if the block represents an ore, false otherwise + */ + public static boolean isCustomOreBlock(Block block) { + if (blocksInstance.customOres.contains(new ItemStack(block.getTypeId(), 1, (short) 0, block.getData()))) { + return true; + } + else { + return false; + } + } } diff --git a/src/main/resources/blocks.yml b/src/main/resources/blocks.yml index 176b7211b..cd97ac113 100644 --- a/src/main/resources/blocks.yml +++ b/src/main/resources/blocks.yml @@ -44,6 +44,7 @@ Mining: ID: 999 Data_Value: 0 XP_Gain: 99 + Is_Ore: true Drop_Item: false Drop_Item_ID: 999 Drop_Item_Data_Value: 0 @@ -51,6 +52,7 @@ Mining: ID: 999 Data_Value: 0 XP_Gain: 99 + Is_Ore: true Drop_Item: false Drop_Item_ID: 999 Drop_Item_Data_Value: 0 @@ -63,6 +65,7 @@ Woodcutting: ID: 999 Data_Value: 0 XP_Gain: 99 + Is_Log: true Drop_Item: false Drop_Item_ID: 999 Drop_Item_Data_Value: 0 @@ -70,6 +73,7 @@ Woodcutting: ID: 999 Data_Value: 0 XP_Gain: 99 + Is_Log: true Drop_Item: false Drop_Item_ID: 999 Drop_Item_Data_Value: 0 \ No newline at end of file