mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 05:06:45 +01:00
minor refactoring
This commit is contained in:
parent
2f1278c784
commit
590b00aeca
@ -35,10 +35,15 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import static com.gmail.nossr50.util.Misc.getBlockCenter;
|
||||
import static com.gmail.nossr50.util.Misc.spawnItem;
|
||||
import static com.gmail.nossr50.util.skills.RankUtils.hasUnlockedSubskill;
|
||||
|
||||
//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 static final String SAPLING = "sapling";
|
||||
public static final String PROPAGULE = "propagule";
|
||||
private boolean treeFellerReachedThreshold = false;
|
||||
private static int treeFellerThreshold; //TODO: Shared setting, will be removed in 2.2
|
||||
|
||||
@ -61,7 +66,7 @@ public class WoodcuttingManager extends SkillManager {
|
||||
|
||||
public boolean canUseLeafBlower(ItemStack heldItem) {
|
||||
return Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.WOODCUTTING_LEAF_BLOWER)
|
||||
&& RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.WOODCUTTING_LEAF_BLOWER)
|
||||
&& hasUnlockedSubskill(getPlayer(), SubSkillType.WOODCUTTING_LEAF_BLOWER)
|
||||
&& ItemUtils.isAxe(heldItem);
|
||||
}
|
||||
|
||||
@ -317,7 +322,7 @@ public class WoodcuttingManager extends SkillManager {
|
||||
xp += processTreeFellerXPGains(blockState, processedLogCount);
|
||||
|
||||
//Drop displaced block
|
||||
Misc.spawnItemsFromCollection(player, Misc.getBlockCenter(blockState), block.getDrops(itemStack), ItemSpawnReason.TREE_FELLER_DISPLACED_BLOCK);
|
||||
Misc.spawnItemsFromCollection(player, getBlockCenter(blockState), block.getDrops(itemStack), ItemSpawnReason.TREE_FELLER_DISPLACED_BLOCK);
|
||||
|
||||
//Bonus Drops / Harvest lumber checks
|
||||
processBonusDropCheck(blockState);
|
||||
@ -325,19 +330,22 @@ public class WoodcuttingManager extends SkillManager {
|
||||
// 75% of the time do not drop leaf blocks
|
||||
if (ThreadLocalRandom.current().nextInt(100) > 75) {
|
||||
Misc.spawnItemsFromCollection(player,
|
||||
Misc.getBlockCenter(blockState),
|
||||
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);
|
||||
} else if (hasUnlockedSubskill(player, SubSkillType.WOODCUTTING_KNOCK_ON_WOOD)) {
|
||||
// if KnockOnWood is unlocked, then drop any saplings from the remaining blocks
|
||||
spawnItem(block.getDrops(itemStack),
|
||||
ItemSpawnReason.TREE_FELLER_DISPLACED_BLOCK,
|
||||
getBlockCenter(blockState),
|
||||
// only spawn saplings
|
||||
p -> p.toLowerCase().contains(SAPLING) || p.toLowerCase().contains(PROPAGULE),
|
||||
player
|
||||
);
|
||||
}
|
||||
|
||||
//Drop displaced non-woodcutting XP blocks
|
||||
if (RankUtils.hasUnlockedSubskill(player, SubSkillType.WOODCUTTING_KNOCK_ON_WOOD)) {
|
||||
if (hasUnlockedSubskill(player, SubSkillType.WOODCUTTING_KNOCK_ON_WOOD)) {
|
||||
if (RankUtils.hasReachedRank(2, player, SubSkillType.WOODCUTTING_KNOCK_ON_WOOD)) {
|
||||
if (mcMMO.p.getAdvancedConfig().isKnockOnWoodXPOrbEnabled()) {
|
||||
if (ProbabilityUtil.isStaticSkillRNGSuccessful(PrimarySkillType.WOODCUTTING, mmoPlayer, 10)) {
|
||||
@ -416,7 +424,7 @@ public class WoodcuttingManager extends SkillManager {
|
||||
protected void spawnHarvestLumberBonusDrops(@NotNull BlockState blockState) {
|
||||
Misc.spawnItemsFromCollection(
|
||||
getPlayer(),
|
||||
Misc.getBlockCenter(blockState),
|
||||
getBlockCenter(blockState),
|
||||
blockState.getBlock().getDrops(getPlayer().getInventory().getItemInMainHand()),
|
||||
ItemSpawnReason.BONUS_DROPS);
|
||||
}
|
||||
|
@ -130,14 +130,42 @@ public final class Misc {
|
||||
}
|
||||
|
||||
/**
|
||||
* Drops the item from the item stack only if it is a sapling (or equivalent)
|
||||
* Needed for TreeFeller
|
||||
* Spawn items form a collection if conditions are met.
|
||||
* Each item is tested against the condition and spawned if it passes.
|
||||
*
|
||||
* @param potentialItemDrops The collection of items to iterate over, each one is tested and spawned if the
|
||||
* predicate is true
|
||||
* @param itemSpawnReason The reason for the item drop
|
||||
* @param spawnLocation The location to spawn the item at
|
||||
* @param predicate The predicate to test the item against
|
||||
* @param player The player to spawn the item for
|
||||
*/
|
||||
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);
|
||||
}
|
||||
public static void spawnItem(@NotNull Collection <ItemStack> potentialItemDrops,
|
||||
@NotNull ItemSpawnReason itemSpawnReason,
|
||||
@NotNull Location spawnLocation,
|
||||
@NotNull Predicate<String> predicate,
|
||||
@NotNull Player player) {
|
||||
for (ItemStack drop : potentialItemDrops) {
|
||||
spawnItem(drop, itemSpawnReason, spawnLocation, predicate, player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Spawn item if conditions are met.
|
||||
*
|
||||
* @param potentialItemSpawn The item to spawn if conditions are met
|
||||
* @param itemSpawnReason The reason for the item drop
|
||||
* @param spawnLocation The location to spawn the item at
|
||||
* @param predicate The predicate to test the item against
|
||||
* @param player The player to spawn the item for
|
||||
*/
|
||||
public static void spawnItem(@NotNull ItemStack potentialItemSpawn,
|
||||
@NotNull ItemSpawnReason itemSpawnReason,
|
||||
@NotNull Location spawnLocation,
|
||||
@NotNull Predicate<String> predicate,
|
||||
@NotNull Player player) {
|
||||
if (predicate.test(potentialItemSpawn.getType().getKey().getKey())) {
|
||||
spawnItem(player, spawnLocation, potentialItemSpawn, itemSpawnReason);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user