mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-24 22:26:46 +01:00
Fix sapling drops to ignore reduction and obey Knock on Wood (#5012)
* Fixed NPE when party creation doesn't use password. Solves bug reported here: https://discord.com/channels/526933440214597677/526938425161416727/1213131451235827753 Signed-off-by: Momshroom <Momshroom@gmail.com> * Actually don't reduce sapling drop if KnockOnWood unlocked. (Prior fix didn't) Signed-off-by: Momshroom <Momshroom@gmail.com> * removed unnecessary getPlayer() calls. clarified comment clarified location variable name Signed-off-by: Momshroom <Momshroom@gmail.com> * made new method more generic. Removed no longer needed dropString variable Signed-off-by: Momshroom <Momshroom@gmail.com> --------- Signed-off-by: Momshroom <Momshroom@gmail.com>
This commit is contained in:
parent
d0ab2bdb2f
commit
2f1278c784
@ -35,6 +35,7 @@ import java.util.HashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
//TODO: Seems to not be using the item drop event for bonus drops, may want to change that.. or may not be able to be changed?
|
//TODO: Seems to not be using the item drop event for bonus drops, may want to change that.. or may not be able to be changed?
|
||||||
public class WoodcuttingManager extends SkillManager {
|
public class WoodcuttingManager extends SkillManager {
|
||||||
@ -316,19 +317,24 @@ public class WoodcuttingManager extends SkillManager {
|
|||||||
xp += processTreeFellerXPGains(blockState, processedLogCount);
|
xp += processTreeFellerXPGains(blockState, processedLogCount);
|
||||||
|
|
||||||
//Drop displaced block
|
//Drop displaced block
|
||||||
Misc.spawnItemsFromCollection(getPlayer(), Misc.getBlockCenter(blockState), block.getDrops(itemStack), ItemSpawnReason.TREE_FELLER_DISPLACED_BLOCK);
|
Misc.spawnItemsFromCollection(player, Misc.getBlockCenter(blockState), block.getDrops(itemStack), ItemSpawnReason.TREE_FELLER_DISPLACED_BLOCK);
|
||||||
|
|
||||||
//Bonus Drops / Harvest lumber checks
|
//Bonus Drops / Harvest lumber checks
|
||||||
processBonusDropCheck(blockState);
|
processBonusDropCheck(blockState);
|
||||||
} else if (BlockUtils.isNonWoodPartOfTree(blockState)) {
|
} else if (BlockUtils.isNonWoodPartOfTree(blockState)) {
|
||||||
// 75% of the time do not drop leaf blocks
|
// 75% of the time do not drop leaf blocks
|
||||||
if (blockState.getType().getKey().getKey().toLowerCase().contains("sapling")
|
if (ThreadLocalRandom.current().nextInt(100) > 75) {
|
||||||
|| ThreadLocalRandom.current().nextInt(100) > 75) {
|
Misc.spawnItemsFromCollection(player,
|
||||||
Misc.spawnItemsFromCollection(getPlayer(),
|
|
||||||
Misc.getBlockCenter(blockState),
|
Misc.getBlockCenter(blockState),
|
||||||
block.getDrops(itemStack),
|
block.getDrops(itemStack),
|
||||||
ItemSpawnReason.TREE_FELLER_DISPLACED_BLOCK);
|
ItemSpawnReason.TREE_FELLER_DISPLACED_BLOCK);
|
||||||
}
|
}
|
||||||
|
// if KnockOnWood is unlocked, then drop any saplings from the remaining blocks
|
||||||
|
else if (RankUtils.hasUnlockedSubskill(player, SubSkillType.WOODCUTTING_KNOCK_ON_WOOD)) {
|
||||||
|
Predicate<String> isSapling = p -> p.contains("sapling") || p.contains("propagule");
|
||||||
|
Misc.conditionallySpawn(isSapling, player, Misc.getBlockCenter(blockState),
|
||||||
|
block.getDrops(itemStack), ItemSpawnReason.TREE_FELLER_DISPLACED_BLOCK);
|
||||||
|
}
|
||||||
|
|
||||||
//Drop displaced non-woodcutting XP blocks
|
//Drop displaced non-woodcutting XP blocks
|
||||||
if (RankUtils.hasUnlockedSubskill(player, SubSkillType.WOODCUTTING_KNOCK_ON_WOOD)) {
|
if (RankUtils.hasUnlockedSubskill(player, SubSkillType.WOODCUTTING_KNOCK_ON_WOOD)) {
|
||||||
|
@ -20,6 +20,7 @@ import java.util.Collection;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
public final class Misc {
|
public final class Misc {
|
||||||
private static final @NotNull Random random = new Random();
|
private static final @NotNull Random random = new Random();
|
||||||
@ -128,6 +129,18 @@ public final class Misc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Drops the item from the item stack only if it is a sapling (or equivalent)
|
||||||
|
* Needed for TreeFeller
|
||||||
|
*/
|
||||||
|
public static void conditionallySpawn(@NotNull Predicate<String> predicate, @NotNull Player player, @NotNull Location spawnLocation, @NotNull Collection <ItemStack> drops, @NotNull ItemSpawnReason itemSpawnReason) {
|
||||||
|
for (ItemStack drop : drops) {
|
||||||
|
if (predicate.test(drop.getType().getKey().getKey())) {
|
||||||
|
spawnItem(player, spawnLocation, drop, itemSpawnReason);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Drop items at a given location.
|
* Drop items at a given location.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user