mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-24 06:06:45 +01:00
made new method more generic.
Removed no longer needed dropString variable Signed-off-by: Momshroom <Momshroom@gmail.com>
This commit is contained in:
parent
b55ac12130
commit
912b960e6b
@ -35,6 +35,7 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
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?
|
||||
public class WoodcuttingManager extends SkillManager {
|
||||
@ -330,8 +331,9 @@ public class WoodcuttingManager extends SkillManager {
|
||||
}
|
||||
// if KnockOnWood is unlocked, then drop any saplings from the remaining blocks
|
||||
else if (RankUtils.hasUnlockedSubskill(player, SubSkillType.WOODCUTTING_KNOCK_ON_WOOD)) {
|
||||
Misc.spawnItemIfSapling(player, Misc.getBlockCenter(blockState),
|
||||
block.getDrops(itemStack),ItemSpawnReason.TREE_FELLER_DISPLACED_BLOCK);
|
||||
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
|
||||
|
@ -20,6 +20,7 @@ import java.util.Collection;
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public final class Misc {
|
||||
private static final @NotNull Random random = new Random();
|
||||
@ -132,11 +133,9 @@ 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 spawnItemIfSapling(@NotNull Player player, @NotNull Location spawnLocation, @NotNull Collection <ItemStack> drops, @NotNull ItemSpawnReason itemSpawnReason) {
|
||||
String dropString;
|
||||
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) {
|
||||
dropString = drop.getType().getKey().getKey();
|
||||
if (dropString.contains("sapling") || dropString.contains("propagule")) {
|
||||
if (predicate.test(drop.getType().getKey().getKey())) {
|
||||
spawnItem(player, spawnLocation, drop, itemSpawnReason);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user