Skip to content

Commit 072f900

Browse files
committed
fix mcMMO spawning bonus drops into other blocks
fixes #5149
1 parent 82af006 commit 072f900

File tree

8 files changed

+25
-15
lines changed

8 files changed

+25
-15
lines changed

Changelog.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Version 2.2.034
2+
Fixed bug where mcMMO would drop items in such a way that they get stuck in an adjacent block and float to the surface
23
Fixed a rare edge case where null entities during chunk unload would cause a NullPointerException and potentially lead to server instability
34
Fixed bug where arrow would award archery xp after a crossbow trickshot bounce
45

src/main/java/com/gmail/nossr50/listeners/BlockListener.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939

4040
import java.util.HashSet;
4141

42+
import static com.gmail.nossr50.util.Misc.getBlockCenter;
43+
4244
public class BlockListener implements Listener {
4345
private final mcMMO plugin;
4446

@@ -103,11 +105,15 @@ public void onBlockDropItemEvent(BlockDropItemEvent event) {
103105
}
104106

105107
if (event.getBlock().getMetadata(MetadataConstants.METADATA_KEY_BONUS_DROPS).size() > 0) {
106-
BonusDropMeta bonusDropMeta = (BonusDropMeta) event.getBlock().getMetadata(MetadataConstants.METADATA_KEY_BONUS_DROPS).get(0);
108+
final BonusDropMeta bonusDropMeta =
109+
(BonusDropMeta) event.getBlock().getMetadata(
110+
MetadataConstants.METADATA_KEY_BONUS_DROPS).get(0);
107111
int bonusCount = bonusDropMeta.asInt();
108-
112+
final Location centeredLocation = getBlockCenter(event.getBlock());
109113
for (int i = 0; i < bonusCount; i++) {
110-
ItemUtils.spawnItemNaturally(event.getPlayer(), event.getBlockState().getLocation(), is, ItemSpawnReason.BONUS_DROPS);
114+
115+
ItemUtils.spawnItemNaturally(event.getPlayer(),
116+
centeredLocation, is, ItemSpawnReason.BONUS_DROPS);
111117
}
112118
}
113119
}

src/main/java/com/gmail/nossr50/skills/excavation/ExcavationManager.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ public void excavationBlockCheck(Block block) {
5050

5151
if (!treasures.isEmpty()) {
5252
int skillLevel = getSkillLevel();
53-
Location location = Misc.getBlockCenter(block);
53+
final Location centerOfBlock = Misc.getBlockCenter(block);
5454

5555
for (ExcavationTreasure treasure : treasures) {
5656
if (skillLevel >= treasure.getDropLevel()
5757
&& ProbabilityUtil.isStaticSkillRNGSuccessful(
5858
PrimarySkillType.EXCAVATION, mmoPlayer, treasure.getDropProbability())) {
59-
processExcavationBonusesOnBlock(treasure, location);
59+
processExcavationBonusesOnBlock(treasure, centerOfBlock);
6060
}
6161
}
6262
}

src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
import static com.gmail.nossr50.util.ItemUtils.hasItemIncludingOffHand;
4545
import static com.gmail.nossr50.util.ItemUtils.removeItemIncludingOffHand;
46+
import static com.gmail.nossr50.util.Misc.getBlockCenter;
4647
import static com.gmail.nossr50.util.text.ConfigStringUtils.getMaterialConfigString;
4748
import static java.util.Objects.requireNonNull;
4849

@@ -733,7 +734,7 @@ public boolean processHylianLuck(BlockState blockState) {
733734
return false;
734735
}
735736
int skillLevel = getSkillLevel();
736-
Location location = Misc.getBlockCenter(blockState);
737+
final Location centerOfBlock = getBlockCenter(blockState);
737738

738739
for (HylianTreasure treasure : treasures) {
739740
if (skillLevel >= treasure.getDropLevel()
@@ -742,7 +743,7 @@ public boolean processHylianLuck(BlockState blockState) {
742743
return false;
743744
}
744745
blockState.setType(Material.AIR);
745-
ItemUtils.spawnItem(getPlayer(), location, treasure.getDrop(), ItemSpawnReason.HYLIAN_LUCK_TREASURE);
746+
ItemUtils.spawnItem(getPlayer(), centerOfBlock, treasure.getDrop(), ItemSpawnReason.HYLIAN_LUCK_TREASURE);
746747
NotificationManager.sendPlayerInformation(mmoPlayer.getPlayer(), NotificationType.SUBSKILL_MESSAGE, "Herbalism.HylianLuck");
747748
return true;
748749
}

src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.util.*;
3232

3333
import static com.gmail.nossr50.util.ItemUtils.isPickaxe;
34+
import static com.gmail.nossr50.util.Misc.getBlockCenter;
3435

3536
public class MiningManager extends SkillManager {
3637

@@ -214,7 +215,7 @@ public void blastMiningDropProcessing(float yield, EntityExplodeEvent event) {
214215

215216
if (block.getType().isItem() && Probability.ofPercent(10).evaluate()) {
216217
ItemUtils.spawnItem(getPlayer(),
217-
Misc.getBlockCenter(block),
218+
getBlockCenter(block),
218219
new ItemStack(block.getType()),
219220
ItemSpawnReason.BLAST_MINING_DEBRIS_NON_ORES); // Initial block that would have been dropped
220221
}
@@ -234,14 +235,14 @@ public void blastMiningDropProcessing(float yield, EntityExplodeEvent event) {
234235
Collection<ItemStack> oreDrops = isPickaxe(mmoPlayer.getPlayer().getInventory().getItemInMainHand())
235236
? block.getDrops(mmoPlayer.getPlayer().getInventory().getItemInMainHand())
236237
: List.of(new ItemStack(block.getType()));
237-
ItemUtils.spawnItems(getPlayer(), Misc.getBlockCenter(block),
238+
ItemUtils.spawnItems(getPlayer(), getBlockCenter(block),
238239
oreDrops, BLAST_MINING_BLACKLIST, ItemSpawnReason.BLAST_MINING_ORES);
239240

240241
if (mcMMO.p.getAdvancedConfig().isBlastMiningBonusDropsEnabled()) {
241242
if (Probability.ofValue(0.5F).evaluate()) {
242243
for (int i = 1; i < dropMultiplier; i++) {
243-
ItemUtils.spawnItems(getPlayer(),
244-
Misc.getBlockCenter(block),
244+
ItemUtils.pawnItems(getPlayer(),
245+
getBlockCenter(block),
245246
oreDrops,
246247
BLAST_MINING_BLACKLIST,
247248
ItemSpawnReason.BLAST_MINING_ORES_BONUS_DROP);

src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ public void disarmCheck(@NotNull Player defender) {
109109
if (UserManager.getPlayer(defender) == null)
110110
return;
111111

112-
Item item = ItemUtils.spawnItem(getPlayer(), defender.getLocation(), defender.getInventory().getItemInMainHand(), ItemSpawnReason.UNARMED_DISARMED_ITEM);
112+
final Item item = ItemUtils.spawnItem(getPlayer(), defender.getLocation(),
113+
defender.getInventory().getItemInMainHand(), ItemSpawnReason.UNARMED_DISARMED_ITEM);
113114

114115
if (item != null && mcMMO.p.getAdvancedConfig().getDisarmProtected()) {
115116
item.setMetadata(MetadataConstants.METADATA_KEY_DISARMED_ITEM, UserManager.getPlayer(defender).getPlayerMetadata());

src/main/java/com/gmail/nossr50/util/ItemUtils.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ public static void spawnItems(@Nullable Player player,
759759
}
760760

761761
// We can't get the item until we spawn it and we want to make it cancellable, so we have a custom event.
762-
McMMOItemSpawnEvent event = new McMMOItemSpawnEvent(location, itemStack, itemSpawnReason, player);
762+
final McMMOItemSpawnEvent event = new McMMOItemSpawnEvent(location, itemStack, itemSpawnReason, player);
763763
mcMMO.p.getServer().getPluginManager().callEvent(event);
764764

765765
if (event.isCancelled()) {
@@ -786,7 +786,7 @@ public static void spawnItems(@Nullable Player player,
786786
}
787787

788788
// We can't get the item until we spawn it and we want to make it cancellable, so we have a custom event.
789-
McMMOItemSpawnEvent event = new McMMOItemSpawnEvent(location, itemStack, itemSpawnReason, player);
789+
final McMMOItemSpawnEvent event = new McMMOItemSpawnEvent(location, itemStack, itemSpawnReason, player);
790790
mcMMO.p.getServer().getPluginManager().callEvent(event);
791791

792792
if (event.isCancelled()) {

src/main/java/com/gmail/nossr50/util/Misc.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public static Location getBlockCenter(Block block) {
109109
}
110110

111111
public static Location getBlockCenter(Location location) {
112-
return location.add(0.5, 0.5, 0.5);
112+
return location.clone().add(0.5, 0.5, 0.5);
113113
}
114114

115115
public static void profileCleanup(@NotNull String playerName) {

0 commit comments

Comments
 (0)