mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 13:16:45 +01:00
Fixes #3832 - Resolved issue with double drops & herbalism, similar fixes coming to woodcutting/mining soon. Reminder to update config.yml, read changelog for instructions.
If you harvest crops with a Hoe it does not require seeds to replant on successful Green Thumb
This commit is contained in:
parent
ce6553d857
commit
255f7bf335
@ -11,6 +11,7 @@ Version 2.1.22
|
||||
Less aggressive spam click protection on Fishing
|
||||
Added all missing flowers to Double Drop tables for Herbalism
|
||||
Fixed Double Drop entries for all farming crops for Herbalism
|
||||
It no longer requires seeds to replant crops if you are harvesting crops with a hoe (will still consume seeds if you aren't)
|
||||
NOTE: You'll need to add these entries to your config.yml manually, or wait for the upcoming config update where this will be fixed for you automatically.
|
||||
NOTE: Here's what your Double_Drop entries in Config.yml for Herbalism should look like: https://paste.gg/p/anonymous/8d8db4ac69bd495fa48a7f5190484c5e
|
||||
|
||||
|
@ -3,8 +3,6 @@ package com.gmail.nossr50.commands.skills;
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.skills.smelting.Smelting;
|
||||
import com.gmail.nossr50.skills.smelting.SmeltingManager;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.TextComponentFactory;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
|
@ -35,6 +35,7 @@ import org.bukkit.Material;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.block.*;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -54,6 +55,22 @@ public class BlockListener implements Listener {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockDropItemEvent(BlockDropItemEvent event)
|
||||
{
|
||||
for(Item item : event.getItems())
|
||||
{
|
||||
ItemStack is = new ItemStack(item.getItemStack());
|
||||
if(event.getBlock().getState().getMetadata(mcMMO.doubleDropKey).size() > 0)
|
||||
event.getBlock().getState().getWorld().dropItemNaturally(event.getBlockState().getLocation(), is);
|
||||
else if(event.getBlock().getState().getMetadata(mcMMO.tripleDropKey).size() > 0)
|
||||
{
|
||||
event.getBlock().getState().getWorld().dropItemNaturally(event.getBlockState().getLocation(), is);
|
||||
event.getBlock().getState().getWorld().dropItemNaturally(event.getBlockState().getLocation(), is);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Monitor BlockPistonExtend events.
|
||||
*
|
||||
|
@ -14,7 +14,6 @@ import com.gmail.nossr50.events.fake.FakeEntityTameEvent;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.party.PartyManager;
|
||||
import com.gmail.nossr50.skills.archery.Archery;
|
||||
import com.gmail.nossr50.skills.fishing.Fishing;
|
||||
import com.gmail.nossr50.skills.mining.BlastMining;
|
||||
import com.gmail.nossr50.skills.mining.MiningManager;
|
||||
import com.gmail.nossr50.skills.taming.Taming;
|
||||
|
@ -2,7 +2,6 @@ package com.gmail.nossr50.listeners;
|
||||
|
||||
import com.gmail.nossr50.config.WorldBlacklist;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.blockmeta.conversion.BlockStoreConversionMain;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.BlockState;
|
||||
|
@ -113,6 +113,8 @@ public class mcMMO extends JavaPlugin {
|
||||
public final static String disarmedItemKey = "mcMMO: Disarmed Item";
|
||||
public final static String playerDataKey = "mcMMO: Player Data";
|
||||
public final static String greenThumbDataKey = "mcMMO: Green Thumb";
|
||||
public final static String doubleDropKey = "mcMMO: Double Drop";
|
||||
public final static String tripleDropKey = "mcMMO: Triple Drop";
|
||||
public final static String databaseCommandKey = "mcMMO: Processing Database Command";
|
||||
public final static String bredMetadataKey = "mcMMO: Bred Animal";
|
||||
|
||||
|
@ -27,7 +27,6 @@ import com.gmail.nossr50.util.skills.RankUtils;
|
||||
import com.gmail.nossr50.util.skills.SkillUtils;
|
||||
import com.gmail.nossr50.util.sounds.SoundManager;
|
||||
import com.gmail.nossr50.util.sounds.SoundType;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.gmail.nossr50.skills.herbalism;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.BlockUtils;
|
||||
import com.gmail.nossr50.util.skills.SkillUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@ -42,11 +43,11 @@ public class Herbalism {
|
||||
}
|
||||
}
|
||||
|
||||
private static int calculateChorusPlantDrops(Block target) {
|
||||
return calculateChorusPlantDropsRecursive(target, new HashSet<>());
|
||||
private static int calculateChorusPlantDrops(Block target, boolean triple, HerbalismManager herbalismManager) {
|
||||
return calculateChorusPlantDropsRecursive(target, new HashSet<>(), triple, herbalismManager);
|
||||
}
|
||||
|
||||
private static int calculateChorusPlantDropsRecursive(Block target, HashSet<Block> traversed) {
|
||||
private static int calculateChorusPlantDropsRecursive(Block target, HashSet<Block> traversed, boolean triple, HerbalismManager herbalismManager) {
|
||||
if (target.getType() != Material.CHORUS_PLANT)
|
||||
return 0;
|
||||
|
||||
@ -62,10 +63,15 @@ public class Herbalism {
|
||||
if (mcMMO.getPlaceStore().isTrue(target))
|
||||
mcMMO.getPlaceStore().setFalse(target);
|
||||
else
|
||||
{
|
||||
dropAmount++;
|
||||
|
||||
if(herbalismManager.checkDoubleDrop(target.getState()))
|
||||
BlockUtils.markBlocksForBonusDrops(target.getState(), triple);
|
||||
}
|
||||
|
||||
for (BlockFace blockFace : new BlockFace[] { BlockFace.UP, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST ,BlockFace.WEST})
|
||||
dropAmount += calculateChorusPlantDropsRecursive(target.getRelative(blockFace, 1), traversed);
|
||||
dropAmount += calculateChorusPlantDropsRecursive(target.getRelative(blockFace, 1), traversed, triple, herbalismManager);
|
||||
|
||||
return dropAmount;
|
||||
}
|
||||
@ -78,7 +84,7 @@ public class Herbalism {
|
||||
* The {@link BlockState} of the bottom block of the plant
|
||||
* @return the number of bonus drops to award from the blocks in this plant
|
||||
*/
|
||||
protected static int calculateMultiBlockPlantDrops(BlockState blockState) {
|
||||
protected static int countAndMarkDoubleDropsMultiBlockPlant(BlockState blockState, boolean triple, HerbalismManager herbalismManager) {
|
||||
Block block = blockState.getBlock();
|
||||
Material blockType = blockState.getType();
|
||||
int dropAmount = mcMMO.getPlaceStore().isTrue(block) ? 0 : 1;
|
||||
@ -87,11 +93,11 @@ public class Herbalism {
|
||||
dropAmount = 1;
|
||||
|
||||
if (block.getRelative(BlockFace.DOWN, 1).getType() == Material.END_STONE) {
|
||||
dropAmount = calculateChorusPlantDrops(block);
|
||||
dropAmount = calculateChorusPlantDrops(block, triple, herbalismManager);
|
||||
}
|
||||
} else {
|
||||
// Handle the two blocks above it - cacti & sugar cane can only grow 3 high naturally
|
||||
for (int y = 1; y < 256; y++) {
|
||||
for (int y = 1; y < 255; y++) {
|
||||
Block relativeBlock = block.getRelative(BlockFace.UP, y);
|
||||
|
||||
if (relativeBlock.getType() != blockType) {
|
||||
@ -102,6 +108,9 @@ public class Herbalism {
|
||||
mcMMO.getPlaceStore().setFalse(relativeBlock);
|
||||
} else {
|
||||
dropAmount++;
|
||||
|
||||
if(herbalismManager.checkDoubleDrop(relativeBlock.getState()))
|
||||
BlockUtils.markBlocksForBonusDrops(relativeBlock.getState(), triple);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -117,12 +126,11 @@ public class Herbalism {
|
||||
* The {@link BlockState} of the bottom block of the plant
|
||||
* @return the number of bonus drops to award from the blocks in this plant
|
||||
*/
|
||||
protected static int calculateKelpPlantDrops(BlockState blockState) {
|
||||
protected static int countAndMarkDoubleDropsKelp(BlockState blockState, boolean triple, HerbalismManager herbalismManager) {
|
||||
Block block = blockState.getBlock();
|
||||
|
||||
int dropAmount = mcMMO.getPlaceStore().isTrue(block) ? 0 : 1;
|
||||
|
||||
int kelpMaxHeight = 256;
|
||||
int kelpMaxHeight = 255;
|
||||
int amount = 1;
|
||||
|
||||
// Handle the two blocks above it - cacti & sugar cane can only grow 3 high naturally
|
||||
for (int y = 1; y < kelpMaxHeight; y++) {
|
||||
@ -131,10 +139,14 @@ public class Herbalism {
|
||||
if(!isKelp(relativeUpBlock))
|
||||
break;
|
||||
|
||||
dropAmount = addKelpDrops(dropAmount, relativeUpBlock);
|
||||
amount += 1;
|
||||
|
||||
if(herbalismManager.checkDoubleDrop(relativeUpBlock.getState()))
|
||||
BlockUtils.markBlocksForBonusDrops(relativeUpBlock.getState(), triple);
|
||||
|
||||
}
|
||||
|
||||
return dropAmount;
|
||||
return amount;
|
||||
}
|
||||
|
||||
private static int addKelpDrops(int dropAmount, Block relativeBlock) {
|
||||
|
@ -31,7 +31,6 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class HerbalismManager extends SkillManager {
|
||||
@ -138,8 +137,7 @@ public class HerbalismManager extends SkillManager {
|
||||
return;
|
||||
}
|
||||
|
||||
Collection<ItemStack> drops = null;
|
||||
int amount = 1;
|
||||
int amount;
|
||||
int xp;
|
||||
boolean greenTerra = mcMMOPlayer.getAbilityMode(skill.getAbility());
|
||||
|
||||
@ -148,25 +146,26 @@ public class HerbalismManager extends SkillManager {
|
||||
xp = customBlock.getXpGain();
|
||||
|
||||
if (Permissions.isSubSkillEnabled(player, SubSkillType.HERBALISM_DOUBLE_DROPS) && customBlock.isDoubleDropEnabled()) {
|
||||
drops = blockState.getBlock().getDrops();
|
||||
if(checkDoubleDrop(blockState))
|
||||
BlockUtils.markBlocksForBonusDrops(blockState, greenTerra);
|
||||
}
|
||||
}
|
||||
else {
|
||||
xp = ExperienceConfig.getInstance().getXp(skill, blockState.getBlockData());
|
||||
|
||||
if (Config.getInstance().getDoubleDropsEnabled(skill, material) && Permissions.isSubSkillEnabled(player, SubSkillType.HERBALISM_DOUBLE_DROPS)) {
|
||||
drops = blockState.getBlock().getDrops();
|
||||
}
|
||||
|
||||
if (!oneBlockPlant) {
|
||||
//Kelp is actually two blocks mixed together
|
||||
if(material == Material.KELP_PLANT || material == Material.KELP) {
|
||||
amount = Herbalism.calculateKelpPlantDrops(blockState);
|
||||
amount = Herbalism.countAndMarkDoubleDropsKelp(blockState, greenTerra,this);
|
||||
} else {
|
||||
amount = Herbalism.calculateMultiBlockPlantDrops(blockState);
|
||||
amount = Herbalism.countAndMarkDoubleDropsMultiBlockPlant(blockState, greenTerra, this);
|
||||
}
|
||||
|
||||
xp *= amount;
|
||||
} else {
|
||||
/* MARK SINGLE BLOCK CROP FOR DOUBLE DROP */
|
||||
if(checkDoubleDrop(blockState))
|
||||
BlockUtils.markBlocksForBonusDrops(blockState, greenTerra);
|
||||
}
|
||||
|
||||
if (Permissions.greenThumbPlant(player, material)) {
|
||||
@ -175,18 +174,16 @@ public class HerbalismManager extends SkillManager {
|
||||
}
|
||||
|
||||
applyXpGain(xp, XPGainReason.PVE);
|
||||
|
||||
if (drops == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = greenTerra ? 2 : 1; i != 0; i--) {
|
||||
if (RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.HERBALISM_DOUBLE_DROPS, player)) {
|
||||
for (ItemStack item : drops) {
|
||||
Misc.dropItems(Misc.getBlockCenter(blockState), item, amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -320,11 +317,7 @@ public class HerbalismManager extends SkillManager {
|
||||
|
||||
ItemStack seedStack = new ItemStack(seed);
|
||||
|
||||
if (!playerInventory.containsAtLeast(seedStack, 1)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!greenTerra && !RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.HERBALISM_GREEN_THUMB, player)) {
|
||||
if (!greenTerra && !RandomChanceUtil.checkRandomChanceExecutionSuccess(player, SubSkillType.HERBALISM_GREEN_THUMB, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -332,8 +325,16 @@ public class HerbalismManager extends SkillManager {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!ItemUtils.isHoe(getPlayer().getInventory().getItemInMainHand()))
|
||||
{
|
||||
if (!playerInventory.containsAtLeast(seedStack, 1)) {
|
||||
return;
|
||||
}
|
||||
|
||||
playerInventory.removeItem(seedStack);
|
||||
player.updateInventory(); // Needed until replacement available
|
||||
}
|
||||
|
||||
new HerbalismBlockUpdaterTask(blockState).runTaskLater(mcMMO.p, 0);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.gmail.nossr50.skills.smelting;
|
||||
|
||||
import com.gmail.nossr50.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.config.experience.ExperienceConfig;
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
|
@ -1,28 +1,16 @@
|
||||
package com.gmail.nossr50.skills.smelting;
|
||||
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.experience.XPGainReason;
|
||||
import com.gmail.nossr50.datatypes.experience.XPGainSource;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.skills.SkillManager;
|
||||
import com.gmail.nossr50.skills.mining.Mining;
|
||||
import com.gmail.nossr50.util.BlockUtils;
|
||||
import com.gmail.nossr50.util.EventUtils;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.random.RandomChanceUtil;
|
||||
import com.gmail.nossr50.util.skills.ParticleEffectUtils;
|
||||
import com.gmail.nossr50.util.skills.RankUtils;
|
||||
import com.gmail.nossr50.util.skills.SkillActivationType;
|
||||
import com.gmail.nossr50.util.skills.SkillUtils;
|
||||
import com.gmail.nossr50.util.sounds.SoundManager;
|
||||
import com.gmail.nossr50.util.sounds.SoundType;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.FurnaceBurnEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
@ -1,14 +1,19 @@
|
||||
package com.gmail.nossr50.util;
|
||||
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.config.experience.ExperienceConfig;
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.skills.repair.Repair;
|
||||
import com.gmail.nossr50.skills.salvage.Salvage;
|
||||
import com.gmail.nossr50.util.random.RandomChanceSkill;
|
||||
import com.gmail.nossr50.util.random.RandomChanceUtil;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.data.Ageable;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
@ -16,6 +21,34 @@ public final class BlockUtils {
|
||||
|
||||
private BlockUtils() {}
|
||||
|
||||
/**
|
||||
* Mark a block for giving bonus drops, double drops are used if triple is false
|
||||
* @param blockState target blockstate
|
||||
* @param triple marks the block to give triple drops
|
||||
*/
|
||||
public static void markBlocksForBonusDrops(BlockState blockState, boolean triple)
|
||||
{
|
||||
if(triple)
|
||||
blockState.setMetadata(mcMMO.tripleDropKey, mcMMO.metadataValue);
|
||||
else
|
||||
blockState.setMetadata(mcMMO.doubleDropKey, mcMMO.metadataValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a player successfully passed the double drop check
|
||||
* @param blockState the blockstate
|
||||
* @return true if the player succeeded in the check
|
||||
*/
|
||||
public static boolean checkDoubleDrops(Player player, BlockState blockState, PrimarySkillType skillType, SubSkillType subSkillType)
|
||||
{
|
||||
if(Config.getInstance().getDoubleDropsEnabled(skillType, blockState.getType()) && Permissions.isSubSkillEnabled(player, subSkillType))
|
||||
{
|
||||
return RandomChanceUtil.checkRandomChanceExecutionSuccess(new RandomChanceSkill(player, subSkillType, true));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if a given block awards XP.
|
||||
*
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.gmail.nossr50.worldguard;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user