mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 05:06:45 +01:00
Fix bonus drops on multi-block crops
This commit is contained in:
parent
e70e5b04b5
commit
95652efbaa
@ -3,6 +3,7 @@ Version 2.1.60
|
||||
Fixed a bug where tamed mobs could kill themselves if their owner shot them once
|
||||
Corrected a typo when naming entities summoned by COTW (Locale string - Taming.Summon.Name.Format)
|
||||
Fixed a bug where tamed mobs could have hearts instead of their name in their own death messages
|
||||
Fixed a bug where multi-block crops would fail to double/triple drop (Sugar Cane, Cactus, etc)
|
||||
|
||||
Version 2.1.59
|
||||
Raised the overfishing limit from 3 to 10
|
||||
|
@ -0,0 +1,14 @@
|
||||
package com.gmail.nossr50.datatypes.meta;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
|
||||
/**
|
||||
* Stores how many bonus drops a block should give
|
||||
*/
|
||||
public class BonusDropMeta extends FixedMetadataValue {
|
||||
|
||||
public BonusDropMeta(int value, mcMMO plugin) {
|
||||
super(plugin, value);
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.config.HiddenConfig;
|
||||
import com.gmail.nossr50.config.WorldBlacklist;
|
||||
import com.gmail.nossr50.config.experience.ExperienceConfig;
|
||||
import com.gmail.nossr50.datatypes.meta.BonusDropMeta;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
|
||||
@ -65,17 +66,15 @@ public class BlockListener implements Listener {
|
||||
&& !Config.getInstance().getDoubleDropsEnabled(PrimarySkillType.WOODCUTTING, is.getType()))
|
||||
continue;
|
||||
|
||||
//TODO: Should just store the amount of drops in the metadata itself and use a loop
|
||||
if(event.getBlock().getMetadata(mcMMO.doubleDrops).size() > 0)
|
||||
{
|
||||
event.getBlock().getWorld().dropItemNaturally(event.getBlockState().getLocation(), is);
|
||||
event.getBlock().removeMetadata(mcMMO.doubleDrops, plugin);
|
||||
}
|
||||
else if(event.getBlock().getMetadata(mcMMO.tripleDrops).size() > 0)
|
||||
{
|
||||
event.getBlock().getWorld().dropItemNaturally(event.getBlockState().getLocation(), is);
|
||||
event.getBlock().getWorld().dropItemNaturally(event.getBlockState().getLocation(), is);
|
||||
event.getBlock().removeMetadata(mcMMO.tripleDrops, plugin);
|
||||
if (event.getBlock().getMetadata(mcMMO.BONUS_DROPS_METAKEY).size() > 0) {
|
||||
BonusDropMeta bonusDropMeta = (BonusDropMeta) event.getBlock().getMetadata(mcMMO.BONUS_DROPS_METAKEY).get(0);
|
||||
int bonusCount = bonusDropMeta.asInt();
|
||||
|
||||
for (int i = 0; i < bonusCount; i++) {
|
||||
event.getBlock().getWorld().dropItemNaturally(event.getBlockState().getLocation(), is);
|
||||
}
|
||||
|
||||
event.getBlock().removeMetadata(mcMMO.BONUS_DROPS_METAKEY, plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -120,8 +120,7 @@ public class mcMMO extends JavaPlugin {
|
||||
public final static String infiniteArrowKey = "mcMMO: Infinite Arrow";
|
||||
public final static String bowForceKey = "mcMMO: Bow Force";
|
||||
public final static String arrowDistanceKey = "mcMMO: Arrow Distance";
|
||||
public final static String doubleDrops = "mcMMO: Double Drops";
|
||||
public final static String tripleDrops = "mcMMO: Triple Drops";
|
||||
public final static String BONUS_DROPS_METAKEY = "mcMMO: Double Drops";
|
||||
//public final static String customDamageKey = "mcMMO: Custom Damage";
|
||||
public final static String disarmedItemKey = "mcMMO: Disarmed Item";
|
||||
public final static String playerDataKey = "mcMMO: Player Data";
|
||||
|
@ -87,7 +87,9 @@ public class Herbalism {
|
||||
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;
|
||||
int dropAmount = 0;
|
||||
int bonusDropAmount = 0;
|
||||
int bonusAdd = triple ? 2 : 1;
|
||||
|
||||
if (blockType == Material.CHORUS_PLANT) {
|
||||
dropAmount = 1;
|
||||
@ -96,6 +98,17 @@ public class Herbalism {
|
||||
dropAmount = calculateChorusPlantDrops(block, triple, herbalismManager);
|
||||
}
|
||||
} else {
|
||||
//Check the block itself first
|
||||
if(!mcMMO.getPlaceStore().isTrue(block))
|
||||
{
|
||||
dropAmount++;
|
||||
|
||||
if(herbalismManager.checkDoubleDrop(blockState))
|
||||
bonusDropAmount+=bonusAdd;
|
||||
} else {
|
||||
mcMMO.getPlaceStore().setFalse(blockState);
|
||||
}
|
||||
|
||||
// Handle the two blocks above it - cacti & sugar cane can only grow 3 high naturally
|
||||
for (int y = 1; y < 255; y++) {
|
||||
Block relativeBlock = block.getRelative(BlockFace.UP, y);
|
||||
@ -110,11 +123,14 @@ public class Herbalism {
|
||||
dropAmount++;
|
||||
|
||||
if(herbalismManager.checkDoubleDrop(relativeBlock.getState()))
|
||||
BlockUtils.markDropsAsBonus(relativeBlock.getState(), triple);
|
||||
bonusDropAmount+=bonusAdd;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Mark the original block for bonus drops
|
||||
BlockUtils.markDropsAsBonus(blockState, bonusDropAmount);
|
||||
|
||||
return dropAmount;
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ package com.gmail.nossr50.util;
|
||||
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.config.experience.ExperienceConfig;
|
||||
import com.gmail.nossr50.datatypes.meta.BonusDropMeta;
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
@ -30,9 +31,18 @@ public final class BlockUtils {
|
||||
*/
|
||||
public static void markDropsAsBonus(BlockState blockState, boolean triple) {
|
||||
if (triple)
|
||||
blockState.setMetadata(mcMMO.tripleDrops, mcMMO.metadataValue);
|
||||
blockState.setMetadata(mcMMO.BONUS_DROPS_METAKEY, new BonusDropMeta(2, mcMMO.p));
|
||||
else
|
||||
blockState.setMetadata(mcMMO.doubleDrops, mcMMO.metadataValue);
|
||||
blockState.setMetadata(mcMMO.BONUS_DROPS_METAKEY, new BonusDropMeta(1, mcMMO.p));
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks a block to drop extra copies of items
|
||||
* @param blockState target blockstate
|
||||
* @param amount amount of extra items to drop
|
||||
*/
|
||||
public static void markDropsAsBonus(BlockState blockState, int amount) {
|
||||
blockState.setMetadata(mcMMO.BONUS_DROPS_METAKEY, new BonusDropMeta(amount, mcMMO.p));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user