2013-03-01 06:52:01 +01:00
|
|
|
package com.gmail.nossr50.skills.herbalism;
|
|
|
|
|
2013-10-09 16:27:06 +02:00
|
|
|
import java.util.Collection;
|
2013-03-01 06:52:01 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
2013-03-08 10:11:33 +01:00
|
|
|
import org.bukkit.CropState;
|
2015-11-04 19:35:25 +01:00
|
|
|
import org.bukkit.Location;
|
2013-03-01 06:52:01 +01:00
|
|
|
import org.bukkit.Material;
|
2013-04-05 04:24:02 +02:00
|
|
|
import org.bukkit.NetherWartsState;
|
2013-03-01 06:52:01 +01:00
|
|
|
import org.bukkit.block.BlockState;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
import org.bukkit.inventory.PlayerInventory;
|
2013-03-08 10:11:33 +01:00
|
|
|
import org.bukkit.material.CocoaPlant;
|
|
|
|
import org.bukkit.material.CocoaPlant.CocoaPlantSize;
|
2013-09-05 22:36:02 +02:00
|
|
|
import org.bukkit.material.Crops;
|
2013-04-05 04:24:02 +02:00
|
|
|
import org.bukkit.material.NetherWarts;
|
2014-04-06 14:41:40 +02:00
|
|
|
import org.bukkit.metadata.FixedMetadataValue;
|
2013-03-01 06:52:01 +01:00
|
|
|
|
|
|
|
import com.gmail.nossr50.mcMMO;
|
|
|
|
import com.gmail.nossr50.config.Config;
|
2013-10-09 16:27:06 +02:00
|
|
|
import com.gmail.nossr50.config.experience.ExperienceConfig;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.config.treasure.TreasureConfig;
|
2013-10-09 17:44:45 +02:00
|
|
|
import com.gmail.nossr50.datatypes.mods.CustomBlock;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
|
|
|
import com.gmail.nossr50.datatypes.skills.AbilityType;
|
2013-11-22 18:48:53 +01:00
|
|
|
import com.gmail.nossr50.datatypes.skills.SecondaryAbility;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.datatypes.skills.SkillType;
|
|
|
|
import com.gmail.nossr50.datatypes.skills.ToolType;
|
2014-05-11 15:14:46 +02:00
|
|
|
import com.gmail.nossr50.datatypes.skills.XPGainReason;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.datatypes.treasure.HylianTreasure;
|
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
2013-03-08 10:11:33 +01:00
|
|
|
import com.gmail.nossr50.runnables.skills.HerbalismBlockUpdaterTask;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.skills.SkillManager;
|
|
|
|
import com.gmail.nossr50.util.BlockUtils;
|
2013-10-18 14:31:00 +02:00
|
|
|
import com.gmail.nossr50.util.EventUtils;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.util.Misc;
|
|
|
|
import com.gmail.nossr50.util.Permissions;
|
|
|
|
import com.gmail.nossr50.util.StringUtils;
|
|
|
|
import com.gmail.nossr50.util.skills.SkillUtils;
|
|
|
|
|
|
|
|
public class HerbalismManager extends SkillManager {
|
|
|
|
public HerbalismManager(McMMOPlayer mcMMOPlayer) {
|
|
|
|
super(mcMMOPlayer, SkillType.HERBALISM);
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
Player player = getPlayer();
|
2016-03-05 11:39:16 +01:00
|
|
|
ItemStack item = player.getInventory().getItemInMainHand();
|
|
|
|
|
2016-03-11 15:20:23 +01:00
|
|
|
return item.getAmount() > 0 && item.getType() == Material.SEEDS && BlockUtils.canMakeMossy(blockState) && Permissions.greenThumbBlock(player, blockState.getType());
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canUseShroomThumb(BlockState blockState) {
|
|
|
|
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
|
|
|
|
2016-03-12 19:35:19 +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.secondaryAbilityEnabled(player, SecondaryAbility.SHROOM_THUMB);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canUseHylianLuck() {
|
2013-11-22 18:48:53 +01:00
|
|
|
return Permissions.secondaryAbilityEnabled(getPlayer(), SecondaryAbility.HYLIAN_LUCK);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canGreenTerraBlock(BlockState blockState) {
|
2013-03-03 17:06:05 +01:00
|
|
|
return mcMMOPlayer.getAbilityMode(AbilityType.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() {
|
2013-03-03 17:06:05 +01:00
|
|
|
return mcMMOPlayer.getAbilityMode(AbilityType.GREEN_TERRA);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the Farmer's Diet ability
|
|
|
|
*
|
|
|
|
* @param rankChange The # of levels to change rank for the food
|
|
|
|
* @param eventFoodLevel The initial change in hunger from the event
|
|
|
|
* @return the modified change in hunger for the event
|
|
|
|
*/
|
|
|
|
public int farmersDiet(int rankChange, int eventFoodLevel) {
|
2013-03-08 10:33:20 +01:00
|
|
|
return SkillUtils.handleFoodSkills(getPlayer(), skill, eventFoodLevel, Herbalism.farmersDietRankLevel1, Herbalism.farmersDietMaxLevel, rankChange);
|
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();
|
|
|
|
ItemStack seed = new ItemStack(Material.SEEDS);
|
|
|
|
|
|
|
|
if (!playerInventory.containsAtLeast(seed, 1)) {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTe.NeedMore"));
|
|
|
|
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();
|
2016-03-11 15:20:23 +01:00
|
|
|
boolean oneBlockPlant = !(material == Material.CACTUS || material == Material.CHORUS_PLANT || material == Material.SUGAR_CANE_BLOCK);
|
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;
|
|
|
|
}
|
2016-03-11 15:20:23 +01:00
|
|
|
|
2013-10-05 01:18:51 +02:00
|
|
|
if (!canBlockCheck()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-09 16:27:06 +02:00
|
|
|
Collection<ItemStack> drops = null;
|
2013-03-08 10:11:33 +01:00
|
|
|
int amount = 1;
|
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
|
|
|
|
2013-11-22 18:48:53 +01:00
|
|
|
if (Permissions.secondaryAbilityEnabled(player, SecondaryAbility.HERBALISM_DOUBLE_DROPS) && customBlock.isDoubleDropEnabled()) {
|
2013-10-09 16:27:06 +02:00
|
|
|
drops = blockState.getBlock().getDrops();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (Permissions.greenThumbPlant(player, material)) {
|
2013-03-08 10:11:33 +01:00
|
|
|
processGreenThumbPlants(blockState, greenTerra);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
2013-03-08 10:11:33 +01:00
|
|
|
|
2017-06-10 19:47:20 +02:00
|
|
|
if(material == Material.CHORUS_FLOWER && blockState.getRawData() != 5) {
|
|
|
|
return;
|
2013-12-02 18:08:12 +01:00
|
|
|
}
|
2017-06-10 19:47:20 +02:00
|
|
|
xp = ExperienceConfig.getInstance().getXp(skill, blockState.getData());
|
2013-03-08 10:11:33 +01:00
|
|
|
|
2013-11-22 18:48:53 +01:00
|
|
|
if (Config.getInstance().getDoubleDropsEnabled(skill, material) && Permissions.secondaryAbilityEnabled(player, SecondaryAbility.HERBALISM_DOUBLE_DROPS)) {
|
2013-10-09 16:27:06 +02:00
|
|
|
drops = blockState.getBlock().getDrops();
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
2013-03-08 10:11:33 +01:00
|
|
|
|
2013-03-08 19:33:03 +01:00
|
|
|
if (!oneBlockPlant) {
|
2016-03-11 15:20:23 +01:00
|
|
|
amount = Herbalism.calculateMultiBlockPlantDrops(blockState);
|
2013-03-08 10:11:33 +01:00
|
|
|
xp *= amount;
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-18 21:56:03 +02:00
|
|
|
applyXpGain(xp, XPGainReason.PVE);
|
2013-03-08 10:11:33 +01:00
|
|
|
|
2013-10-09 16:27:06 +02:00
|
|
|
if (drops == null) {
|
2013-03-08 10:11:33 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = greenTerra ? 2 : 1; i != 0; i--) {
|
2013-11-22 18:48:53 +01:00
|
|
|
if (SkillUtils.activationSuccessful(SecondaryAbility.HERBALISM_DOUBLE_DROPS, getPlayer(), getSkillLevel(), activationChance)) {
|
2013-10-09 16:27:06 +02:00
|
|
|
for (ItemStack item : drops) {
|
2016-03-16 17:47:40 +01:00
|
|
|
Misc.dropItems(Misc.getBlockCenter(blockState), item, amount);
|
2013-10-09 16:27:06 +02:00
|
|
|
}
|
2013-03-08 10:11:33 +01:00
|
|
|
}
|
|
|
|
}
|
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) {
|
2013-11-22 18:48:53 +01:00
|
|
|
if (!SkillUtils.activationSuccessful(SecondaryAbility.GREEN_THUMB_BLOCK, getPlayer(), getSkillLevel(), activationChance)) {
|
2013-03-04 15:40:03 +01:00
|
|
|
getPlayer().sendMessage(LocaleLoader.getString("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) {
|
2013-11-22 18:48:53 +01:00
|
|
|
if (!SkillUtils.activationSuccessful(SecondaryAbility.HYLIAN_LUCK, getPlayer(), getSkillLevel(), activationChance)) {
|
2013-03-01 06:52:01 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-06-10 20:16:31 +02:00
|
|
|
String friendly = StringUtils.getFriendlyConfigMaterialDataString(blockState.getData());
|
|
|
|
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) {
|
|
|
|
if (skillLevel >= treasure.getDropLevel() && SkillUtils.treasureDropSuccessful(getPlayer(), treasure.getDropChance(), activationChance)) {
|
|
|
|
if (!EventUtils.simulateBlockBreak(blockState.getBlock(), player, false)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
blockState.setType(Material.AIR);
|
|
|
|
Misc.dropItem(location, treasure.getDrop());
|
|
|
|
player.sendMessage(LocaleLoader.getString("Herbalism.HylianLuck"));
|
|
|
|
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)) {
|
2013-03-01 06:52:01 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Skills.NeedMore", StringUtils.getPrettyItemString(Material.BROWN_MUSHROOM)));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-12 19:35:19 +01:00
|
|
|
if (!playerInventory.contains(Material.RED_MUSHROOM, 1)) {
|
2013-03-01 06:52:01 +01:00
|
|
|
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();
|
|
|
|
|
2013-11-22 18:48:53 +01:00
|
|
|
if (!SkillUtils.activationSuccessful(SecondaryAbility.SHROOM_THUMB, getPlayer(), getSkillLevel(), activationChance)) {
|
2013-03-01 06:52:01 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.ShroomThumb.Fail"));
|
|
|
|
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) {
|
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()) {
|
|
|
|
case CARROT:
|
2016-03-18 01:18:40 +01:00
|
|
|
seed = Material.CARROT_ITEM;
|
2013-10-09 16:27:06 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CROPS:
|
2016-03-18 01:18:40 +01:00
|
|
|
seed = Material.SEEDS;
|
2013-10-09 16:27:06 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NETHER_WARTS:
|
2016-03-18 01:18:40 +01:00
|
|
|
seed = Material.NETHER_STALK;
|
2013-10-09 16:27:06 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case POTATO:
|
2016-03-18 01:18:40 +01:00
|
|
|
seed = Material.POTATO_ITEM;
|
2013-10-09 16:27:06 +02:00
|
|
|
break;
|
2016-06-26 23:14:19 +02:00
|
|
|
|
2016-06-19 23:33:43 +02:00
|
|
|
case BEETROOT_BLOCK:
|
|
|
|
seed = Material.BEETROOT_SEEDS;
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (!playerInventory.containsAtLeast(seedStack, 1)) {
|
2013-03-01 06:52:01 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-22 18:48:53 +01:00
|
|
|
if (!greenTerra && !SkillUtils.activationSuccessful(SecondaryAbility.GREEN_THUMB_PLANT, getPlayer(), getSkillLevel(), activationChance)) {
|
2013-03-01 06:52:01 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-08 10:11:33 +01:00
|
|
|
if (!handleBlockState(blockState, greenTerra)) {
|
2013-03-01 06:52:01 +01:00
|
|
|
return;
|
|
|
|
}
|
2013-03-08 10:11:33 +01:00
|
|
|
|
2017-09-01 05:47:28 +02:00
|
|
|
playerInventory.removeItem(seedStack);
|
2013-03-08 10:11:33 +01:00
|
|
|
player.updateInventory(); // Needed until replacement available
|
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) {
|
2013-09-05 22:36:02 +02:00
|
|
|
byte greenThumbStage = getGreenThumbStage();
|
|
|
|
|
2014-04-06 14:41:40 +02:00
|
|
|
blockState.setMetadata(mcMMO.greenThumbDataKey, new FixedMetadataValue(mcMMO.p, (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR)));
|
|
|
|
|
2013-03-08 10:11:33 +01:00
|
|
|
switch (blockState.getType()) {
|
2016-06-26 23:14:19 +02:00
|
|
|
|
|
|
|
case POTATO:
|
|
|
|
case CARROT:
|
|
|
|
case BEETROOT_BLOCK:
|
2013-03-08 10:11:33 +01:00
|
|
|
case CROPS:
|
2013-09-05 22:36:02 +02:00
|
|
|
Crops crops = (Crops) blockState.getData();
|
|
|
|
|
|
|
|
if (greenTerra) {
|
|
|
|
crops.setState(CropState.MEDIUM);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
switch (greenThumbStage) {
|
|
|
|
case 4:
|
|
|
|
crops.setState(CropState.SMALL);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
crops.setState(CropState.VERY_SMALL);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
crops.setState(CropState.GERMINATED);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
crops.setState(CropState.SEEDED);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
2013-03-08 10:11:33 +01:00
|
|
|
case NETHER_WARTS:
|
2013-04-05 04:24:02 +02:00
|
|
|
NetherWarts warts = (NetherWarts) blockState.getData();
|
|
|
|
|
2013-09-05 22:36:02 +02:00
|
|
|
if (greenTerra || greenThumbStage > 2) {
|
2013-04-05 04:24:02 +02:00
|
|
|
warts.setState(NetherWartsState.STAGE_TWO);
|
2013-03-08 10:11:33 +01:00
|
|
|
}
|
2013-09-05 22:36:02 +02:00
|
|
|
else if (greenThumbStage == 2) {
|
|
|
|
warts.setState(NetherWartsState.STAGE_ONE);
|
|
|
|
}
|
2013-03-08 10:11:33 +01:00
|
|
|
else {
|
2013-09-05 22:36:02 +02:00
|
|
|
warts.setState(NetherWartsState.SEEDED);
|
2013-03-08 10:11:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case COCOA:
|
|
|
|
CocoaPlant plant = (CocoaPlant) blockState.getData();
|
|
|
|
|
|
|
|
if (greenTerra || getGreenThumbStage() > 1) {
|
|
|
|
plant.setSize(CocoaPlantSize.MEDIUM);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
plant.setSize(CocoaPlantSize.SMALL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private byte getGreenThumbStage() {
|
2013-10-29 16:02:57 +01:00
|
|
|
return (byte) Math.min(Math.min(getSkillLevel(), Herbalism.greenThumbStageMaxLevel) / Herbalism.greenThumbStageChangeLevel, 4);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
}
|