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:
Momshroom
2024-05-23 20:02:29 -05:00
committed by GitHub
parent d0ab2bdb2f
commit 2f1278c784
2 changed files with 23 additions and 4 deletions

View File

@@ -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();
@@ -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.
*