made new method more generic.

Removed no longer needed dropString variable

Signed-off-by: Momshroom <Momshroom@gmail.com>
This commit is contained in:
Momshroom 2024-05-23 19:49:32 -05:00
parent b55ac12130
commit 912b960e6b
2 changed files with 7 additions and 6 deletions

View File

@ -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 {
@ -330,8 +331,9 @@ public class WoodcuttingManager extends SkillManager {
} }
// if KnockOnWood is unlocked, then drop any saplings from the remaining blocks // if KnockOnWood is unlocked, then drop any saplings from the remaining blocks
else if (RankUtils.hasUnlockedSubskill(player, SubSkillType.WOODCUTTING_KNOCK_ON_WOOD)) { else if (RankUtils.hasUnlockedSubskill(player, SubSkillType.WOODCUTTING_KNOCK_ON_WOOD)) {
Misc.spawnItemIfSapling(player, Misc.getBlockCenter(blockState), Predicate<String> isSapling = p -> p.contains("sapling") || p.contains("propagule");
block.getDrops(itemStack),ItemSpawnReason.TREE_FELLER_DISPLACED_BLOCK); 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

View File

@ -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();
@ -132,11 +133,9 @@ public final class Misc {
* Drops the item from the item stack only if it is a sapling (or equivalent) * Drops the item from the item stack only if it is a sapling (or equivalent)
* Needed for TreeFeller * Needed for TreeFeller
*/ */
public static void spawnItemIfSapling(@NotNull Player player, @NotNull Location spawnLocation, @NotNull Collection <ItemStack> drops, @NotNull ItemSpawnReason itemSpawnReason) { public static void conditionallySpawn(@NotNull Predicate<String> predicate, @NotNull Player player, @NotNull Location spawnLocation, @NotNull Collection <ItemStack> drops, @NotNull ItemSpawnReason itemSpawnReason) {
String dropString;
for (ItemStack drop : drops) { for (ItemStack drop : drops) {
dropString = drop.getType().getKey().getKey(); if (predicate.test(drop.getType().getKey().getKey())) {
if (dropString.contains("sapling") || dropString.contains("propagule")) {
spawnItem(player, spawnLocation, drop, itemSpawnReason); spawnItem(player, spawnLocation, drop, itemSpawnReason);
} }
} }