|
@@ -3,29 +3,29 @@ package com.gmail.nossr50.skills.herbalism;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
-import org.bukkit.DyeColor;
|
|
|
|
|
|
+import org.bukkit.CropState;
|
|
import org.bukkit.Location;
|
|
import org.bukkit.Location;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.block.Block;
|
|
import org.bukkit.block.Block;
|
|
import org.bukkit.block.BlockFace;
|
|
import org.bukkit.block.BlockFace;
|
|
|
|
+import org.bukkit.block.BlockState;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.entity.Player;
|
|
-import org.bukkit.event.block.BlockBreakEvent;
|
|
|
|
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
|
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
|
import org.bukkit.inventory.ItemStack;
|
|
import org.bukkit.inventory.ItemStack;
|
|
import org.bukkit.inventory.PlayerInventory;
|
|
import org.bukkit.inventory.PlayerInventory;
|
|
|
|
+import org.bukkit.material.CocoaPlant;
|
|
|
|
+import org.bukkit.material.CocoaPlant.CocoaPlantSize;
|
|
|
|
|
|
import com.gmail.nossr50.mcMMO;
|
|
import com.gmail.nossr50.mcMMO;
|
|
import com.gmail.nossr50.config.AdvancedConfig;
|
|
import com.gmail.nossr50.config.AdvancedConfig;
|
|
import com.gmail.nossr50.config.Config;
|
|
import com.gmail.nossr50.config.Config;
|
|
import com.gmail.nossr50.config.TreasuresConfig;
|
|
import com.gmail.nossr50.config.TreasuresConfig;
|
|
-import com.gmail.nossr50.datatypes.McMMOPlayer;
|
|
|
|
import com.gmail.nossr50.datatypes.PlayerProfile;
|
|
import com.gmail.nossr50.datatypes.PlayerProfile;
|
|
import com.gmail.nossr50.datatypes.treasure.HylianTreasure;
|
|
import com.gmail.nossr50.datatypes.treasure.HylianTreasure;
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
|
import com.gmail.nossr50.mods.ModChecks;
|
|
import com.gmail.nossr50.mods.ModChecks;
|
|
import com.gmail.nossr50.mods.datatypes.CustomBlock;
|
|
import com.gmail.nossr50.mods.datatypes.CustomBlock;
|
|
import com.gmail.nossr50.skills.utilities.AbilityType;
|
|
import com.gmail.nossr50.skills.utilities.AbilityType;
|
|
-import com.gmail.nossr50.skills.utilities.PerksUtils;
|
|
|
|
import com.gmail.nossr50.skills.utilities.SkillTools;
|
|
import com.gmail.nossr50.skills.utilities.SkillTools;
|
|
import com.gmail.nossr50.skills.utilities.SkillType;
|
|
import com.gmail.nossr50.skills.utilities.SkillType;
|
|
import com.gmail.nossr50.util.Misc;
|
|
import com.gmail.nossr50.util.Misc;
|
|
@@ -65,63 +65,87 @@ public class Herbalism {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Activate the Green Terra ability.
|
|
|
|
|
|
+ * Process the Green Terra ability.
|
|
*
|
|
*
|
|
- * @param player The player activating the ability
|
|
|
|
- * @param block The block to be changed by Green Terra
|
|
|
|
|
|
+ * @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 void greenTerra(Player player, Block block) {
|
|
|
|
- PlayerInventory inventory = player.getInventory();
|
|
|
|
- boolean hasSeeds = inventory.contains(Material.SEEDS);
|
|
|
|
|
|
+ public static boolean processGreenTerra(BlockState blockState, Player player) {
|
|
|
|
+ PlayerInventory playerInventory = player.getInventory();
|
|
|
|
+ ItemStack seed = new ItemStack(Material.SEEDS);
|
|
|
|
|
|
- if (!hasSeeds) {
|
|
|
|
|
|
+ if (!playerInventory.containsAtLeast(seed, 1)) {
|
|
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTe.NeedMore"));
|
|
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTe.NeedMore"));
|
|
- return;
|
|
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
|
|
|
|
- inventory.removeItem(new ItemStack(Material.SEEDS));
|
|
|
|
- player.updateInventory(); // Needed until replacement available
|
|
|
|
- greenTerraConvert(player, block);
|
|
|
|
- }
|
|
|
|
|
|
+ playerInventory.removeItem(seed);
|
|
|
|
+ player.updateInventory(); // Needed until replacement available
|
|
|
|
|
|
- public static void greenTerraConvert(Player player, Block block) {
|
|
|
|
- if (SkillTools.blockBreakSimulate(block, player, false)) {
|
|
|
|
- Material type = block.getType();
|
|
|
|
|
|
+ return convertGreenTerraBlocks(blockState, player);
|
|
|
|
+ }
|
|
|
|
|
|
- if (!Permissions.greenThumbBlock(player, type)) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 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 convertGreenTerraBlocks(BlockState blockState, Player player) {
|
|
|
|
+ Material blockType = blockState.getType();
|
|
|
|
|
|
- switch (type) {
|
|
|
|
- case SMOOTH_BRICK:
|
|
|
|
- block.setData((byte) 0x1);
|
|
|
|
- return;
|
|
|
|
|
|
+ if (!Permissions.greenThumbBlock(player, blockType)) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
|
|
- case DIRT:
|
|
|
|
- block.setType(Material.GRASS);
|
|
|
|
- return;
|
|
|
|
|
|
+ switch (blockType) {
|
|
|
|
+ case COBBLE_WALL:
|
|
|
|
+ case SMOOTH_BRICK:
|
|
|
|
+ blockState.setRawData((byte) 0x1);
|
|
|
|
+ return true;
|
|
|
|
|
|
- case COBBLESTONE:
|
|
|
|
- block.setType(Material.MOSSY_COBBLESTONE);
|
|
|
|
- return;
|
|
|
|
|
|
+ case DIRT:
|
|
|
|
+ blockState.setType(Material.GRASS);
|
|
|
|
+ return true;
|
|
|
|
|
|
- case COBBLE_WALL:
|
|
|
|
- block.setData((byte) 0x1);
|
|
|
|
- return;
|
|
|
|
|
|
+ case COBBLESTONE:
|
|
|
|
+ blockState.setType(Material.MOSSY_COBBLESTONE);
|
|
|
|
+ return true;
|
|
|
|
|
|
- default:
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
|
|
+ default:
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private static int calculateCatciAndSugarDrops(Block block) {
|
|
|
|
- Material blockType = block.getType();
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Calculate the drop amounts for cacti & sugar cane based on the blocks above them.
|
|
|
|
+ *
|
|
|
|
+ * @param blockState The {@link BlockState} of the bottom block of the plant
|
|
|
|
+ * @return the number of bonus drops to award from the blocks in this plant
|
|
|
|
+ */
|
|
|
|
+ private static int calculateCatciAndSugarDrops(BlockState blockState) {
|
|
|
|
+ Block block = blockState.getBlock();
|
|
|
|
+ Material blockType = blockState.getType();
|
|
int dropAmount = 0;
|
|
int dropAmount = 0;
|
|
|
|
|
|
- for (int y = 0; y <= 2; y++) {
|
|
|
|
|
|
+ // Handle the original block
|
|
|
|
+ if (!mcMMO.placeStore.isTrue(blockState)) {
|
|
|
|
+ dropAmount++;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Handle the two blocks above it - cacti & sugar cane can only grow 3 high naturally
|
|
|
|
+ for (int y = 1; y < 3; y++) {
|
|
Block relativeBlock = block.getRelative(BlockFace.UP, y);
|
|
Block relativeBlock = block.getRelative(BlockFace.UP, y);
|
|
- if (relativeBlock.getType() == blockType && !mcMMO.placeStore.isTrue(relativeBlock)) {
|
|
|
|
|
|
+ Material relativeBlockType = relativeBlock.getType();
|
|
|
|
+
|
|
|
|
+ // If the first one is air, so is the next one
|
|
|
|
+ if (relativeBlockType == Material.AIR) {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (relativeBlockType == blockType && !mcMMO.placeStore.isTrue(relativeBlock)) {
|
|
dropAmount++;
|
|
dropAmount++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -130,23 +154,18 @@ public class Herbalism {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Check for extra Herbalism drops.
|
|
|
|
|
|
+ * Process double drops & XP gain for Herbalism.
|
|
*
|
|
*
|
|
- * @param block The block to check for extra drops
|
|
|
|
- * @param mcMMOPlayer The player getting extra drops
|
|
|
|
- * @param event The event to use for Green Thumb
|
|
|
|
- * @param plugin mcMMO plugin instance
|
|
|
|
|
|
+ * @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 void herbalismProcCheck(final Block block, McMMOPlayer mcMMOPlayer, mcMMO plugin) {
|
|
|
|
- Player player = mcMMOPlayer.getPlayer();
|
|
|
|
-
|
|
|
|
|
|
+ public static boolean herbalismBlockCheck(BlockState blockState, Player player) {
|
|
if (Config.getInstance().getHerbalismAFKDisabled() && player.isInsideVehicle()) {
|
|
if (Config.getInstance().getHerbalismAFKDisabled() && player.isInsideVehicle()) {
|
|
- return;
|
|
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
|
|
|
|
- PlayerProfile profile = mcMMOPlayer.getProfile();
|
|
|
|
- int herbLevel = profile.getSkillLevel(SkillType.HERBALISM);
|
|
|
|
- Material blockType = block.getType();
|
|
|
|
|
|
+ Material blockType = blockState.getType();
|
|
|
|
|
|
HerbalismBlock herbalismBlock = HerbalismBlock.getHerbalismBlock(blockType);
|
|
HerbalismBlock herbalismBlock = HerbalismBlock.getHerbalismBlock(blockType);
|
|
CustomBlock customBlock = null;
|
|
CustomBlock customBlock = null;
|
|
@@ -154,199 +173,226 @@ public class Herbalism {
|
|
int xp = 0;
|
|
int xp = 0;
|
|
int dropAmount = 1;
|
|
int dropAmount = 1;
|
|
ItemStack dropItem = null;
|
|
ItemStack dropItem = null;
|
|
|
|
+ boolean update = false;
|
|
|
|
|
|
if (herbalismBlock != null) {
|
|
if (herbalismBlock != null) {
|
|
if (blockType == Material.CACTUS || blockType == Material.SUGAR_CANE_BLOCK) {
|
|
if (blockType == Material.CACTUS || blockType == Material.SUGAR_CANE_BLOCK) {
|
|
dropItem = herbalismBlock.getDropItem();
|
|
dropItem = herbalismBlock.getDropItem();
|
|
- dropAmount = calculateCatciAndSugarDrops(block);
|
|
|
|
|
|
+ dropAmount = calculateCatciAndSugarDrops(blockState);
|
|
xp = herbalismBlock.getXpGain() * dropAmount;
|
|
xp = herbalismBlock.getXpGain() * dropAmount;
|
|
}
|
|
}
|
|
else if (herbalismBlock.hasGreenThumbPermission(player)){
|
|
else if (herbalismBlock.hasGreenThumbPermission(player)){
|
|
dropItem = herbalismBlock.getDropItem();
|
|
dropItem = herbalismBlock.getDropItem();
|
|
xp = herbalismBlock.getXpGain();
|
|
xp = herbalismBlock.getXpGain();
|
|
-
|
|
|
|
- greenThumbWheat(block, player, plugin);
|
|
|
|
|
|
+ update = processGreenThumbPlants(blockState, player);
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
- if (!mcMMO.placeStore.isTrue(block)) {
|
|
|
|
|
|
+ if (!mcMMO.placeStore.isTrue(blockState)) {
|
|
dropItem = herbalismBlock.getDropItem();
|
|
dropItem = herbalismBlock.getDropItem();
|
|
xp = herbalismBlock.getXpGain();
|
|
xp = herbalismBlock.getXpGain();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
- customBlock = ModChecks.getCustomBlock(block);
|
|
|
|
|
|
+ customBlock = ModChecks.getCustomBlock(blockState);
|
|
dropItem = customBlock.getItemDrop();
|
|
dropItem = customBlock.getItemDrop();
|
|
xp = customBlock.getXpGain();
|
|
xp = customBlock.getXpGain();
|
|
}
|
|
}
|
|
|
|
|
|
- if (Permissions.doubleDrops(player, SkillType.HERBALISM)) {
|
|
|
|
- int activationChance = PerksUtils.handleLuckyPerks(player, SkillType.HERBALISM);
|
|
|
|
- double chance = (doubleDropsMaxChance / doubleDropsMaxLevel) * SkillTools.skillCheck(herbLevel, doubleDropsMaxLevel);
|
|
|
|
|
|
+ if (Permissions.doubleDrops(player, SkillType.HERBALISM) && SkillTools.activationSuccessful(player, SkillType.HERBALISM, doubleDropsMaxChance, doubleDropsMaxLevel)) {
|
|
|
|
+ Location location = blockState.getLocation();
|
|
|
|
|
|
- if (chance > Misc.getRandom().nextInt(activationChance)) {
|
|
|
|
- Location location = block.getLocation();
|
|
|
|
|
|
+ if (dropItem != null && herbalismBlock != null && herbalismBlock.canDoubleDrop()) {
|
|
|
|
+ Misc.dropItems(location, dropItem, dropAmount);
|
|
|
|
+ }
|
|
|
|
+ else if (customBlock != null){
|
|
|
|
+ int minimumDropAmount = customBlock.getMinimumDropAmount();
|
|
|
|
+ int maximumDropAmount = customBlock.getMaximumDropAmount();
|
|
|
|
|
|
- if (dropItem != null && herbalismBlock != null && herbalismBlock.canDoubleDrop()) {
|
|
|
|
- Misc.dropItems(location, dropItem, dropAmount);
|
|
|
|
|
|
+ if (minimumDropAmount != maximumDropAmount) {
|
|
|
|
+ Misc.randomDropItems(location, dropItem, maximumDropAmount - minimumDropAmount);
|
|
}
|
|
}
|
|
- else if (customBlock != null){
|
|
|
|
- int minimumDropAmount = customBlock.getMinimumDropAmount();
|
|
|
|
- int maximumDropAmount = customBlock.getMaximumDropAmount();
|
|
|
|
|
|
|
|
- if (minimumDropAmount != maximumDropAmount) {
|
|
|
|
- Misc.randomDropItems(location, dropItem, maximumDropAmount - minimumDropAmount);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- Misc.dropItems(location, dropItem, minimumDropAmount);
|
|
|
|
- }
|
|
|
|
|
|
+ Misc.dropItems(location, dropItem, minimumDropAmount);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- mcMMOPlayer.beginXpGain(SkillType.HERBALISM, xp);
|
|
|
|
|
|
+ Users.getPlayer(player).beginXpGain(SkillType.HERBALISM, xp);
|
|
|
|
+ return update;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Apply the Green Thumb ability to crops.
|
|
|
|
|
|
+ * Convert plants affected by the Green Terra ability.
|
|
*
|
|
*
|
|
- * @param block The block to apply the ability to
|
|
|
|
- * @param player The player using the ability
|
|
|
|
- * @param event The event triggering the ability
|
|
|
|
- * @param plugin mcMMO plugin instance
|
|
|
|
|
|
+ * @param blockState The {@link BlockState} to check ability activation for
|
|
|
|
+ * @return true if the ability was successful, false otherwise
|
|
*/
|
|
*/
|
|
- private static void greenThumbWheat(Block block, Player player, mcMMO plugin) {
|
|
|
|
- PlayerProfile profile = Users.getPlayer(player).getProfile();
|
|
|
|
- int herbLevel = profile.getSkillLevel(SkillType.HERBALISM);
|
|
|
|
- PlayerInventory inventory = player.getInventory();
|
|
|
|
- boolean hasSeeds = false;
|
|
|
|
- Material type = block.getType();
|
|
|
|
-
|
|
|
|
- switch(type) {
|
|
|
|
|
|
+ private static boolean convertGreenTerraPlants(BlockState blockState) {
|
|
|
|
+ switch (blockState.getType()) {
|
|
case CROPS:
|
|
case CROPS:
|
|
- hasSeeds = inventory.contains(Material.SEEDS);
|
|
|
|
- break;
|
|
|
|
- case COCOA:
|
|
|
|
- hasSeeds = inventory.containsAtLeast(new ItemStack(Material.INK_SACK, 1, DyeColor.BROWN.getDyeData()), 1);
|
|
|
|
- break;
|
|
|
|
case CARROT:
|
|
case CARROT:
|
|
- hasSeeds = inventory.contains(Material.CARROT_ITEM);
|
|
|
|
- break;
|
|
|
|
case POTATO:
|
|
case POTATO:
|
|
- hasSeeds = inventory.contains(Material.POTATO_ITEM);
|
|
|
|
- break;
|
|
|
|
|
|
+ blockState.setRawData(CropState.MEDIUM.getData());
|
|
|
|
+ return true;
|
|
|
|
+
|
|
case NETHER_WARTS:
|
|
case NETHER_WARTS:
|
|
- hasSeeds = inventory.contains(Material.NETHER_STALK);
|
|
|
|
- break;
|
|
|
|
|
|
+ blockState.setRawData((byte) 0x2);
|
|
|
|
+ return true;
|
|
|
|
+
|
|
|
|
+ case COCOA:
|
|
|
|
+ CocoaPlant plant = (CocoaPlant) blockState.getData();
|
|
|
|
+ plant.setSize(CocoaPlantSize.MEDIUM);
|
|
|
|
+ blockState.setData(plant);
|
|
|
|
+ return true;
|
|
|
|
+
|
|
default:
|
|
default:
|
|
- break;
|
|
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
|
|
- if (!hasSeeds) {
|
|
|
|
- return;
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Process the Green Thumb ability for blocks.
|
|
|
|
+ *
|
|
|
|
+ * @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 processGreenThumbBlocks(BlockState blockState, Player player) {
|
|
|
|
+ if (!SkillTools.activationSuccessful(player, SkillType.HERBALISM, greenThumbMaxChance, greenThumbMaxLevel)) {
|
|
|
|
+ player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTh.Fail"));
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
|
|
|
|
- int activationChance = PerksUtils.handleLuckyPerks(player, SkillType.HERBALISM);
|
|
|
|
- float chance = (float) (greenThumbMaxChance / greenThumbMaxLevel * herbLevel);
|
|
|
|
|
|
+ return convertGreenTerraBlocks(blockState, player);
|
|
|
|
+ }
|
|
|
|
|
|
- if (chance > greenThumbMaxChance) {
|
|
|
|
- chance = (float) greenThumbMaxChance;
|
|
|
|
- }
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Convert plants affected by the Green Thumb ability.
|
|
|
|
+ *
|
|
|
|
+ * @param blockState The {@link BlockState} to check ability activation for
|
|
|
|
+ * @param skillLevel The player's Herbalism skill level
|
|
|
|
+ * @return true if the ability was successful, false otherwise
|
|
|
|
+ */
|
|
|
|
+ private static boolean convertGreenThumbPlants(BlockState blockState, int skillLevel) {
|
|
|
|
+ int greenThumbStage = Math.min(skillLevel, greenThumbStageMaxLevel) / 4;
|
|
|
|
|
|
- if (profile.getAbilityMode(AbilityType.GREEN_TERRA) || chance > Misc.getRandom().nextInt(activationChance)) {
|
|
|
|
- switch(type) {
|
|
|
|
- case CROPS:
|
|
|
|
- inventory.removeItem(new ItemStack(Material.SEEDS));
|
|
|
|
- break;
|
|
|
|
- case COCOA:
|
|
|
|
- inventory.removeItem(new ItemStack(Material.INK_SACK, 1, DyeColor.BROWN.getDyeData()));
|
|
|
|
- break;
|
|
|
|
- case CARROT:
|
|
|
|
- inventory.removeItem(new ItemStack(Material.CARROT_ITEM));
|
|
|
|
- break;
|
|
|
|
- case POTATO:
|
|
|
|
- inventory.removeItem(new ItemStack(Material.POTATO_ITEM));
|
|
|
|
- break;
|
|
|
|
- case NETHER_WARTS:
|
|
|
|
- inventory.removeItem(new ItemStack(Material.NETHER_STALK));
|
|
|
|
- break;
|
|
|
|
- default:
|
|
|
|
- break;
|
|
|
|
|
|
+ switch(blockState.getType()) {
|
|
|
|
+ case CROPS:
|
|
|
|
+ case CARROT:
|
|
|
|
+ case POTATO:
|
|
|
|
+ blockState.setRawData((byte) greenThumbStage);
|
|
|
|
+ return true;
|
|
|
|
+
|
|
|
|
+ case NETHER_WARTS:
|
|
|
|
+ if (greenThumbStage > 2) {
|
|
|
|
+ blockState.setRawData((byte) 0x2);
|
|
}
|
|
}
|
|
|
|
+ else if (greenThumbStage == 2) {
|
|
|
|
+ blockState.setRawData((byte) 0x1);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ blockState.setRawData((byte) 0x0);
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
|
|
|
|
- plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new GreenThumbTimer(block, profile, type), 0);
|
|
|
|
- player.updateInventory(); // Needed until replacement available
|
|
|
|
|
|
+ case COCOA:
|
|
|
|
+ CocoaPlant plant = (CocoaPlant) blockState.getData();
|
|
|
|
+
|
|
|
|
+ if (greenThumbStage > 1) {
|
|
|
|
+ plant.setSize(CocoaPlantSize.MEDIUM);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ plant.setSize(CocoaPlantSize.SMALL);
|
|
|
|
+ }
|
|
|
|
+ blockState.setData(plant);
|
|
|
|
+ return true;
|
|
|
|
+
|
|
|
|
+ default:
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Apply the Green Thumb ability to blocks.
|
|
|
|
|
|
+ * Process the Green Thumb ability for plants.
|
|
*
|
|
*
|
|
- * @param is The item in the player's hand
|
|
|
|
- * @param player The player activating the ability
|
|
|
|
- * @param block The block being used in the 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 void greenThumbBlocks(ItemStack is, Player player, Block block) {
|
|
|
|
- PlayerProfile profile = Users.getPlayer(player).getProfile();
|
|
|
|
- int skillLevel = profile.getSkillLevel(SkillType.HERBALISM);
|
|
|
|
- int seeds = is.getAmount();
|
|
|
|
|
|
+ private static boolean processGreenThumbPlants(BlockState blockState, Player player) {
|
|
|
|
+ PlayerInventory playerInventory = player.getInventory();
|
|
|
|
+ ItemStack seed = HerbalismBlock.getHerbalismBlock(blockState.getType()).getDropItem();
|
|
|
|
|
|
- player.setItemInHand(new ItemStack(Material.SEEDS, seeds - 1));
|
|
|
|
|
|
+ if (!playerInventory.containsAtLeast(seed, 1)) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
|
|
- int activationChance = PerksUtils.handleLuckyPerks(player, SkillType.HERBALISM);
|
|
|
|
|
|
+ PlayerProfile playerProfile = Users.getPlayer(player).getProfile();
|
|
|
|
|
|
- float chance = (float) ((greenThumbMaxChance / greenThumbMaxLevel) * skillLevel);
|
|
|
|
- if (chance > greenThumbMaxChance) chance = (float) greenThumbMaxChance;
|
|
|
|
|
|
+ if (playerProfile.getAbilityMode(AbilityType.GREEN_TERRA)) {
|
|
|
|
+ playerInventory.removeItem(seed);
|
|
|
|
+ player.updateInventory(); // Needed until replacement available
|
|
|
|
|
|
- if (chance > Misc.getRandom().nextInt(activationChance)) {
|
|
|
|
- greenTerraConvert(player, block);
|
|
|
|
|
|
+ return convertGreenTerraPlants(blockState);
|
|
}
|
|
}
|
|
- else {
|
|
|
|
- player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTh.Fail"));
|
|
|
|
|
|
+ else if (SkillTools.activationSuccessful(player, SkillType.HERBALISM, greenThumbMaxChance, greenThumbMaxLevel)) {
|
|
|
|
+ playerInventory.removeItem(seed);
|
|
|
|
+ player.updateInventory(); // Needed until replacement available
|
|
|
|
+
|
|
|
|
+ return convertGreenThumbPlants(blockState, playerProfile.getSkillLevel(SkillType.HERBALISM));
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
|
|
|
|
- public static void hylianLuck(Block block, Player player, BlockBreakEvent event) {
|
|
|
|
- int skillLevel = Users.getPlayer(player).getProfile().getSkillLevel(SkillType.HERBALISM);
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Process the Hylian Luck 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 processHylianLuck(BlockState blockState, Player player) {
|
|
|
|
+ if (!SkillTools.activationSuccessful(player, SkillType.HERBALISM, hylianLuckMaxChance, hylianLuckMaxLevel)) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
|
|
- double chance = (hylianLuckMaxChance / hylianLuckMaxLevel) * SkillTools.skillCheck(skillLevel, hylianLuckMaxLevel);
|
|
|
|
- int activationChance = PerksUtils.handleLuckyPerks(player, SkillType.HERBALISM);
|
|
|
|
|
|
+ List<HylianTreasure> treasures = new ArrayList<HylianTreasure>();
|
|
|
|
|
|
- if (chance > Misc.getRandom().nextInt(activationChance)) {
|
|
|
|
- List<HylianTreasure> treasures = new ArrayList<HylianTreasure>();
|
|
|
|
|
|
+ switch (blockState.getType()) {
|
|
|
|
+ case DEAD_BUSH:
|
|
|
|
+ case LONG_GRASS:
|
|
|
|
+ case SAPLING:
|
|
|
|
+ treasures = TreasuresConfig.getInstance().hylianFromBushes;
|
|
|
|
+ break;
|
|
|
|
|
|
- switch (block.getType()) {
|
|
|
|
- case DEAD_BUSH:
|
|
|
|
- case LONG_GRASS:
|
|
|
|
- case SAPLING:
|
|
|
|
- treasures = TreasuresConfig.getInstance().hylianFromBushes;
|
|
|
|
- break;
|
|
|
|
|
|
+ case RED_ROSE:
|
|
|
|
+ case YELLOW_FLOWER:
|
|
|
|
+ if (mcMMO.placeStore.isTrue(blockState)) {
|
|
|
|
+ mcMMO.placeStore.setFalse(blockState);
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
|
|
- case RED_ROSE:
|
|
|
|
- case YELLOW_FLOWER:
|
|
|
|
- if (mcMMO.placeStore.isTrue(block)) {
|
|
|
|
- mcMMO.placeStore.setFalse(block);
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
|
|
+ treasures = TreasuresConfig.getInstance().hylianFromFlowers;
|
|
|
|
+ break;
|
|
|
|
|
|
- treasures = TreasuresConfig.getInstance().hylianFromFlowers;
|
|
|
|
- break;
|
|
|
|
|
|
+ case FLOWER_POT:
|
|
|
|
+ treasures = TreasuresConfig.getInstance().hylianFromPots;
|
|
|
|
+ break;
|
|
|
|
|
|
- case FLOWER_POT:
|
|
|
|
- treasures = TreasuresConfig.getInstance().hylianFromPots;
|
|
|
|
- break;
|
|
|
|
|
|
+ default:
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
|
|
- default:
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
|
|
+ if (treasures.isEmpty()) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
|
|
- if (treasures.isEmpty()) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
|
|
+ blockState.setRawData((byte) 0x0);
|
|
|
|
+ blockState.setType(Material.AIR);
|
|
|
|
|
|
- event.setCancelled(true);
|
|
|
|
- event.getBlock().setType(Material.AIR);
|
|
|
|
- Misc.dropItem(block.getLocation(), treasures.get(Misc.getRandom().nextInt(treasures.size())).getDrop());
|
|
|
|
- player.sendMessage(LocaleLoader.getString("Herbalism.HylianLuck"));
|
|
|
|
- }
|
|
|
|
|
|
+ Misc.dropItem(blockState.getLocation(), treasures.get(Misc.getRandom().nextInt(treasures.size())).getDrop());
|
|
|
|
+ player.sendMessage(LocaleLoader.getString("Herbalism.HylianLuck"));
|
|
|
|
+ return true;
|
|
}
|
|
}
|
|
}
|
|
}
|