Fix illegal blastmining drops

Fixed so now spawners actually dont drop from blastmining, mining wont spawn illegal items anymore, before items like suspisous sand, infested_stone and similar illegal items were requiable with blastmining.

Removed double drops from non-mining related blocks
Added stone types back into the drops w/o double drops
Added Javadoc
This commit is contained in:
rasmus123d 2024-08-14 13:14:55 +02:00
parent 969b901615
commit 13dd8dad2a

View File

@ -31,55 +31,78 @@ import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Set;
import static com.gmail.nossr50.util.ItemUtils.isPickaxe; import static com.gmail.nossr50.util.ItemUtils.isPickaxe;
public class MiningManager extends SkillManager { public class MiningManager extends SkillManager {
public static final String BUDDING_AMETHYST = "budding_amethyst";
public static final Collection<Material> BLAST_MINING_BLACKLIST = Set.of(Material.SPAWNER);
public MiningManager(@NotNull McMMOPlayer mcMMOPlayer) { public MiningManager(@NotNull McMMOPlayer mcMMOPlayer) {
super(mcMMOPlayer, PrimarySkillType.MINING); super(mcMMOPlayer, PrimarySkillType.MINING);
} }
/**
* Determines if the player can use Demolitions Expertise.
*
* @return true if the player can use Demolitions Expertise, false otherwise
*/
public boolean canUseDemolitionsExpertise() { public boolean canUseDemolitionsExpertise() {
if (!RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.MINING_DEMOLITIONS_EXPERTISE)) return RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.MINING_DEMOLITIONS_EXPERTISE)
return false; && getSkillLevel() >= BlastMining.getDemolitionExpertUnlockLevel()
&& Permissions.demolitionsExpertise(getPlayer());
return getSkillLevel() >= BlastMining.getDemolitionExpertUnlockLevel() && Permissions.demolitionsExpertise(getPlayer());
} }
/**
* Determines if the player can detonate TNT remotely.
*
* @return true if the player can detonate TNT remotely, false otherwise
*/
public boolean canDetonate() { public boolean canDetonate() {
Player player = getPlayer(); Player player = getPlayer();
return canUseBlastMining() && player.isSneaking() return canUseBlastMining() && player.isSneaking()
&& (isPickaxe(getPlayer().getInventory().getItemInMainHand()) || player.getInventory().getItemInMainHand().getType() == mcMMO.p.getGeneralConfig().getDetonatorItem()) && (isPickaxe(player.getInventory().getItemInMainHand())
|| player.getInventory().getItemInMainHand().getType() == mcMMO.p.getGeneralConfig().getDetonatorItem())
&& Permissions.remoteDetonation(player); && Permissions.remoteDetonation(player);
} }
/**
* Determines if the player can use Blast Mining.
*
* @return true if the player can use Blast Mining, false otherwise
*/
public boolean canUseBlastMining() { public boolean canUseBlastMining() {
//Not checking permissions?
return RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.MINING_BLAST_MINING); return RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.MINING_BLAST_MINING);
} }
/**
* Determines if the player can use Bigger Bombs.
*
* @return true if the player can use Bigger Bombs, false otherwise
*/
public boolean canUseBiggerBombs() { public boolean canUseBiggerBombs() {
if (!RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.MINING_BIGGER_BOMBS)) return RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.MINING_BIGGER_BOMBS)
return false; && getSkillLevel() >= BlastMining.getBiggerBombsUnlockLevel()
&& Permissions.biggerBombs(getPlayer());
return getSkillLevel() >= BlastMining.getBiggerBombsUnlockLevel() && Permissions.biggerBombs(getPlayer());
} }
/**
* Determines if the player can trigger Double Drops.
*
* @return true if the player can trigger Double Drops, false otherwise
*/
public boolean canDoubleDrop() { public boolean canDoubleDrop() {
return RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.MINING_DOUBLE_DROPS) && Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.MINING_DOUBLE_DROPS); return RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.MINING_DOUBLE_DROPS)
&& Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.MINING_DOUBLE_DROPS);
} }
/**
* Determines if the player can trigger Mother Lode.
*
* @return true if the player can trigger Mother Lode, false otherwise
*/
public boolean canMotherLode() { public boolean canMotherLode() {
return Permissions.canUseSubSkill(getPlayer(), SubSkillType.MINING_MOTHER_LODE); return Permissions.canUseSubSkill(getPlayer(), SubSkillType.MINING_MOTHER_LODE);
} }
/** /**
* Process double drops & XP gain for Mining. * Process double drops & XP gain for Mining.
* *
@ -98,14 +121,15 @@ public class MiningManager extends SkillManager {
SkillUtils.handleDurabilityChange(getPlayer().getInventory().getItemInMainHand(), mcMMO.p.getGeneralConfig().getAbilityToolDamage()); SkillUtils.handleDurabilityChange(getPlayer().getInventory().getItemInMainHand(), mcMMO.p.getGeneralConfig().getAbilityToolDamage());
} }
if (!mcMMO.p.getGeneralConfig().getDoubleDropsEnabled(PrimarySkillType.MINING, blockState.getType()) || !canDoubleDrop()) if (!mcMMO.p.getGeneralConfig().getDoubleDropsEnabled(PrimarySkillType.MINING, blockState.getType()) || !canDoubleDrop()) {
return; return;
}
boolean silkTouch = player.getInventory().getItemInMainHand().containsEnchantment(Enchantment.SILK_TOUCH); boolean silkTouch = player.getInventory().getItemInMainHand().containsEnchantment(Enchantment.SILK_TOUCH);
if (silkTouch && !mcMMO.p.getAdvancedConfig().getDoubleDropSilkTouchEnabled()) if (silkTouch && !mcMMO.p.getAdvancedConfig().getDoubleDropSilkTouchEnabled()) {
return; return;
}
//Mining mastery allows for a chance of triple drops //Mining mastery allows for a chance of triple drops
if (canMotherLode()) { if (canMotherLode()) {
//Triple Drops failed so do a normal double drops check //Triple Drops failed so do a normal double drops check
@ -118,20 +142,30 @@ public class MiningManager extends SkillManager {
} }
} }
/**
* Processes triple drops for Mining.
*
* @param blockState The {@link BlockState} to check ability activation for
* @return true if triple drops were successful, false otherwise
*/
private boolean processTripleDrops(@NotNull BlockState blockState) { private boolean processTripleDrops(@NotNull BlockState blockState) {
//TODO: Make this readable //TODO: Make this readable
if (ProbabilityUtil.isSkillRNGSuccessful(SubSkillType.MINING_MOTHER_LODE, mmoPlayer)) { if (ProbabilityUtil.isSkillRNGSuccessful(SubSkillType.MINING_MOTHER_LODE, mmoPlayer)) {
BlockUtils.markDropsAsBonus(blockState, 2); BlockUtils.markDropsAsBonus(blockState, 2);
return true; return true;
} else { }
return false; return false;
} }
}
/**
* Processes double drops for Mining.
*
* @param blockState The {@link BlockState} to check ability activation for
*/
private void processDoubleDrops(@NotNull BlockState blockState) { private void processDoubleDrops(@NotNull BlockState blockState) {
//TODO: Make this readable
if (ProbabilityUtil.isSkillRNGSuccessful(SubSkillType.MINING_DOUBLE_DROPS, mmoPlayer)) { if (ProbabilityUtil.isSkillRNGSuccessful(SubSkillType.MINING_DOUBLE_DROPS, mmoPlayer)) {
boolean useTriple = mmoPlayer.getAbilityMode(SuperAbilityType.SUPER_BREAKER) && mcMMO.p.getAdvancedConfig().getAllowMiningTripleDrops(); boolean useTriple = mmoPlayer.getAbilityMode(SuperAbilityType.SUPER_BREAKER)
&& mcMMO.p.getAdvancedConfig().getAllowMiningTripleDrops();
BlockUtils.markDropsAsBonus(blockState, useTriple); BlockUtils.markDropsAsBonus(blockState, useTriple);
} }
} }
@ -165,7 +199,8 @@ public class MiningManager extends SkillManager {
mmoPlayer.setAbilityDATS(SuperAbilityType.BLAST_MINING, System.currentTimeMillis()); mmoPlayer.setAbilityDATS(SuperAbilityType.BLAST_MINING, System.currentTimeMillis());
mmoPlayer.setAbilityInformed(SuperAbilityType.BLAST_MINING, false); mmoPlayer.setAbilityInformed(SuperAbilityType.BLAST_MINING, false);
mcMMO.p.getFoliaLib().getImpl().runAtEntityLater(mmoPlayer.getPlayer(), new AbilityCooldownTask(mmoPlayer, SuperAbilityType.BLAST_MINING), (long) SuperAbilityType.BLAST_MINING.getCooldown() * Misc.TICK_CONVERSION_FACTOR); mcMMO.p.getFoliaLib().getImpl().runAtEntityLater(mmoPlayer.getPlayer(), new AbilityCooldownTask(mmoPlayer, SuperAbilityType.BLAST_MINING),
(long) SuperAbilityType.BLAST_MINING.getCooldown() * Misc.TICK_CONVERSION_FACTOR);
} }
/** /**
@ -175,66 +210,56 @@ public class MiningManager extends SkillManager {
* @param event The {@link EntityExplodeEvent} * @param event The {@link EntityExplodeEvent}
*/ */
public void blastMiningDropProcessing(float yield, EntityExplodeEvent event) { public void blastMiningDropProcessing(float yield, EntityExplodeEvent event) {
if (yield == 0) if (yield == 0) return;
return;
var increasedYieldFromBonuses = yield + (yield * getOreBonus()); var increasedYieldFromBonuses = yield + (yield * getOreBonus());
// Strip out only stuff that gives mining XP
List<BlockState> ores = new ArrayList<>(); List<BlockState> ores = new ArrayList<>();
List<BlockState> notOres = new ArrayList<>(); List<BlockState> nonOres = new ArrayList<>();
for (Block targetBlock : event.blockList()) { for (Block targetBlock : event.blockList()) {
BlockState blockState = targetBlock.getState(); BlockState blockState = targetBlock.getState();
if(mcMMO.getUserBlockTracker().isIneligible(targetBlock)) if (mcMMO.getUserBlockTracker().isIneligible(targetBlock)) continue;
continue;
if (ExperienceConfig.getInstance().getXp(PrimarySkillType.MINING, targetBlock) != 0) { if (ExperienceConfig.getInstance().getXp(PrimarySkillType.MINING, targetBlock) != 0) {
if (BlockUtils.isOre(blockState) && !(targetBlock instanceof Container)) { if (BlockUtils.isOre(blockState) && !(targetBlock instanceof Container)) {
ores.add(blockState); ores.add(blockState);
} else {
nonOres.add(blockState);
} }
} else { } else {
notOres.add(blockState); nonOres.add(blockState);
} }
} }
int xp = 0; int xp = 0;
int dropMultiplier = getDropMultiplier(); int dropMultiplier = getDropMultiplier();
for(BlockState blockState : notOres) { for (BlockState blockState : nonOres) {
if (isDropIllegal(blockState.getType())) Collection<ItemStack> drops = blockState.getBlock().getDrops(mmoPlayer.getPlayer().getInventory().getItemInMainHand());
continue; ItemUtils.spawnItems(getPlayer(), Misc.getBlockCenter(blockState), drops, ItemSpawnReason.BLAST_MINING_DEBRIS_NON_ORES);
}
if (Probability.ofPercent(50).evaluate()) {
ItemUtils.spawnItem(getPlayer(),
Misc.getBlockCenter(blockState),
new ItemStack(blockState.getType()),
ItemSpawnReason.BLAST_MINING_DEBRIS_NON_ORES); // Initial block that would have been dropped
}
}
for (BlockState blockState : ores) { for (BlockState blockState : ores) {
// currentOreYield only used for drop calculations for ores // currentOreYield only used for drop calculations for ores
float currentOreYield = increasedYieldFromBonuses; float currentOreYield = increasedYieldFromBonuses;
if (isDropIllegal(blockState.getType())) {
continue;
}
// Always give XP for every ore destroyed // Always give XP for every ore destroyed
xp += Mining.getBlockXp(blockState); xp += Mining.getBlockXp(blockState);
while(currentOreYield > 0) { while (currentOreYield > 0) {
if (Probability.ofValue(currentOreYield).evaluate()) { if (Probability.ofValue(currentOreYield).evaluate()) {
Collection<ItemStack> oreDrops = isPickaxe(mmoPlayer.getPlayer().getInventory().getItemInMainHand()) Collection<ItemStack> oreDrops = isPickaxe(mmoPlayer.getPlayer().getInventory().getItemInMainHand())
? blockState.getBlock().getDrops(mmoPlayer.getPlayer().getInventory().getItemInMainHand()) ? blockState.getBlock().getDrops(mmoPlayer.getPlayer().getInventory().getItemInMainHand())
: List.of(new ItemStack(blockState.getType())); : List.of(new ItemStack(blockState.getType()));
ItemUtils.spawnItems(getPlayer(), Misc.getBlockCenter(blockState), ItemUtils.spawnItems(getPlayer(), Misc.getBlockCenter(blockState),
oreDrops, BLAST_MINING_BLACKLIST, ItemSpawnReason.BLAST_MINING_ORES); oreDrops, ItemSpawnReason.BLAST_MINING_ORES);
if (mcMMO.p.getAdvancedConfig().isBlastMiningBonusDropsEnabled()) { if (mcMMO.p.getAdvancedConfig().isBlastMiningBonusDropsEnabled()) {
for (int i = 1; i < dropMultiplier; i++) { for (int i = 1; i < dropMultiplier; i++) {
ItemUtils.spawnItems(getPlayer(), ItemUtils.spawnItems(getPlayer(),
Misc.getBlockCenter(blockState), Misc.getBlockCenter(blockState),
oreDrops, oreDrops,
BLAST_MINING_BLACKLIST,
ItemSpawnReason.BLAST_MINING_ORES_BONUS_DROP); ItemSpawnReason.BLAST_MINING_ORES_BONUS_DROP);
} }
} }
@ -243,22 +268,10 @@ public class MiningManager extends SkillManager {
} }
} }
// Replace the event blocklist with the newYield list
event.setYield(0F); event.setYield(0F);
applyXpGain(xp, XPGainReason.PVE); applyXpGain(xp, XPGainReason.PVE);
} }
/**
* Checks if it would be illegal (in vanilla) to obtain the block
* Certain things should never drop ( such as budding_amethyst )
*
* @param material target material
* @return true if it's not legal to obtain the block through normal gameplay
*/
public boolean isDropIllegal(@NotNull Material material) {
return material.getKey().getKey().equalsIgnoreCase(BUDDING_AMETHYST);
}
/** /**
* Increases the blast radius of the explosion. * Increases the blast radius of the explosion.
* *
@ -269,6 +282,12 @@ public class MiningManager extends SkillManager {
return (float) (radius + getBlastRadiusModifier()); return (float) (radius + getBlastRadiusModifier());
} }
/**
* Processes damage reduction for Demolitions Expertise.
*
* @param damage initial damage
* @return reduced damage
*/
public double processDemolitionsExpertise(double damage) { public double processDemolitionsExpertise(double damage) {
return damage * ((100.0D - getBlastDamageModifier()) / 100.0D); return damage * ((100.0D - getBlastDamageModifier()) / 100.0D);
} }
@ -283,9 +302,9 @@ public class MiningManager extends SkillManager {
} }
/** /**
* Gets the Blast Mining tier * Gets the ore bonus for Blast Mining.
* *
* @return the Blast Mining tier * @return the ore bonus as a float value
*/ */
public float getOreBonus() { public float getOreBonus() {
return (float) (mcMMO.p.getAdvancedConfig().getOreBonus(getBlastMiningTier()) / 100F); return (float) (mcMMO.p.getAdvancedConfig().getOreBonus(getBlastMiningTier()) / 100F);
@ -296,27 +315,39 @@ public class MiningManager extends SkillManager {
return mcMMO.p.getAdvancedConfig().getOreBonus(rank); return mcMMO.p.getAdvancedConfig().getOreBonus(rank);
} }
/**
* Gets the debris reduction for Blast Mining.
*
* @param rank the current rank of Blast Mining
* @return the debris reduction as a double value
*/
public static double getDebrisReduction(int rank) { public static double getDebrisReduction(int rank) {
return mcMMO.p.getAdvancedConfig().getDebrisReduction(rank); return mcMMO.p.getAdvancedConfig().getDebrisReduction(rank);
} }
/** /**
* Gets the Blast Mining tier * Gets the debris reduction for the player's current Blast Mining tier.
* *
* @return the Blast Mining tier * @return the debris reduction as a double value
*/ */
public double getDebrisReduction() { public double getDebrisReduction() {
return getDebrisReduction(getBlastMiningTier()); return getDebrisReduction(getBlastMiningTier());
} }
/**
* Gets the drop multiplier for Blast Mining.
*
* @param rank the current rank of Blast Mining
* @return the drop multiplier
*/
public static int getDropMultiplier(int rank) { public static int getDropMultiplier(int rank) {
return mcMMO.p.getAdvancedConfig().getDropMultiplier(rank); return mcMMO.p.getAdvancedConfig().getDropMultiplier(rank);
} }
/** /**
* Gets the Blast Mining tier * Gets the drop multiplier for the player's current Blast Mining tier.
* *
* @return the Blast Mining tier * @return the drop multiplier
*/ */
public int getDropMultiplier() { public int getDropMultiplier() {
if (!mcMMO.p.getAdvancedConfig().isBlastMiningBonusDropsEnabled()) { if (!mcMMO.p.getAdvancedConfig().isBlastMiningBonusDropsEnabled()) {
@ -332,23 +363,28 @@ public class MiningManager extends SkillManager {
} }
/** /**
* Gets the Blast Mining tier * Gets the blast radius modifier for the player's current Blast Mining tier.
* *
* @return the Blast Mining tier * @return the blast radius modifier
*/ */
public double getBlastRadiusModifier() { public double getBlastRadiusModifier() {
return BlastMining.getBlastRadiusModifier(getBlastMiningTier()); return BlastMining.getBlastRadiusModifier(getBlastMiningTier());
} }
/** /**
* Gets the Blast Mining tier * Gets the blast damage modifier for the player's current Blast Mining tier.
* *
* @return the Blast Mining tier * @return the blast damage modifier
*/ */
public double getBlastDamageModifier() { public double getBlastDamageModifier() {
return BlastMining.getBlastDamageDecrease(getBlastMiningTier()); return BlastMining.getBlastDamageDecrease(getBlastMiningTier());
} }
/**
* Checks if the Blast Mining cooldown is over.
*
* @return true if the cooldown is over, false otherwise
*/
private boolean blastMiningCooldownOver() { private boolean blastMiningCooldownOver() {
int timeRemaining = mmoPlayer.calculateTimeRemaining(SuperAbilityType.BLAST_MINING); int timeRemaining = mmoPlayer.calculateTimeRemaining(SuperAbilityType.BLAST_MINING);