2013-03-01 06:52:01 +01:00
|
|
|
package com.gmail.nossr50.skills.herbalism;
|
|
|
|
|
2018-07-24 04:13:57 +02:00
|
|
|
import com.gmail.nossr50.config.Config;
|
|
|
|
import com.gmail.nossr50.config.experience.ExperienceConfig;
|
|
|
|
import com.gmail.nossr50.config.treasure.TreasureConfig;
|
2019-01-28 03:11:51 +01:00
|
|
|
import com.gmail.nossr50.datatypes.experience.XPGainReason;
|
2019-01-14 08:23:48 +01:00
|
|
|
import com.gmail.nossr50.datatypes.interactions.NotificationType;
|
2018-07-24 04:13:57 +02:00
|
|
|
import com.gmail.nossr50.datatypes.mods.CustomBlock;
|
|
|
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
2019-01-28 03:11:51 +01:00
|
|
|
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
|
|
|
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
|
|
|
import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
|
|
|
|
import com.gmail.nossr50.datatypes.skills.ToolType;
|
2018-07-24 04:13:57 +02:00
|
|
|
import com.gmail.nossr50.datatypes.treasure.HylianTreasure;
|
|
|
|
import com.gmail.nossr50.mcMMO;
|
|
|
|
import com.gmail.nossr50.runnables.skills.HerbalismBlockUpdaterTask;
|
|
|
|
import com.gmail.nossr50.skills.SkillManager;
|
|
|
|
import com.gmail.nossr50.util.*;
|
2019-01-14 08:23:48 +01:00
|
|
|
import com.gmail.nossr50.util.player.NotificationManager;
|
2019-01-25 05:45:26 +01:00
|
|
|
import com.gmail.nossr50.util.random.RandomChanceSkillStatic;
|
|
|
|
import com.gmail.nossr50.util.random.RandomChanceUtil;
|
2019-01-15 14:35:41 +01:00
|
|
|
import com.gmail.nossr50.util.skills.RankUtils;
|
2019-01-09 04:52:52 +01:00
|
|
|
import com.gmail.nossr50.util.skills.SkillActivationType;
|
2018-07-24 04:13:57 +02:00
|
|
|
import com.gmail.nossr50.util.skills.SkillUtils;
|
2018-10-10 03:48:47 +02:00
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.Material;
|
2013-03-01 06:52:01 +01:00
|
|
|
import org.bukkit.block.BlockState;
|
2018-08-01 03:35:45 +02:00
|
|
|
import org.bukkit.block.data.Ageable;
|
2013-03-01 06:52:01 +01:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
import org.bukkit.inventory.PlayerInventory;
|
2014-04-06 14:41:40 +02:00
|
|
|
import org.bukkit.metadata.FixedMetadataValue;
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2018-07-24 04:13:57 +02:00
|
|
|
import java.util.List;
|
2013-03-01 06:52:01 +01:00
|
|
|
|
|
|
|
public class HerbalismManager extends SkillManager {
|
|
|
|
public HerbalismManager(McMMOPlayer mcMMOPlayer) {
|
2019-01-13 08:54:53 +01:00
|
|
|
super(mcMMOPlayer, PrimarySkillType.HERBALISM);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canBlockCheck() {
|
2013-10-28 15:39:47 +01:00
|
|
|
return !(Config.getInstance().getHerbalismPreventAFK() && getPlayer().isInsideVehicle());
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canGreenThumbBlock(BlockState blockState) {
|
2019-01-26 20:21:25 +01:00
|
|
|
if(!RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.HERBALISM_GREEN_THUMB))
|
|
|
|
return false;
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
Player player = getPlayer();
|
2016-03-05 11:39:16 +01:00
|
|
|
ItemStack item = player.getInventory().getItemInMainHand();
|
2018-07-24 04:13:57 +02:00
|
|
|
|
|
|
|
return item.getAmount() > 0 && item.getType() == Material.WHEAT_SEEDS && BlockUtils.canMakeMossy(blockState) && Permissions.greenThumbBlock(player, blockState.getType());
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canUseShroomThumb(BlockState blockState) {
|
2019-01-26 20:21:25 +01:00
|
|
|
if(!RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.HERBALISM_SHROOM_THUMB))
|
|
|
|
return false;
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
Player player = getPlayer();
|
2016-03-12 19:35:19 +01:00
|
|
|
PlayerInventory inventory = player.getInventory();
|
|
|
|
Material itemType = inventory.getItemInMainHand().getType();
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2019-01-09 04:52:52 +01:00
|
|
|
return (itemType == Material.BROWN_MUSHROOM || itemType == Material.RED_MUSHROOM) && inventory.contains(Material.BROWN_MUSHROOM, 1) && inventory.contains(Material.RED_MUSHROOM, 1) && BlockUtils.canMakeShroomy(blockState) && Permissions.isSubSkillEnabled(player, SubSkillType.HERBALISM_SHROOM_THUMB);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canUseHylianLuck() {
|
2019-01-26 20:21:25 +01:00
|
|
|
if(!RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.HERBALISM_HYLIAN_LUCK))
|
|
|
|
return false;
|
|
|
|
|
2019-01-09 04:52:52 +01:00
|
|
|
return Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.HERBALISM_HYLIAN_LUCK);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canGreenTerraBlock(BlockState blockState) {
|
2019-01-13 04:56:54 +01:00
|
|
|
return mcMMOPlayer.getAbilityMode(SuperAbilityType.GREEN_TERRA) && BlockUtils.canMakeMossy(blockState);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canActivateAbility() {
|
2013-03-03 17:06:05 +01:00
|
|
|
return mcMMOPlayer.getToolPreparationMode(ToolType.HOE) && Permissions.greenTerra(getPlayer());
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canGreenTerraPlant() {
|
2019-01-13 04:56:54 +01:00
|
|
|
return mcMMOPlayer.getAbilityMode(SuperAbilityType.GREEN_TERRA);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the Farmer's Diet ability
|
|
|
|
*
|
|
|
|
* @param eventFoodLevel The initial change in hunger from the event
|
|
|
|
* @return the modified change in hunger for the event
|
|
|
|
*/
|
2019-01-15 14:39:25 +01:00
|
|
|
public int farmersDiet(int eventFoodLevel) {
|
2019-01-15 14:35:41 +01:00
|
|
|
return SkillUtils.handleFoodSkills(getPlayer(), eventFoodLevel, SubSkillType.HERBALISM_FARMERS_DIET);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process the Green Terra ability.
|
|
|
|
*
|
|
|
|
* @param blockState The {@link BlockState} to check ability activation for
|
|
|
|
* @return true if the ability was successful, false otherwise
|
|
|
|
*/
|
|
|
|
public boolean processGreenTerra(BlockState blockState) {
|
|
|
|
Player player = getPlayer();
|
|
|
|
|
|
|
|
if (!Permissions.greenThumbBlock(player, blockState.getType())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
PlayerInventory playerInventory = player.getInventory();
|
2018-07-24 04:13:57 +02:00
|
|
|
ItemStack seed = new ItemStack(Material.WHEAT_SEEDS);
|
2013-03-01 06:52:01 +01:00
|
|
|
|
|
|
|
if (!playerInventory.containsAtLeast(seed, 1)) {
|
2019-01-14 08:23:48 +01:00
|
|
|
NotificationManager.sendPlayerInformation(player, NotificationType.REQUIREMENTS_NOT_MET, "Herbalism.Ability.GTe.NeedMore");
|
2013-03-01 06:52:01 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
playerInventory.removeItem(seed);
|
|
|
|
player.updateInventory(); // Needed until replacement available
|
|
|
|
|
|
|
|
return Herbalism.convertGreenTerraBlocks(blockState);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param blockState The {@link BlockState} to check ability activation for
|
|
|
|
*/
|
|
|
|
public void herbalismBlockCheck(BlockState blockState) {
|
2013-10-09 16:27:06 +02:00
|
|
|
Player player = getPlayer();
|
2013-03-08 14:53:54 +01:00
|
|
|
Material material = blockState.getType();
|
2019-03-17 04:26:26 +01:00
|
|
|
boolean oneBlockPlant = !(material == Material.CACTUS || material == Material.CHORUS_PLANT
|
|
|
|
|| material == Material.SUGAR_CANE || material == Material.KELP_PLANT || material == Material.KELP);
|
2013-03-08 14:53:54 +01:00
|
|
|
|
[bugfix] Resolve issues with Herbalism exp.
Due to flaws the previous changes to the configuration system combined with some bad lines in the experience.config that I mistakenly recommended, herbalism was not granting experience in most cases, as it was marking newly planted crops and such as player placed no exp granting blocks, rather than ignoring them as it should.
block types now are evaluated in 3 steps:
1: Explicit Name i.e. ("Crops|4", "Crops|0"), Which is the material name then data value
2: "friendly name" i.e. ("Crops_Ripe", "Crops_Ungrown"), Which is a typically data valueless name, some of which I make up in mcMMO, but most of which are just the Material name
3: Wildcard name i.e. ("Crops|*") Which is any block with that block value, regardless of data value
In order to be sure herbalism grants exp for you once again, make sure your configuration for herbalism looks similar to this:
https://github.com/mcMMO-Dev/mcMMO/blob/master/src/main/resources/experience.yml#L151
In terms of which blocks are listed there. Specifically, there should be no blocks marked "ungrown"
2017-08-01 07:33:02 +02:00
|
|
|
// Prevents placing and immediately breaking blocks for exp
|
2013-04-25 15:16:42 +02:00
|
|
|
if (oneBlockPlant && mcMMO.getPlaceStore().isTrue(blockState)) {
|
2013-03-08 10:11:33 +01:00
|
|
|
return;
|
|
|
|
}
|
2018-07-27 02:47:45 +02:00
|
|
|
|
2013-10-05 01:18:51 +02:00
|
|
|
if (!canBlockCheck()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-24 00:21:25 +01:00
|
|
|
int amount;
|
2014-01-20 22:58:40 +01:00
|
|
|
int xp;
|
2013-03-08 10:35:52 +01:00
|
|
|
boolean greenTerra = mcMMOPlayer.getAbilityMode(skill.getAbility());
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2014-02-03 20:48:43 +01:00
|
|
|
if (mcMMO.getModManager().isCustomHerbalismBlock(blockState)) {
|
|
|
|
CustomBlock customBlock = mcMMO.getModManager().getBlock(blockState);
|
2013-10-09 17:44:45 +02:00
|
|
|
xp = customBlock.getXpGain();
|
2013-10-09 16:27:06 +02:00
|
|
|
|
2019-01-09 04:52:52 +01:00
|
|
|
if (Permissions.isSubSkillEnabled(player, SubSkillType.HERBALISM_DOUBLE_DROPS) && customBlock.isDoubleDropEnabled()) {
|
2019-03-24 00:21:25 +01:00
|
|
|
if(checkDoubleDrop(blockState))
|
2019-03-29 19:27:49 +01:00
|
|
|
BlockUtils.spawnBonusDrops(blockState, greenTerra);
|
2013-10-09 16:27:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2018-10-15 03:27:55 +02:00
|
|
|
xp = ExperienceConfig.getInstance().getXp(skill, blockState.getBlockData());
|
2013-03-08 10:11:33 +01:00
|
|
|
|
2013-03-08 19:33:03 +01:00
|
|
|
if (!oneBlockPlant) {
|
2019-03-17 04:26:26 +01:00
|
|
|
//Kelp is actually two blocks mixed together
|
|
|
|
if(material == Material.KELP_PLANT || material == Material.KELP) {
|
2019-03-24 00:21:25 +01:00
|
|
|
amount = Herbalism.countAndMarkDoubleDropsKelp(blockState, greenTerra,this);
|
2019-03-17 04:26:26 +01:00
|
|
|
} else {
|
2019-03-24 00:21:25 +01:00
|
|
|
amount = Herbalism.countAndMarkDoubleDropsMultiBlockPlant(blockState, greenTerra, this);
|
2019-03-17 04:26:26 +01:00
|
|
|
}
|
|
|
|
|
2013-03-08 10:11:33 +01:00
|
|
|
xp *= amount;
|
2019-03-24 00:21:25 +01:00
|
|
|
} else {
|
|
|
|
/* MARK SINGLE BLOCK CROP FOR DOUBLE DROP */
|
|
|
|
if(checkDoubleDrop(blockState))
|
2019-03-29 19:27:49 +01:00
|
|
|
BlockUtils.spawnBonusDrops(blockState, greenTerra);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
2019-03-24 00:21:25 +01:00
|
|
|
|
2018-01-15 22:47:41 +01:00
|
|
|
if (Permissions.greenThumbPlant(player, material)) {
|
|
|
|
processGreenThumbPlants(blockState, greenTerra);
|
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
2014-04-18 21:56:03 +02:00
|
|
|
applyXpGain(xp, XPGainReason.PVE);
|
2019-03-24 00:21:25 +01:00
|
|
|
}
|
2013-03-08 10:11:33 +01:00
|
|
|
|
2019-03-24 00:21:25 +01:00
|
|
|
/**
|
|
|
|
* Check for success on herbalism double drops
|
|
|
|
* @param blockState target block state
|
|
|
|
* @return true if double drop succeeds
|
|
|
|
*/
|
|
|
|
public boolean checkDoubleDrop(BlockState blockState)
|
|
|
|
{
|
|
|
|
return BlockUtils.checkDoubleDrops(getPlayer(), blockState, skill, SubSkillType.HERBALISM_DOUBLE_DROPS);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process the Green Thumb ability for blocks.
|
|
|
|
*
|
|
|
|
* @param blockState The {@link BlockState} to check ability activation for
|
|
|
|
* @return true if the ability was successful, false otherwise
|
|
|
|
*/
|
|
|
|
public boolean processGreenThumbBlocks(BlockState blockState) {
|
2019-01-25 05:45:26 +01:00
|
|
|
if (!RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.HERBALISM_GREEN_THUMB, getPlayer())) {
|
2019-02-01 19:34:13 +01:00
|
|
|
NotificationManager.sendPlayerInformation(getPlayer(), NotificationType.SUBSKILL_MESSAGE_FAILED, "Herbalism.Ability.GTh.Fail");
|
2013-03-01 06:52:01 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Herbalism.convertGreenTerraBlocks(blockState);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process the Hylian Luck ability.
|
|
|
|
*
|
|
|
|
* @param blockState The {@link BlockState} to check ability activation for
|
|
|
|
* @return true if the ability was successful, false otherwise
|
|
|
|
*/
|
|
|
|
public boolean processHylianLuck(BlockState blockState) {
|
2019-01-25 05:45:26 +01:00
|
|
|
if (!RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.HERBALISM_HYLIAN_LUCK, getPlayer())) {
|
2013-03-01 06:52:01 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-27 01:53:29 +02:00
|
|
|
String friendly = StringUtils.getFriendlyConfigBlockDataString(blockState.getBlockData());
|
2017-06-10 20:16:31 +02:00
|
|
|
if (!TreasureConfig.getInstance().hylianMap.containsKey(friendly))
|
|
|
|
return false;
|
|
|
|
List<HylianTreasure> treasures = TreasureConfig.getInstance().hylianMap.get(friendly);
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-10-18 14:31:00 +02:00
|
|
|
Player player = getPlayer();
|
2013-10-11 23:47:42 +02:00
|
|
|
|
2015-11-04 19:35:25 +01:00
|
|
|
if (treasures.isEmpty()) {
|
2013-10-11 23:47:42 +02:00
|
|
|
return false;
|
|
|
|
}
|
2015-11-04 19:35:25 +01:00
|
|
|
int skillLevel = getSkillLevel();
|
2016-03-16 17:47:40 +01:00
|
|
|
Location location = Misc.getBlockCenter(blockState);
|
2013-10-11 23:47:42 +02:00
|
|
|
|
2015-11-04 19:35:25 +01:00
|
|
|
for (HylianTreasure treasure : treasures) {
|
2019-01-25 05:45:26 +01:00
|
|
|
if (skillLevel >= treasure.getDropLevel()
|
|
|
|
&& RandomChanceUtil.checkRandomChanceExecutionSuccess(new RandomChanceSkillStatic(treasure.getDropChance(), getPlayer(), SubSkillType.HERBALISM_HYLIAN_LUCK))) {
|
2015-11-04 19:35:25 +01:00
|
|
|
if (!EventUtils.simulateBlockBreak(blockState.getBlock(), player, false)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
blockState.setType(Material.AIR);
|
|
|
|
Misc.dropItem(location, treasure.getDrop());
|
2019-01-14 08:23:48 +01:00
|
|
|
NotificationManager.sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE, "Herbalism.HylianLuck");
|
2015-11-04 19:35:25 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process the Shroom Thumb ability.
|
|
|
|
*
|
|
|
|
* @param blockState The {@link BlockState} to check ability activation for
|
|
|
|
* @return true if the ability was successful, false otherwise
|
|
|
|
*/
|
|
|
|
public boolean processShroomThumb(BlockState blockState) {
|
|
|
|
Player player = getPlayer();
|
|
|
|
PlayerInventory playerInventory = player.getInventory();
|
2016-03-12 19:35:19 +01:00
|
|
|
|
|
|
|
if (!playerInventory.contains(Material.BROWN_MUSHROOM, 1)) {
|
2019-01-14 08:23:48 +01:00
|
|
|
NotificationManager.sendPlayerInformation(player, NotificationType.REQUIREMENTS_NOT_MET, "Skills.NeedMore", StringUtils.getPrettyItemString(Material.BROWN_MUSHROOM));
|
2013-03-01 06:52:01 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-12 19:35:19 +01:00
|
|
|
if (!playerInventory.contains(Material.RED_MUSHROOM, 1)) {
|
2019-01-14 08:23:48 +01:00
|
|
|
NotificationManager.sendPlayerInformation(player, NotificationType.REQUIREMENTS_NOT_MET, "Skills.NeedMore", StringUtils.getPrettyItemString(Material.RED_MUSHROOM));
|
2013-03-01 06:52:01 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
playerInventory.removeItem(new ItemStack(Material.BROWN_MUSHROOM));
|
|
|
|
playerInventory.removeItem(new ItemStack(Material.RED_MUSHROOM));
|
|
|
|
player.updateInventory();
|
|
|
|
|
2019-01-25 05:45:26 +01:00
|
|
|
if (!RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.HERBALISM_SHROOM_THUMB, player)) {
|
2019-02-01 19:34:13 +01:00
|
|
|
NotificationManager.sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE_FAILED, "Herbalism.Ability.ShroomThumb.Fail");
|
2013-03-01 06:52:01 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Herbalism.convertShroomThumb(blockState);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process the Green Thumb ability for plants.
|
|
|
|
*
|
|
|
|
* @param blockState The {@link BlockState} to check ability activation for
|
2013-08-10 20:10:45 +02:00
|
|
|
* @param greenTerra boolean to determine if greenTerra is active or not
|
2013-03-01 06:52:01 +01:00
|
|
|
*/
|
2013-03-08 10:11:33 +01:00
|
|
|
private void processGreenThumbPlants(BlockState blockState, boolean greenTerra) {
|
2018-10-13 23:09:08 +02:00
|
|
|
if (!BlockUtils.isFullyGrown(blockState))
|
|
|
|
return;
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
Player player = getPlayer();
|
|
|
|
PlayerInventory playerInventory = player.getInventory();
|
2016-03-18 01:18:40 +01:00
|
|
|
Material seed = null;
|
2013-10-09 16:27:06 +02:00
|
|
|
|
|
|
|
switch (blockState.getType()) {
|
2018-07-24 04:13:57 +02:00
|
|
|
case CARROTS:
|
|
|
|
seed = Material.CARROT;
|
2013-10-09 16:27:06 +02:00
|
|
|
break;
|
|
|
|
|
2018-07-24 04:13:57 +02:00
|
|
|
case WHEAT:
|
|
|
|
seed = Material.WHEAT_SEEDS;
|
2013-10-09 16:27:06 +02:00
|
|
|
break;
|
|
|
|
|
2018-08-05 16:15:12 +02:00
|
|
|
case NETHER_WART:
|
2018-07-24 04:13:57 +02:00
|
|
|
seed = Material.NETHER_WART;
|
2013-10-09 16:27:06 +02:00
|
|
|
break;
|
|
|
|
|
2018-07-24 04:13:57 +02:00
|
|
|
case POTATOES:
|
|
|
|
seed = Material.POTATO;
|
2013-10-09 16:27:06 +02:00
|
|
|
break;
|
2016-06-26 23:14:19 +02:00
|
|
|
|
2018-07-24 04:13:57 +02:00
|
|
|
case BEETROOTS:
|
2016-06-19 23:33:43 +02:00
|
|
|
seed = Material.BEETROOT_SEEDS;
|
|
|
|
break;
|
2013-10-09 16:27:06 +02:00
|
|
|
|
2018-09-15 04:44:21 +02:00
|
|
|
case COCOA:
|
|
|
|
seed = Material.COCOA_BEANS;
|
|
|
|
break;
|
|
|
|
|
2013-10-09 16:27:06 +02:00
|
|
|
default:
|
2016-03-20 18:42:16 +01:00
|
|
|
return;
|
2013-10-09 16:27:06 +02:00
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2017-09-01 05:47:28 +02:00
|
|
|
ItemStack seedStack = new ItemStack(seed);
|
|
|
|
|
2019-03-24 00:21:25 +01:00
|
|
|
if (!greenTerra && !RandomChanceUtil.checkRandomChanceExecutionSuccess(player, SubSkillType.HERBALISM_GREEN_THUMB, true)) {
|
2013-03-01 06:52:01 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-24 00:21:25 +01:00
|
|
|
if (!handleBlockState(blockState, greenTerra)) {
|
2013-03-01 06:52:01 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-24 00:21:25 +01:00
|
|
|
if(!ItemUtils.isHoe(getPlayer().getInventory().getItemInMainHand()))
|
|
|
|
{
|
|
|
|
if (!playerInventory.containsAtLeast(seedStack, 1)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
playerInventory.removeItem(seedStack);
|
|
|
|
player.updateInventory(); // Needed until replacement available
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
2013-03-08 10:11:33 +01:00
|
|
|
|
2013-03-20 08:11:16 +01:00
|
|
|
new HerbalismBlockUpdaterTask(blockState).runTaskLater(mcMMO.p, 0);
|
2013-03-08 10:11:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private boolean handleBlockState(BlockState blockState, boolean greenTerra) {
|
2019-01-15 14:35:41 +01:00
|
|
|
int greenThumbStage = getGreenThumbStage();
|
2013-09-05 22:36:02 +02:00
|
|
|
|
2014-04-06 14:41:40 +02:00
|
|
|
blockState.setMetadata(mcMMO.greenThumbDataKey, new FixedMetadataValue(mcMMO.p, (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR)));
|
2018-08-05 16:15:12 +02:00
|
|
|
Ageable crops = (Ageable) blockState.getBlockData();
|
2014-04-06 14:41:40 +02:00
|
|
|
|
2013-03-08 10:11:33 +01:00
|
|
|
switch (blockState.getType()) {
|
2016-06-26 23:14:19 +02:00
|
|
|
|
2018-07-27 01:53:29 +02:00
|
|
|
case POTATOES:
|
|
|
|
case CARROTS:
|
2018-07-24 04:13:57 +02:00
|
|
|
case WHEAT:
|
2013-09-05 22:36:02 +02:00
|
|
|
|
|
|
|
if (greenTerra) {
|
2018-08-01 03:35:45 +02:00
|
|
|
crops.setAge(3);
|
2013-09-05 22:36:02 +02:00
|
|
|
}
|
|
|
|
else {
|
2018-08-01 03:35:45 +02:00
|
|
|
crops.setAge(greenThumbStage);
|
2013-09-05 22:36:02 +02:00
|
|
|
}
|
2018-08-05 16:15:12 +02:00
|
|
|
break;
|
2013-09-05 22:36:02 +02:00
|
|
|
|
2018-08-05 16:15:12 +02:00
|
|
|
case BEETROOTS:
|
|
|
|
case NETHER_WART:
|
2013-04-05 04:24:02 +02:00
|
|
|
|
2013-09-05 22:36:02 +02:00
|
|
|
if (greenTerra || greenThumbStage > 2) {
|
2018-08-05 16:15:12 +02:00
|
|
|
crops.setAge(2);
|
2013-03-08 10:11:33 +01:00
|
|
|
}
|
2013-09-05 22:36:02 +02:00
|
|
|
else if (greenThumbStage == 2) {
|
2018-08-05 16:15:12 +02:00
|
|
|
crops.setAge(1);
|
2013-09-05 22:36:02 +02:00
|
|
|
}
|
2013-03-08 10:11:33 +01:00
|
|
|
else {
|
2018-08-05 16:15:12 +02:00
|
|
|
crops.setAge(0);
|
2013-03-08 10:11:33 +01:00
|
|
|
}
|
2018-08-05 16:15:12 +02:00
|
|
|
break;
|
2013-03-08 10:11:33 +01:00
|
|
|
|
|
|
|
case COCOA:
|
|
|
|
|
|
|
|
if (greenTerra || getGreenThumbStage() > 1) {
|
2018-08-05 16:15:12 +02:00
|
|
|
crops.setAge(1);
|
2013-03-08 10:11:33 +01:00
|
|
|
}
|
|
|
|
else {
|
2018-08-05 16:15:12 +02:00
|
|
|
crops.setAge(0);
|
2013-03-08 10:11:33 +01:00
|
|
|
}
|
2018-08-05 16:15:12 +02:00
|
|
|
break;
|
2013-03-08 10:11:33 +01:00
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2018-08-05 16:15:12 +02:00
|
|
|
blockState.setBlockData(crops);
|
|
|
|
return true;
|
2013-03-08 10:11:33 +01:00
|
|
|
}
|
|
|
|
|
2019-01-15 14:35:41 +01:00
|
|
|
private int getGreenThumbStage() {
|
|
|
|
return RankUtils.getRank(getPlayer(), SubSkillType.HERBALISM_GREEN_THUMB);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
}
|