mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-28 03:34:43 +02:00
Change from using Block to BlockState in many locations
Convert Herbalism ability to use BlockState instead of Block. Move all block checks back to BlockChecks. Don't need this if we're using BlockState Convert Excavation to BlockState. We don't need to return booleans here because we never edit the block state.Switch ModCheck.getCustomBlock to use BlockState More work on the conversion to BlockState More conversion to BlockState Better way to handle mining drops, I believe. Remove useless imports. A test of making the diff look nicer BlockChecks diff cleanup Herbalism diff cleanup Gotta update the block states here. Moar blockstate. Little more blockState stuff. Even more blockstate.
This commit is contained in:
@ -1,86 +0,0 @@
|
||||
package com.gmail.nossr50.skills.herbalism;
|
||||
|
||||
import org.bukkit.CropState;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.material.CocoaPlant;
|
||||
import org.bukkit.material.CocoaPlant.CocoaPlantSize;
|
||||
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.skills.utilities.AbilityType;
|
||||
import com.gmail.nossr50.skills.utilities.SkillType;
|
||||
|
||||
public class GreenThumbTimer implements Runnable {
|
||||
private Block block;
|
||||
private PlayerProfile profile;
|
||||
private Material type;
|
||||
|
||||
public GreenThumbTimer(Block block, PlayerProfile profile, Material material) {
|
||||
this.block = block;
|
||||
this.profile = profile;
|
||||
this.type = material;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
this.block.setType(this.type);
|
||||
|
||||
int skillLevel = this.profile.getSkillLevel(SkillType.HERBALISM);
|
||||
int greenThumbStage = skillLevel / Herbalism.greenThumbStageChangeLevel;
|
||||
|
||||
if (greenThumbStage > 4) {
|
||||
greenThumbStage = 4;
|
||||
}
|
||||
|
||||
switch(this.type) {
|
||||
case CROPS:
|
||||
case CARROT:
|
||||
case POTATO:
|
||||
//This replants the wheat at a certain stage in development based on Herbalism Skill
|
||||
if (!this.profile.getAbilityMode(AbilityType.GREEN_TERRA)) {
|
||||
this.block.setData((byte) greenThumbStage);
|
||||
}
|
||||
else {
|
||||
this.block.setData(CropState.MEDIUM.getData());
|
||||
}
|
||||
break;
|
||||
case NETHER_WARTS:
|
||||
if (!this.profile.getAbilityMode(AbilityType.GREEN_TERRA)) {
|
||||
if (greenThumbStage == 3) {
|
||||
this.block.setData((byte) 0x2);
|
||||
}
|
||||
else if (greenThumbStage == 2) {
|
||||
this.block.setData((byte) 0x1);
|
||||
}
|
||||
else {
|
||||
this.block.setData((byte) 0x0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.block.setData((byte) 0x2);
|
||||
}
|
||||
break;
|
||||
case COCOA:
|
||||
CocoaPlant plant = (CocoaPlant) block.getState().getData();
|
||||
|
||||
if (!this.profile.getAbilityMode(AbilityType.GREEN_TERRA)) {
|
||||
if (greenThumbStage == 3) {
|
||||
plant.setSize(CocoaPlantSize.MEDIUM);
|
||||
}
|
||||
else if (greenThumbStage == 2) {
|
||||
plant.setSize(CocoaPlantSize.MEDIUM);
|
||||
}
|
||||
else {
|
||||
plant.setSize(CocoaPlantSize.SMALL);
|
||||
}
|
||||
}
|
||||
else {
|
||||
plant.setSize(CocoaPlantSize.MEDIUM);
|
||||
}
|
||||
block.setData(plant.getData());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
@ -3,29 +3,29 @@ package com.gmail.nossr50.skills.herbalism;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.CropState;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
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.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.config.TreasuresConfig;
|
||||
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.treasure.HylianTreasure;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.mods.ModChecks;
|
||||
import com.gmail.nossr50.mods.datatypes.CustomBlock;
|
||||
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.SkillType;
|
||||
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"));
|
||||
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
|
||||
|
||||
return convertGreenTerraBlocks(blockState, player);
|
||||
}
|
||||
|
||||
public static void greenTerraConvert(Player player, Block block) {
|
||||
if (SkillTools.blockBreakSimulate(block, player, false)) {
|
||||
Material type = block.getType();
|
||||
/**
|
||||
* 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();
|
||||
|
||||
if (!Permissions.greenThumbBlock(player, type)) {
|
||||
return;
|
||||
}
|
||||
if (!Permissions.greenThumbBlock(player, blockType)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case SMOOTH_BRICK:
|
||||
block.setData((byte) 0x1);
|
||||
return;
|
||||
switch (blockType) {
|
||||
case COBBLE_WALL:
|
||||
case SMOOTH_BRICK:
|
||||
blockState.setRawData((byte) 0x1);
|
||||
return true;
|
||||
|
||||
case DIRT:
|
||||
block.setType(Material.GRASS);
|
||||
return;
|
||||
case DIRT:
|
||||
blockState.setType(Material.GRASS);
|
||||
return true;
|
||||
|
||||
case COBBLESTONE:
|
||||
block.setType(Material.MOSSY_COBBLESTONE);
|
||||
return;
|
||||
case COBBLESTONE:
|
||||
blockState.setType(Material.MOSSY_COBBLESTONE);
|
||||
return true;
|
||||
|
||||
case COBBLE_WALL:
|
||||
block.setData((byte) 0x1);
|
||||
return;
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
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++;
|
||||
}
|
||||
}
|
||||
@ -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()) {
|
||||
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);
|
||||
CustomBlock customBlock = null;
|
||||
@ -154,199 +173,226 @@ public class Herbalism {
|
||||
int xp = 0;
|
||||
int dropAmount = 1;
|
||||
ItemStack dropItem = null;
|
||||
boolean update = false;
|
||||
|
||||
if (herbalismBlock != null) {
|
||||
if (blockType == Material.CACTUS || blockType == Material.SUGAR_CANE_BLOCK) {
|
||||
dropItem = herbalismBlock.getDropItem();
|
||||
dropAmount = calculateCatciAndSugarDrops(block);
|
||||
dropAmount = calculateCatciAndSugarDrops(blockState);
|
||||
xp = herbalismBlock.getXpGain() * dropAmount;
|
||||
}
|
||||
else if (herbalismBlock.hasGreenThumbPermission(player)){
|
||||
dropItem = herbalismBlock.getDropItem();
|
||||
xp = herbalismBlock.getXpGain();
|
||||
|
||||
greenThumbWheat(block, player, plugin);
|
||||
update = processGreenThumbPlants(blockState, player);
|
||||
}
|
||||
else {
|
||||
if (!mcMMO.placeStore.isTrue(block)) {
|
||||
if (!mcMMO.placeStore.isTrue(blockState)) {
|
||||
dropItem = herbalismBlock.getDropItem();
|
||||
xp = herbalismBlock.getXpGain();
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
customBlock = ModChecks.getCustomBlock(block);
|
||||
customBlock = ModChecks.getCustomBlock(blockState);
|
||||
dropItem = customBlock.getItemDrop();
|
||||
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:
|
||||
hasSeeds = inventory.contains(Material.SEEDS);
|
||||
break;
|
||||
case COCOA:
|
||||
hasSeeds = inventory.containsAtLeast(new ItemStack(Material.INK_SACK, 1, DyeColor.BROWN.getDyeData()), 1);
|
||||
break;
|
||||
case CARROT:
|
||||
hasSeeds = inventory.contains(Material.CARROT_ITEM);
|
||||
break;
|
||||
case POTATO:
|
||||
hasSeeds = inventory.contains(Material.POTATO_ITEM);
|
||||
break;
|
||||
blockState.setRawData(CropState.MEDIUM.getData());
|
||||
return true;
|
||||
|
||||
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:
|
||||
break;
|
||||
}
|
||||
|
||||
if (!hasSeeds) {
|
||||
return;
|
||||
}
|
||||
|
||||
int activationChance = PerksUtils.handleLuckyPerks(player, SkillType.HERBALISM);
|
||||
float chance = (float) (greenThumbMaxChance / greenThumbMaxLevel * herbLevel);
|
||||
|
||||
if (chance > greenThumbMaxChance) {
|
||||
chance = (float) greenThumbMaxChance;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new GreenThumbTimer(block, profile, type), 0);
|
||||
player.updateInventory(); // Needed until replacement available
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the Green Thumb ability to blocks.
|
||||
* Process the Green Thumb ability for blocks.
|
||||
*
|
||||
* @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();
|
||||
|
||||
player.setItemInHand(new ItemStack(Material.SEEDS, seeds - 1));
|
||||
|
||||
int activationChance = PerksUtils.handleLuckyPerks(player, SkillType.HERBALISM);
|
||||
|
||||
float chance = (float) ((greenThumbMaxChance / greenThumbMaxLevel) * skillLevel);
|
||||
if (chance > greenThumbMaxChance) chance = (float) greenThumbMaxChance;
|
||||
|
||||
if (chance > Misc.getRandom().nextInt(activationChance)) {
|
||||
greenTerraConvert(player, block);
|
||||
}
|
||||
else {
|
||||
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;
|
||||
}
|
||||
|
||||
return convertGreenTerraBlocks(blockState, player);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public static void hylianLuck(Block block, Player player, BlockBreakEvent event) {
|
||||
int skillLevel = Users.getPlayer(player).getProfile().getSkillLevel(SkillType.HERBALISM);
|
||||
/**
|
||||
* Process the Green Thumb ability for plants.
|
||||
*
|
||||
* @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 processGreenThumbPlants(BlockState blockState, Player player) {
|
||||
PlayerInventory playerInventory = player.getInventory();
|
||||
ItemStack seed = HerbalismBlock.getHerbalismBlock(blockState.getType()).getDropItem();
|
||||
|
||||
double chance = (hylianLuckMaxChance / hylianLuckMaxLevel) * SkillTools.skillCheck(skillLevel, hylianLuckMaxLevel);
|
||||
int activationChance = PerksUtils.handleLuckyPerks(player, SkillType.HERBALISM);
|
||||
|
||||
if (chance > Misc.getRandom().nextInt(activationChance)) {
|
||||
List<HylianTreasure> treasures = new ArrayList<HylianTreasure>();
|
||||
|
||||
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(block)) {
|
||||
mcMMO.placeStore.setFalse(block);
|
||||
return;
|
||||
}
|
||||
|
||||
treasures = TreasuresConfig.getInstance().hylianFromFlowers;
|
||||
break;
|
||||
|
||||
case FLOWER_POT:
|
||||
treasures = TreasuresConfig.getInstance().hylianFromPots;
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
if (treasures.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
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"));
|
||||
if (!playerInventory.containsAtLeast(seed, 1)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
PlayerProfile playerProfile = Users.getPlayer(player).getProfile();
|
||||
|
||||
if (playerProfile.getAbilityMode(AbilityType.GREEN_TERRA)) {
|
||||
playerInventory.removeItem(seed);
|
||||
player.updateInventory(); // Needed until replacement available
|
||||
|
||||
return convertGreenTerraPlants(blockState);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
List<HylianTreasure> treasures = new ArrayList<HylianTreasure>();
|
||||
|
||||
switch (blockState.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;
|
||||
}
|
||||
|
||||
treasures = TreasuresConfig.getInstance().hylianFromFlowers;
|
||||
break;
|
||||
|
||||
case FLOWER_POT:
|
||||
treasures = TreasuresConfig.getInstance().hylianFromPots;
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
if (treasures.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
blockState.setRawData((byte) 0x0);
|
||||
blockState.setType(Material.AIR);
|
||||
|
||||
Misc.dropItem(blockState.getLocation(), treasures.get(Misc.getRandom().nextInt(treasures.size())).getDrop());
|
||||
player.sendMessage(LocaleLoader.getString("Herbalism.HylianLuck"));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user