From 8f265441884a2aba2b359cd924b25eda2ac74199 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 19 Feb 2020 13:51:10 -0800 Subject: [PATCH] Immature plants will be replanted if weilding a hoe --- Changelog.txt | 1 + .../skills/herbalism/HerbalismManager.java | 37 ++++++++++++++++--- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index adaf42ab0..69da6676f 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,4 +1,5 @@ Version 2.1.115 + Using a hoe on non-fully grown crops will replant them as a convenience feature for those who can't bother to wait for all of their plants to grow (put away the hoe to break non-fully grown crops) Fixed a bug where Salvage always gave the best results Fixed an issue with arrows causing exceptions with players not yet having data loaded Spectral arrows are now tracked by mcMMO diff --git a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java index 9b6a68881..3eb0951f2 100644 --- a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java +++ b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java @@ -143,6 +143,9 @@ public class HerbalismManager extends SkillManager { //Grab all broken blocks HashSet brokenBlocks = getBrokenHerbalismBlocks(blockBreakEvent); + if(brokenBlocks.size() == 0) + return; + //Handle rewards, xp, ability interactions, etc processHerbalismOnBlocksBroken(blockBreakEvent, brokenBlocks); } @@ -157,7 +160,12 @@ public class HerbalismManager extends SkillManager { //TODO: The design of Green Terra needs to change, this is a mess if(Permissions.greenThumbPlant(getPlayer(), originalBreak.getType())) { - processGreenThumbPlants(originalBreak, isGreenTerraActive()); + processGreenThumbPlants(originalBreak, blockBreakEvent, isGreenTerraActive()); + } + + //When replanting a immature crop we cancel the block break event and back out + if(blockBreakEvent.isCancelled()) { + return; } /* @@ -339,9 +347,11 @@ public class HerbalismManager extends SkillManager { //Calculate XP if(plantData instanceof Ageable) { Ageable plantAgeable = (Ageable) plantData; + if(isAgeableMature(plantAgeable) || isBizarreAgeable(plantData)) { xpToReward += ExperienceConfig.getInstance().getXp(PrimarySkillType.HERBALISM, brokenBlockNewState.getType()); } + } else { xpToReward += ExperienceConfig.getInstance().getXp(PrimarySkillType.HERBALISM, brokenPlantBlock.getType()); } @@ -635,10 +645,18 @@ public class HerbalismManager extends SkillManager { * @param blockState The {@link BlockState} to check ability activation for * @param greenTerra boolean to determine if greenTerra is active or not */ - private void processGreenThumbPlants(BlockState blockState, boolean greenTerra) { - if (!BlockUtils.isFullyGrown(blockState)) + private void processGreenThumbPlants(BlockState blockState, BlockBreakEvent blockBreakEvent, boolean greenTerra) { + BlockData blockData = blockState.getBlockData(); + + if (!(blockData instanceof Ageable)) return; + //If the ageable is NOT mature and the player is NOT using a hoe, abort + if(!isAgeableMature((Ageable) blockData) && !ItemUtils.isHoe(getPlayer().getItemInHand())) { + return; + } + + Player player = getPlayer(); PlayerInventory playerInventory = player.getInventory(); Material seed = null; @@ -678,7 +696,7 @@ public class HerbalismManager extends SkillManager { return; } - if (!processGrowingPlants(blockState, greenTerra)) { + if (!processGrowingPlants(blockState, blockBreakEvent, greenTerra)) { return; } @@ -695,11 +713,18 @@ public class HerbalismManager extends SkillManager { new HerbalismBlockUpdaterTask(blockState).runTaskLater(mcMMO.p, 0); } - private boolean processGrowingPlants(BlockState blockState, boolean greenTerra) { + private boolean processGrowingPlants(BlockState blockState, BlockBreakEvent blockBreakEvent, boolean greenTerra) { + Ageable crops = (Ageable) blockState.getBlockData(); int greenThumbStage = getGreenThumbStage(); + //Immature plants will start over at 0 + if(!isAgeableMature(crops)) { + crops.setAge(0); + blockBreakEvent.setCancelled(true); + return true; + } + blockState.setMetadata(mcMMO.greenThumbDataKey, new FixedMetadataValue(mcMMO.p, (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR))); - Ageable crops = (Ageable) blockState.getBlockData(); switch (blockState.getType()) {