From 2373ca82badca87d9dfe3ebad19918d594f8ddcf Mon Sep 17 00:00:00 2001 From: GJ Date: Mon, 25 Feb 2013 09:58:25 -0500 Subject: [PATCH] Added "Shroom Thumb" ability to Herbalism. Closes #724 --- Changelog.txt | 1 + .../gmail/nossr50/config/AdvancedConfig.java | 3 + .../nossr50/listeners/PlayerListener.java | 6 ++ .../nossr50/skills/herbalism/Herbalism.java | 59 +++++++++++++++++++ .../skills/herbalism/HerbalismCommand.java | 27 ++++++++- .../com/gmail/nossr50/util/BlockChecks.java | 17 ++++++ .../com/gmail/nossr50/util/Permissions.java | 1 + src/main/resources/advanced.yml | 5 ++ .../resources/locale/locale_en_US.properties | 4 ++ src/main/resources/plugin.yml | 3 + 10 files changed, 124 insertions(+), 2 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index f1caec032..75bb0f930 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -39,6 +39,7 @@ Version 1.4.00-dev + Added ability for config files to automatically update with new keys, and prune out old ones + Added config option to make .new config files instead over writing over old ones when updating + Added "Holy Hound" ability to Taming + + Added "Shroom Thumb" ability to Herbalism = Fixed Green Thumb on wheat not working properly at rank 4 = Fixed Green Thumb and Green Terra consuming twice the amount of seed needed = Fixed Green Terra not also checking Green Thumb permissions diff --git a/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java b/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java index 91a270c1b..9c2750fc4 100644 --- a/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java +++ b/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java @@ -111,6 +111,9 @@ public class AdvancedConfig extends AutoUpdateConfigLoader { public double getHylianLuckChanceMax() { return config.getDouble("Skills.Herbalism.HylianLuck_ChanceMax", 10.0D); } public int getHylianLuckMaxLevel() { return config.getInt("Skills.Herbalism.HylianLuck_MaxBonusLevel", 1000); } + public double getShroomThumbChanceMax() { return config.getDouble("Skills.Herbalism.ShroomThumb_ChanceMax", 50.0D); } + public int getShroomThumbMaxLevel() { return config.getInt("Skills.Herbalism.ShroomThumb_MaxBonusLevel", 1500); } + /* MINING */ public double getMiningDoubleDropChance() { return config.getDouble("Skills.Mining.DoubleDrops_ChanceMax", 100.0D); } public int getMiningDoubleDropMaxLevel() { return config.getInt("Skills.Mining.DoubleDrops_MaxBonusLevel", 1000); } diff --git a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index a1e5d4449..b5b136a2f 100644 --- a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -363,6 +363,12 @@ public class PlayerListener implements Listener { } } + /* SHROOM THUMB CHECK */ + else if (BlockChecks.canMakeShroomy(blockState)) { + if (Herbalism.processGreenThumbBlocks(blockState, player) && SkillTools.blockBreakSimulate(block, player, false)) { + blockState.update(true); + } + } break; case RIGHT_CLICK_AIR: diff --git a/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java b/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java index 5594e515f..61f69e361 100644 --- a/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java +++ b/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java @@ -27,6 +27,7 @@ import com.gmail.nossr50.skills.utilities.SkillTools; import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; +import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.Users; public class Herbalism { @@ -46,6 +47,9 @@ public class Herbalism { public static double hylianLuckMaxChance = AdvancedConfig.getInstance().getHylianLuckChanceMax(); public static int hylianLuckMaxLevel = AdvancedConfig.getInstance().getHylianLuckMaxLevel(); + public static double shroomThumbMaxChance = AdvancedConfig.getInstance().getShroomThumbChanceMax(); + public static int shroomThumbMaxLevel = AdvancedConfig.getInstance().getShroomThumbMaxLevel(); + /** * Handle the farmers diet skill. * @@ -314,4 +318,59 @@ public class Herbalism { player.sendMessage(LocaleLoader.getString("Herbalism.HylianLuck")); return true; } + + /** + * Process the Shroom Thumb ability. + * + * @param blockState The {@link BlockState} to check ability activation for + * @param player The {@link Player} using this ability + * @return true if the ability was successful, false otherwise + */ + public static boolean processShroomThumb(BlockState blockState, Player player) { + PlayerInventory playerInventory = player.getInventory(); + + if (!playerInventory.contains(Material.BROWN_MUSHROOM)) { + player.sendMessage(LocaleLoader.getString("Skills.NeedMore", StringUtils.getPrettyItemString(Material.BROWN_MUSHROOM))); + return false; + } + + if (!playerInventory.contains(Material.RED_MUSHROOM)) { + player.sendMessage(LocaleLoader.getString("Skills.NeedMore", StringUtils.getPrettyItemString(Material.RED_MUSHROOM))); + return false; + } + + playerInventory.removeItem(new ItemStack(Material.BROWN_MUSHROOM)); + playerInventory.removeItem(new ItemStack(Material.RED_MUSHROOM)); + player.updateInventory(); + + if (!SkillTools.activationSuccessful(player, SkillType.HERBALISM, shroomThumbMaxChance, shroomThumbMaxLevel)) { + player.sendMessage(LocaleLoader.getString("Herbalism.Ability.ShroomThumb.Fail")); + return false; + } + + return convertShroomThumb(blockState, player); + } + + /** + * Convert blocks affected by the Green Thumb & Green Terra abilities. + * + * @param blockState The {@link BlockState} to check ability activation for + * @param player The {@link Player} using this ability + * @return true if the ability was successful, false otherwise + */ + private static boolean convertShroomThumb(BlockState blockState, Player player) { + if (!Permissions.shroomThumb(player)) { + return false; + } + + switch (blockState.getType()){ + case DIRT: + case GRASS: + blockState.setType(Material.MYCEL); + return true; + + default: + return false; + } + } } diff --git a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismCommand.java b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismCommand.java index 104c99c81..cf56d610e 100644 --- a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismCommand.java +++ b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismCommand.java @@ -18,6 +18,8 @@ public class HerbalismCommand extends SkillCommand { private String doubleDropChanceLucky; private String hylianLuckChance; private String hylianLuckChanceLucky; + private String shroomThumbChance; + private String shroomThumbChanceLucky; private boolean hasHylianLuck; private boolean canGreenTerra; @@ -25,6 +27,7 @@ public class HerbalismCommand extends SkillCommand { private boolean canGreenThumbBlocks; private boolean canFarmersDiet; private boolean canDoubleDrop; + private boolean canShroomThumb; private boolean doubleDropsDisabled; public HerbalismCommand() { @@ -57,6 +60,11 @@ public class HerbalismCommand extends SkillCommand { String[] hylianLuckStrings = calculateAbilityDisplayValues(Herbalism.hylianLuckMaxLevel, Herbalism.hylianLuckMaxChance); hylianLuckChance = hylianLuckStrings[0]; hylianLuckChanceLucky = hylianLuckStrings[1]; + + //SHROOM THUMB + String[] shroomThumbStrings = calculateAbilityDisplayValues(Herbalism.shroomThumbMaxLevel, Herbalism.shroomThumbMaxChance); + shroomThumbChance = shroomThumbStrings[0]; + shroomThumbChanceLucky = shroomThumbStrings[1]; } @Override @@ -68,11 +76,12 @@ public class HerbalismCommand extends SkillCommand { canFarmersDiet = Permissions.farmersDiet(player); canDoubleDrop = Permissions.doubleDrops(player, skill); doubleDropsDisabled = skill.getDoubleDropsDisabled(); + canShroomThumb = Permissions.shroomThumb(player); } @Override protected boolean effectsHeaderPermissions() { - return canGreenTerra || (canDoubleDrop && !doubleDropsDisabled) || canFarmersDiet || canGreenThumbBlocks || canGreenThumbWheat; + return canGreenTerra || (canDoubleDrop && !doubleDropsDisabled) || canFarmersDiet || canGreenThumbBlocks || canGreenThumbWheat || canShroomThumb; } @Override @@ -99,6 +108,10 @@ public class HerbalismCommand extends SkillCommand { player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.10"), LocaleLoader.getString("Herbalism.Effect.11"))); } + if (canShroomThumb) { + player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.12"), LocaleLoader.getString("Herbalism.Effect.13"))); + } + if (canDoubleDrop && !doubleDropsDisabled) { player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.8"), LocaleLoader.getString("Herbalism.Effect.9"))); } @@ -106,7 +119,7 @@ public class HerbalismCommand extends SkillCommand { @Override protected boolean statsHeaderPermissions() { - return canGreenTerra || (canDoubleDrop && !doubleDropsDisabled) || canFarmersDiet || canGreenThumbBlocks || canGreenThumbWheat; + return canGreenTerra || (canDoubleDrop && !doubleDropsDisabled) || canFarmersDiet || canGreenThumbBlocks || canGreenThumbWheat || canShroomThumb; } @Override @@ -145,6 +158,16 @@ public class HerbalismCommand extends SkillCommand { player.sendMessage(LocaleLoader.getString("Herbalism.Ability.HylianLuck", hylianLuckChance)); } } + + if (canShroomThumb) { + if (isLucky) { + player.sendMessage(LocaleLoader.getString("Herbalism.Ability.ShroomThumb.Chance", shroomThumbChance) + LocaleLoader.getString("Perks.lucky.bonus", shroomThumbChanceLucky)); + } + else { + player.sendMessage(LocaleLoader.getString("Herbalism.Ability.ShroomThumb.Chance", shroomThumbChance)); + } + } + if (canDoubleDrop && !doubleDropsDisabled) { if (isLucky) { player.sendMessage(LocaleLoader.getString("Herbalism.Ability.DoubleDropChance", doubleDropChance) + LocaleLoader.getString("Perks.lucky.bonus", doubleDropChanceLucky)); diff --git a/src/main/java/com/gmail/nossr50/util/BlockChecks.java b/src/main/java/com/gmail/nossr50/util/BlockChecks.java index e769b381f..7265a1d11 100644 --- a/src/main/java/com/gmail/nossr50/util/BlockChecks.java +++ b/src/main/java/com/gmail/nossr50/util/BlockChecks.java @@ -345,4 +345,21 @@ public final class BlockChecks { return false; } } + + /** + * Determine if a given block can be made into Mycelium + * + * @param blockState The {@link BlockState} of the block to check + * @return true if the block can be made in Mycelium, false otherwise + */ + public static boolean canMakeShroomy(BlockState blockState) { + switch (blockState.getType()) { + case DIRT: + case GRASS: + return true; + + default: + return false; + } + } } diff --git a/src/main/java/com/gmail/nossr50/util/Permissions.java b/src/main/java/com/gmail/nossr50/util/Permissions.java index 46d907b75..b9371a0d1 100644 --- a/src/main/java/com/gmail/nossr50/util/Permissions.java +++ b/src/main/java/com/gmail/nossr50/util/Permissions.java @@ -146,6 +146,7 @@ public final class Permissions { public static boolean greenThumbBlock(Permissible permissible, Material material) { return permissible.hasPermission("mcmmo.ability.herbalism.greenthumb.blocks." + material.toString().replace("_", "").toLowerCase()); } public static boolean greenThumbPlant(Permissible permissible, Material material) { return permissible.hasPermission("mcmmo.ability.herbalism.greenthumb.plants." + material.toString().replace("_", "").toLowerCase()); } public static boolean hylianLuck(Permissible permissible) { return permissible.hasPermission("mcmmo.ability.herbalism.hylianluck"); } + public static boolean shroomThumb(Permissible permissible) { return permissible.hasPermission("mcmmo.ability.herbalism.shroomthumb"); } /* MINING */ public static boolean biggerBombs(Permissible permissible) { return permissible.hasPermission("mcmmo.ability.mining.blastmining.biggerbombs"); } diff --git a/src/main/resources/advanced.yml b/src/main/resources/advanced.yml index 982a771e8..39baed646 100644 --- a/src/main/resources/advanced.yml +++ b/src/main/resources/advanced.yml @@ -156,6 +156,11 @@ Skills: # HylianLuck_MaxBonusLevel: On this level, Hylian Luck chance will be HylianLuck_ChanceMax HylianLuck_ChanceMax: 10.0 HylianLuck_MaxBonusLevel: 1000 + + # ShroomThumb_ChanceMax: Maximum chance of ShroomThumb + # ShroomThumb_MaxBonusLevel: On this level, ShroomThumb chance will be ShroomThumb_ChanceMax + ShroomThumb_ChanceMax: 50.0 + ShroomThumb_MaxBonusLevel: 1500 # # Settings for Mining ### diff --git a/src/main/resources/locale/locale_en_US.properties b/src/main/resources/locale/locale_en_US.properties index 9bdfe6e4d..12b685448 100644 --- a/src/main/resources/locale/locale_en_US.properties +++ b/src/main/resources/locale/locale_en_US.properties @@ -131,6 +131,8 @@ Herbalism.Ability.GTh=[[GREEN]]**GREEN THUMB** Herbalism.Ability.HylianLuck=[[RED]]Hylian Luck Chance: [[YELLOW]]{0} Herbalism.Ability.Lower=[[GRAY]]**YOU LOWER YOUR HOE** Herbalism.Ability.Ready=[[GREEN]]**YOU READY YOUR HOE** +Herbalism.Ability.ShroomThumb.Chance=[[RED]]Shroom Thumb Chance: [[YELLOW]]{0} +Herbalism.Ability.ShroomThumb.Fail=[[RED]]**SHROOM THUMB FAIL** Herbalism.Effect.0=Green Terra (ABILITY) Herbalism.Effect.1=Spread the Terra, 3x Drops Herbalism.Effect.2=Green Thumb (Wheat) @@ -143,6 +145,8 @@ Herbalism.Effect.8=Double Drops (All Herbs) Herbalism.Effect.9=Double the normal loot Herbalism.Effect.10=Hylian Luck Herbalism.Effect.11=Gives a small chance of finding rare items +Herbalism.Effect.12=Shroom Thumb +Herbalism.Effect.13=Spread mycelium to dirt & grass Herbalism.HylianLuck=[[GREEN]]The luck of Hyrule is with you today! Herbalism.Listener=Herbalism: Herbalism.SkillName=HERBALISM diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 98ed35871..99a00f362 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -277,6 +277,7 @@ permissions: mcmmo.ability.herbalism.greenterra: true mcmmo.ability.herbalism.greenthumb.all: true mcmmo.ability.herbalism.hylianluck: true + mcmmo.ability.herbalism.shroomthumb: true mcmmo.ability.herbalism.doubledrops: description: Allows double drop chance from Herbalism mcmmo.ability.herbalism.farmersdiet: @@ -368,6 +369,8 @@ permissions: mcmmo.ability.herbalism.greenthumb.plants.crops: true mcmmo.ability.herbalism.hylianluck: description: Allows access to the Hylian Luck ability + mcmmo.ability.herbalism.shroomthumb: + description: Allows access to the Shroom Thumb ability mcmmo.ability.mining.*: default: false description: Allows access to all Mining abilities