Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sapling drops to ignore reduction and obey Knock on Wood #5012

Merged
merged 6 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
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 {
Expand Down Expand Up @@ -316,19 +317,24 @@ private void dropTreeFellerLootFromBlocks(@NotNull Set<BlockState> treeFellerBlo
xp += processTreeFellerXPGains(blockState, processedLogCount);

//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
processBonusDropCheck(blockState);
} else if (BlockUtils.isNonWoodPartOfTree(blockState)) {
// 75% of the time do not drop leaf blocks
if (blockState.getType().getKey().getKey().toLowerCase().contains("sapling")
|| ThreadLocalRandom.current().nextInt(100) > 75) {
Misc.spawnItemsFromCollection(getPlayer(),
if (ThreadLocalRandom.current().nextInt(100) > 75) {
Misc.spawnItemsFromCollection(player,
Misc.getBlockCenter(blockState),
block.getDrops(itemStack),
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
if (RankUtils.hasUnlockedSubskill(player, SubSkillType.WOODCUTTING_KNOCK_ON_WOOD)) {
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/gmail/nossr50/util/Misc.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
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();
Expand Down Expand Up @@ -128,6 +129,18 @@ public static void spawnItemsFromCollection(@Nullable Player player, @NotNull Lo
}
}

/**
* 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.
*
Expand Down
Loading