mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-26 18:54:44 +02:00
Expanding McMMOItemSpawnEvent & Fixing a bug with Tree Feller drops
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
package com.gmail.nossr50.skills.archery;
|
||||
|
||||
import com.gmail.nossr50.api.ItemSpawnReason;
|
||||
import com.gmail.nossr50.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.config.experience.ExperienceConfig;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
@ -9,6 +10,7 @@ import org.bukkit.Material;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
@ -50,12 +52,12 @@ public class Archery {
|
||||
*
|
||||
* @param livingEntity The entity hit by the arrows
|
||||
*/
|
||||
public static void arrowRetrievalCheck(LivingEntity livingEntity) {
|
||||
public static void arrowRetrievalCheck(@NotNull LivingEntity livingEntity) {
|
||||
for (Iterator<TrackedEntity> entityIterator = trackedEntities.iterator(); entityIterator.hasNext();) {
|
||||
TrackedEntity trackedEntity = entityIterator.next();
|
||||
|
||||
if (trackedEntity.getID() == livingEntity.getUniqueId()) {
|
||||
Misc.dropItems(livingEntity.getLocation(), new ItemStack(Material.ARROW), trackedEntity.getArrowCount());
|
||||
Misc.spawnItems(livingEntity.getLocation(), new ItemStack(Material.ARROW), trackedEntity.getArrowCount(), ItemSpawnReason.ARROW_RETRIEVAL_ACTIVATED);
|
||||
entityIterator.remove();
|
||||
return;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.gmail.nossr50.skills.excavation;
|
||||
|
||||
import com.gmail.nossr50.api.ItemSpawnReason;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.experience.XPGainReason;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
@ -51,7 +52,7 @@ public class ExcavationManager extends SkillManager {
|
||||
}
|
||||
|
||||
xp += treasure.getXp();
|
||||
Misc.dropItem(location, treasure.getDrop());
|
||||
Misc.spawnItem(location, treasure.getDrop(), ItemSpawnReason.EXCAVATION_TREASURE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.gmail.nossr50.skills.fishing;
|
||||
|
||||
import com.gmail.nossr50.api.ItemSpawnReason;
|
||||
import com.gmail.nossr50.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.config.experience.ExperienceConfig;
|
||||
@ -318,7 +319,7 @@ public class FishingManager extends SkillManager {
|
||||
}
|
||||
|
||||
if (Config.getInstance().getFishingExtraFish()) {
|
||||
Misc.dropItem(player.getEyeLocation(), fishingCatch.getItemStack());
|
||||
Misc.spawnItem(player.getEyeLocation(), fishingCatch.getItemStack(), ItemSpawnReason.FISHING_EXTRA_FISH);
|
||||
}
|
||||
|
||||
fishingCatch.setItemStack(treasureDrop);
|
||||
@ -426,7 +427,7 @@ public class FishingManager extends SkillManager {
|
||||
return;
|
||||
}
|
||||
|
||||
Misc.dropItem(target.getLocation(), drop);
|
||||
Misc.spawnItem(target.getLocation(), drop, ItemSpawnReason.FISHING_SHAKE_TREASURE);
|
||||
CombatUtils.dealDamage(target, Math.min(Math.max(target.getMaxHealth() / 4, 1), 10), EntityDamageEvent.DamageCause.CUSTOM, getPlayer()); // Make it so you can shake a mob no more than 4 times.
|
||||
applyXpGain(ExperienceConfig.getInstance().getFishingShakeXP(), XPGainReason.PVE);
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.gmail.nossr50.skills.herbalism;
|
||||
|
||||
import com.gmail.nossr50.api.ItemSpawnReason;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.config.experience.ExperienceConfig;
|
||||
import com.gmail.nossr50.config.treasure.TreasureConfig;
|
||||
@ -626,7 +627,7 @@ public class HerbalismManager extends SkillManager {
|
||||
return false;
|
||||
}
|
||||
blockState.setType(Material.AIR);
|
||||
Misc.dropItem(location, treasure.getDrop());
|
||||
Misc.spawnItem(location, treasure.getDrop(), ItemSpawnReason.HYLIAN_LUCK_TREASURE);
|
||||
NotificationManager.sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE, "Herbalism.HylianLuck");
|
||||
return true;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.gmail.nossr50.skills.mining;
|
||||
|
||||
import com.gmail.nossr50.api.ItemSpawnReason;
|
||||
import com.gmail.nossr50.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.config.experience.ExperienceConfig;
|
||||
@ -188,7 +189,7 @@ public class MiningManager extends SkillManager {
|
||||
//Drop "debris" based on skill modifiers
|
||||
for(BlockState blockState : notOres) {
|
||||
if(RandomUtils.nextFloat() < debrisYield) {
|
||||
Misc.dropItem(Misc.getBlockCenter(blockState), new ItemStack(blockState.getType())); // Initial block that would have been dropped
|
||||
Misc.spawnItem(Misc.getBlockCenter(blockState), new ItemStack(blockState.getType()), ItemSpawnReason.BLAST_MINING_DEBRIS_NON_ORES); // Initial block that would have been dropped
|
||||
}
|
||||
}
|
||||
|
||||
@ -196,12 +197,12 @@ public class MiningManager extends SkillManager {
|
||||
if (RandomUtils.nextFloat() < (yield + oreBonus)) {
|
||||
xp += Mining.getBlockXp(blockState);
|
||||
|
||||
Misc.dropItem(Misc.getBlockCenter(blockState), new ItemStack(blockState.getType())); // Initial block that would have been dropped
|
||||
Misc.spawnItem(Misc.getBlockCenter(blockState), new ItemStack(blockState.getType()), ItemSpawnReason.BLAST_MINING_ORES); // Initial block that would have been dropped
|
||||
|
||||
if (!mcMMO.getPlaceStore().isTrue(blockState)) {
|
||||
for (int i = 1; i < dropMultiplier; i++) {
|
||||
// Bukkit.broadcastMessage("Bonus Drop on Ore: "+blockState.getType().toString());
|
||||
Misc.dropItem(Misc.getBlockCenter(blockState), new ItemStack(blockState.getType())); // Initial block that would have been dropped
|
||||
Misc.spawnItem(Misc.getBlockCenter(blockState), new ItemStack(blockState.getType()), ItemSpawnReason.BLAST_MINING_ORES_BONUS_DROP); // Initial block that would have been dropped
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.gmail.nossr50.skills.salvage;
|
||||
|
||||
import com.gmail.nossr50.api.ItemSpawnReason;
|
||||
import com.gmail.nossr50.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.config.experience.ExperienceConfig;
|
||||
@ -159,10 +160,10 @@ public class SalvageManager extends SkillManager {
|
||||
anvilLoc.add(0, .1, 0);
|
||||
|
||||
if (enchantBook != null) {
|
||||
Misc.spawnItemTowardsLocation(anvilLoc.clone(), playerLoc.clone(), enchantBook, vectorSpeed);
|
||||
Misc.spawnItemTowardsLocation(anvilLoc.clone(), playerLoc.clone(), enchantBook, vectorSpeed, ItemSpawnReason.SALVAGE_ENCHANTMENT_BOOK);
|
||||
}
|
||||
|
||||
Misc.spawnItemTowardsLocation(anvilLoc.clone(), playerLoc.clone(), salvageResults, vectorSpeed);
|
||||
Misc.spawnItemTowardsLocation(anvilLoc.clone(), playerLoc.clone(), salvageResults, vectorSpeed, ItemSpawnReason.SALVAGE_MATERIALS);
|
||||
|
||||
// BWONG BWONG BWONG - CLUNK!
|
||||
if (Config.getInstance().getSalvageAnvilUseSoundsEnabled()) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.gmail.nossr50.skills.unarmed;
|
||||
|
||||
import com.gmail.nossr50.api.ItemSpawnReason;
|
||||
import com.gmail.nossr50.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.datatypes.interactions.NotificationType;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
@ -109,7 +110,7 @@ public class UnarmedManager extends SkillManager {
|
||||
if(UserManager.getPlayer(defender) == null)
|
||||
return;
|
||||
|
||||
Item item = Misc.dropItem(defender.getLocation(), defender.getInventory().getItemInMainHand());
|
||||
Item item = Misc.spawnItem(defender.getLocation(), defender.getInventory().getItemInMainHand(), ItemSpawnReason.UNARMED_DISARMED_ITEM);
|
||||
|
||||
if (item != null && AdvancedConfig.getInstance().getDisarmProtected()) {
|
||||
item.setMetadata(mcMMO.disarmedItemKey, UserManager.getPlayer(defender).getPlayerMetadata());
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.gmail.nossr50.skills.woodcutting;
|
||||
|
||||
import com.gmail.nossr50.api.ItemSpawnReason;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.config.experience.ExperienceConfig;
|
||||
import com.gmail.nossr50.datatypes.experience.XPGainReason;
|
||||
@ -27,6 +28,7 @@ import org.bukkit.event.player.PlayerItemDamageEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
@ -65,10 +67,11 @@ public class WoodcuttingManager extends SkillManager {
|
||||
&& ItemUtils.isAxe(heldItem);
|
||||
}
|
||||
|
||||
private boolean canGetDoubleDrops() {
|
||||
private boolean checkHarvestLumberActivation(@NotNull Material material) {
|
||||
return Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.WOODCUTTING_HARVEST_LUMBER)
|
||||
&& RankUtils.hasReachedRank(1, getPlayer(), SubSkillType.WOODCUTTING_HARVEST_LUMBER)
|
||||
&& RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.WOODCUTTING_HARVEST_LUMBER, getPlayer());
|
||||
&& RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.WOODCUTTING_HARVEST_LUMBER, getPlayer())
|
||||
&& Config.getInstance().getDoubleDropsEnabled(PrimarySkillType.WOODCUTTING, material);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -76,20 +79,14 @@ public class WoodcuttingManager extends SkillManager {
|
||||
*
|
||||
* @param blockState Block being broken
|
||||
*/
|
||||
public void woodcuttingBlockCheck(BlockState blockState) {
|
||||
int xp = getExperienceFromLog(blockState);
|
||||
|
||||
switch (blockState.getType()) {
|
||||
case BROWN_MUSHROOM_BLOCK:
|
||||
case RED_MUSHROOM_BLOCK:
|
||||
break;
|
||||
|
||||
default:
|
||||
if (canGetDoubleDrops()) {
|
||||
checkForDoubleDrop(blockState);
|
||||
}
|
||||
public void processHarvestLumber(@NotNull BlockState blockState) {
|
||||
if (checkHarvestLumberActivation(blockState.getType())) {
|
||||
spawnHarvestLumberBonusDrops(blockState);
|
||||
}
|
||||
}
|
||||
|
||||
public void processWoodcuttingBlockXP(@NotNull BlockState blockState) {
|
||||
int xp = getExperienceFromLog(blockState);
|
||||
applyXpGain(xp, XPGainReason.PVE);
|
||||
}
|
||||
|
||||
@ -206,7 +203,7 @@ public class WoodcuttingManager extends SkillManager {
|
||||
* @param player the player holding the item
|
||||
* @return True if the tool can sustain the durability loss
|
||||
*/
|
||||
private static boolean handleDurabilityLoss(Set<BlockState> treeFellerBlocks, ItemStack inHand, Player player) {
|
||||
private static boolean handleDurabilityLoss(@NotNull Set<BlockState> treeFellerBlocks, @NotNull ItemStack inHand, @NotNull Player player) {
|
||||
//Treat the NBT tag for unbreakable and the durability enchant differently
|
||||
ItemMeta meta = inHand.getItemMeta();
|
||||
|
||||
@ -218,7 +215,7 @@ public class WoodcuttingManager extends SkillManager {
|
||||
Material type = inHand.getType();
|
||||
|
||||
for (BlockState blockState : treeFellerBlocks) {
|
||||
if (BlockUtils.isLog(blockState)) {
|
||||
if (BlockUtils.hasWoodcuttingXP(blockState)) {
|
||||
durabilityLoss += Config.getInstance().getAbilityToolDamage();
|
||||
}
|
||||
}
|
||||
@ -249,7 +246,7 @@ public class WoodcuttingManager extends SkillManager {
|
||||
* @return true if and only if the given blockState was a Log not already
|
||||
* in treeFellerBlocks.
|
||||
*/
|
||||
private boolean processTreeFellerTargetBlock(BlockState blockState, List<BlockState> futureCenterBlocks, Set<BlockState> treeFellerBlocks) {
|
||||
private boolean processTreeFellerTargetBlock(@NotNull BlockState blockState, @NotNull List<BlockState> futureCenterBlocks, @NotNull Set<BlockState> treeFellerBlocks) {
|
||||
if (treeFellerBlocks.contains(blockState) || mcMMO.getPlaceStore().isTrue(blockState)) {
|
||||
return false;
|
||||
}
|
||||
@ -259,12 +256,12 @@ public class WoodcuttingManager extends SkillManager {
|
||||
treeFellerReachedThreshold = true;
|
||||
}
|
||||
|
||||
if (BlockUtils.isLog(blockState)) {
|
||||
if (BlockUtils.hasWoodcuttingXP(blockState)) {
|
||||
treeFellerBlocks.add(blockState);
|
||||
futureCenterBlocks.add(blockState);
|
||||
return true;
|
||||
}
|
||||
else if (BlockUtils.isLeaves(blockState)) {
|
||||
else if (BlockUtils.isNonWoodPartOfTree(blockState)) {
|
||||
treeFellerBlocks.add(blockState);
|
||||
return false;
|
||||
}
|
||||
@ -276,7 +273,7 @@ public class WoodcuttingManager extends SkillManager {
|
||||
*
|
||||
* @param treeFellerBlocks List of blocks to be dropped
|
||||
*/
|
||||
private void dropTreeFellerLootFromBlocks(Set<BlockState> treeFellerBlocks) {
|
||||
private void dropTreeFellerLootFromBlocks(@NotNull Set<BlockState> treeFellerBlocks) {
|
||||
Player player = getPlayer();
|
||||
int xp = 0;
|
||||
int processedLogCount = 0;
|
||||
@ -289,25 +286,22 @@ public class WoodcuttingManager extends SkillManager {
|
||||
break; // TODO: Shouldn't we use continue instead?
|
||||
}
|
||||
|
||||
Material material = blockState.getType();
|
||||
/*
|
||||
* Handle Drops & XP
|
||||
*/
|
||||
|
||||
//TODO: Update this to drop the correct items/blocks via NMS
|
||||
if (material == Material.BROWN_MUSHROOM_BLOCK || material == Material.RED_MUSHROOM_BLOCK) {
|
||||
if (BlockUtils.hasWoodcuttingXP(blockState)) {
|
||||
//Add XP
|
||||
xp += processTreeFellerXPGains(blockState, processedLogCount);
|
||||
Misc.dropItems(Misc.getBlockCenter(blockState), block.getDrops());
|
||||
} else if (mcMMO.getModManager().isCustomLeaf(blockState)) {
|
||||
Misc.dropItems(Misc.getBlockCenter(blockState), block.getDrops());
|
||||
} else {
|
||||
if (BlockUtils.isLog(blockState)) {
|
||||
if (canGetDoubleDrops()) {
|
||||
checkForDoubleDrop(blockState);
|
||||
}
|
||||
xp += processTreeFellerXPGains(blockState, processedLogCount);
|
||||
Misc.dropItems(Misc.getBlockCenter(blockState), block.getDrops());
|
||||
}
|
||||
if (BlockUtils.isLeaves(blockState)) {
|
||||
Misc.dropItems(Misc.getBlockCenter(blockState), block.getDrops());
|
||||
}
|
||||
|
||||
//Drop displaced block
|
||||
Misc.spawnItemsFromCollection(Misc.getBlockCenter(blockState), block.getDrops(), ItemSpawnReason.TREE_FELLER_DISPLACED_BLOCK);
|
||||
|
||||
//Bonus Drops / Harvest lumber checks
|
||||
processHarvestLumber(blockState);
|
||||
} else if (BlockUtils.isNonWoodPartOfTree(blockState)) {
|
||||
//Drop displaced non-woodcutting XP blocks
|
||||
Misc.spawnItemsFromCollection(Misc.getBlockCenter(blockState), block.getDrops(), ItemSpawnReason.TREE_FELLER_DISPLACED_BLOCK, 1);
|
||||
}
|
||||
|
||||
blockState.setType(Material.AIR);
|
||||
@ -367,13 +361,11 @@ public class WoodcuttingManager extends SkillManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for double drops
|
||||
* Spawns harvest lumber bonus drops
|
||||
*
|
||||
* @param blockState Block being broken
|
||||
*/
|
||||
protected static void checkForDoubleDrop(BlockState blockState) {
|
||||
if (Config.getInstance().getWoodcuttingDoubleDropsEnabled(blockState.getBlockData())) {
|
||||
Misc.dropItems(Misc.getBlockCenter(blockState), blockState.getBlock().getDrops());
|
||||
}
|
||||
protected static void spawnHarvestLumberBonusDrops(@NotNull BlockState blockState) {
|
||||
Misc.spawnItemsFromCollection(Misc.getBlockCenter(blockState), blockState.getBlock().getDrops(), ItemSpawnReason.BONUS_DROPS);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user