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.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
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?
|
//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 {
|
||||||
|
public static final String SAPLING = "sapling";
|
||||||
|
public static final String PROPAGULE = "propagule";
|
||||||
private boolean treeFellerReachedThreshold = false;
|
private boolean treeFellerReachedThreshold = false;
|
||||||
private static int treeFellerThreshold; //TODO: Shared setting, will be removed in 2.2
|
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) {
|
public boolean canUseLeafBlower(ItemStack heldItem) {
|
||||||
return Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.WOODCUTTING_LEAF_BLOWER)
|
return Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.WOODCUTTING_LEAF_BLOWER)
|
||||||
&& RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.WOODCUTTING_LEAF_BLOWER)
|
&& hasUnlockedSubskill(getPlayer(), SubSkillType.WOODCUTTING_LEAF_BLOWER)
|
||||||
&& ItemUtils.isAxe(heldItem);
|
&& ItemUtils.isAxe(heldItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,7 +322,7 @@ public class WoodcuttingManager extends SkillManager {
|
|||||||
xp += processTreeFellerXPGains(blockState, processedLogCount);
|
xp += processTreeFellerXPGains(blockState, processedLogCount);
|
||||||
|
|
||||||
//Drop displaced block
|
//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
|
//Bonus Drops / Harvest lumber checks
|
||||||
processBonusDropCheck(blockState);
|
processBonusDropCheck(blockState);
|
||||||
@ -325,19 +330,22 @@ public class WoodcuttingManager extends SkillManager {
|
|||||||
// 75% of the time do not drop leaf blocks
|
// 75% of the time do not drop leaf blocks
|
||||||
if (ThreadLocalRandom.current().nextInt(100) > 75) {
|
if (ThreadLocalRandom.current().nextInt(100) > 75) {
|
||||||
Misc.spawnItemsFromCollection(player,
|
Misc.spawnItemsFromCollection(player,
|
||||||
Misc.getBlockCenter(blockState),
|
getBlockCenter(blockState),
|
||||||
block.getDrops(itemStack),
|
block.getDrops(itemStack),
|
||||||
ItemSpawnReason.TREE_FELLER_DISPLACED_BLOCK);
|
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
|
// if KnockOnWood is unlocked, then drop any saplings from the remaining blocks
|
||||||
else if (RankUtils.hasUnlockedSubskill(player, SubSkillType.WOODCUTTING_KNOCK_ON_WOOD)) {
|
spawnItem(block.getDrops(itemStack),
|
||||||
Predicate<String> isSapling = p -> p.contains("sapling") || p.contains("propagule");
|
ItemSpawnReason.TREE_FELLER_DISPLACED_BLOCK,
|
||||||
Misc.conditionallySpawn(isSapling, player, Misc.getBlockCenter(blockState),
|
getBlockCenter(blockState),
|
||||||
block.getDrops(itemStack), ItemSpawnReason.TREE_FELLER_DISPLACED_BLOCK);
|
// only spawn saplings
|
||||||
|
p -> p.toLowerCase().contains(SAPLING) || p.toLowerCase().contains(PROPAGULE),
|
||||||
|
player
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Drop displaced non-woodcutting XP blocks
|
//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 (RankUtils.hasReachedRank(2, player, SubSkillType.WOODCUTTING_KNOCK_ON_WOOD)) {
|
||||||
if (mcMMO.p.getAdvancedConfig().isKnockOnWoodXPOrbEnabled()) {
|
if (mcMMO.p.getAdvancedConfig().isKnockOnWoodXPOrbEnabled()) {
|
||||||
if (ProbabilityUtil.isStaticSkillRNGSuccessful(PrimarySkillType.WOODCUTTING, mmoPlayer, 10)) {
|
if (ProbabilityUtil.isStaticSkillRNGSuccessful(PrimarySkillType.WOODCUTTING, mmoPlayer, 10)) {
|
||||||
@ -416,7 +424,7 @@ public class WoodcuttingManager extends SkillManager {
|
|||||||
protected void spawnHarvestLumberBonusDrops(@NotNull BlockState blockState) {
|
protected void spawnHarvestLumberBonusDrops(@NotNull BlockState blockState) {
|
||||||
Misc.spawnItemsFromCollection(
|
Misc.spawnItemsFromCollection(
|
||||||
getPlayer(),
|
getPlayer(),
|
||||||
Misc.getBlockCenter(blockState),
|
getBlockCenter(blockState),
|
||||||
blockState.getBlock().getDrops(getPlayer().getInventory().getItemInMainHand()),
|
blockState.getBlock().getDrops(getPlayer().getInventory().getItemInMainHand()),
|
||||||
ItemSpawnReason.BONUS_DROPS);
|
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)
|
* Spawn items form a collection if conditions are met.
|
||||||
* Needed for TreeFeller
|
* 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) {
|
public static void spawnItem(@NotNull Collection <ItemStack> potentialItemDrops,
|
||||||
for (ItemStack drop : drops) {
|
@NotNull ItemSpawnReason itemSpawnReason,
|
||||||
if (predicate.test(drop.getType().getKey().getKey())) {
|
@NotNull Location spawnLocation,
|
||||||
spawnItem(player, spawnLocation, drop, itemSpawnReason);
|
@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