浏览代码

fix mcMMO spawning bonus drops into other blocks
fixes #5149

nossr50 2 月之前
父节点
当前提交
f69f88add7

+ 1 - 0
Changelog.txt

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

+ 9 - 3
src/main/java/com/gmail/nossr50/listeners/BlockListener.java

@@ -39,6 +39,8 @@ import org.bukkit.inventory.ItemStack;
 
 import java.util.HashSet;
 
+import static com.gmail.nossr50.util.Misc.getBlockCenter;
+
 public class BlockListener implements Listener {
     private final mcMMO plugin;
 
@@ -103,11 +105,15 @@ public class BlockListener implements Listener {
                 }
 
                 if (event.getBlock().getMetadata(MetadataConstants.METADATA_KEY_BONUS_DROPS).size() > 0) {
-                    BonusDropMeta bonusDropMeta = (BonusDropMeta) event.getBlock().getMetadata(MetadataConstants.METADATA_KEY_BONUS_DROPS).get(0);
+                    final BonusDropMeta bonusDropMeta =
+                            (BonusDropMeta) event.getBlock().getMetadata(
+                                    MetadataConstants.METADATA_KEY_BONUS_DROPS).get(0);
                     int bonusCount = bonusDropMeta.asInt();
-
+                    final Location centeredLocation = getBlockCenter(event.getBlock());
                     for (int i = 0; i < bonusCount; i++) {
-                        ItemUtils.spawnItemNaturally(event.getPlayer(), event.getBlockState().getLocation(), is, ItemSpawnReason.BONUS_DROPS);
+
+                        ItemUtils.spawnItemNaturally(event.getPlayer(),
+                                centeredLocation, is, ItemSpawnReason.BONUS_DROPS);
                     }
                 }
             }

+ 2 - 2
src/main/java/com/gmail/nossr50/skills/excavation/ExcavationManager.java

@@ -50,13 +50,13 @@ public class ExcavationManager extends SkillManager {
 
             if (!treasures.isEmpty()) {
                 int skillLevel = getSkillLevel();
-                Location location = Misc.getBlockCenter(block);
+                final Location centerOfBlock = Misc.getBlockCenter(block);
 
                 for (ExcavationTreasure treasure : treasures) {
                     if (skillLevel >= treasure.getDropLevel()
                             && ProbabilityUtil.isStaticSkillRNGSuccessful(
                             PrimarySkillType.EXCAVATION, mmoPlayer, treasure.getDropProbability())) {
-                        processExcavationBonusesOnBlock(treasure, location);
+                        processExcavationBonusesOnBlock(treasure, centerOfBlock);
                     }
                 }
             }

+ 3 - 2
src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java

@@ -43,6 +43,7 @@ import java.util.*;
 
 import static com.gmail.nossr50.util.ItemUtils.hasItemIncludingOffHand;
 import static com.gmail.nossr50.util.ItemUtils.removeItemIncludingOffHand;
+import static com.gmail.nossr50.util.Misc.getBlockCenter;
 import static com.gmail.nossr50.util.text.ConfigStringUtils.getMaterialConfigString;
 import static java.util.Objects.requireNonNull;
 
@@ -733,7 +734,7 @@ public class HerbalismManager extends SkillManager {
             return false;
         }
         int skillLevel = getSkillLevel();
-        Location location = Misc.getBlockCenter(blockState);
+        final Location centerOfBlock = getBlockCenter(blockState);
 
         for (HylianTreasure treasure : treasures) {
             if (skillLevel >= treasure.getDropLevel()
@@ -742,7 +743,7 @@ public class HerbalismManager extends SkillManager {
                     return false;
                 }
                 blockState.setType(Material.AIR);
-                ItemUtils.spawnItem(getPlayer(), location, treasure.getDrop(), ItemSpawnReason.HYLIAN_LUCK_TREASURE);
+                ItemUtils.spawnItem(getPlayer(), centerOfBlock, treasure.getDrop(), ItemSpawnReason.HYLIAN_LUCK_TREASURE);
                 NotificationManager.sendPlayerInformation(mmoPlayer.getPlayer(), NotificationType.SUBSKILL_MESSAGE, "Herbalism.HylianLuck");
                 return true;
             }

+ 4 - 3
src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java

@@ -31,6 +31,7 @@ import org.jetbrains.annotations.NotNull;
 import java.util.*;
 
 import static com.gmail.nossr50.util.ItemUtils.isPickaxe;
+import static com.gmail.nossr50.util.Misc.getBlockCenter;
 
 public class MiningManager extends SkillManager {
 
@@ -214,7 +215,7 @@ public class MiningManager extends SkillManager {
 
             if (block.getType().isItem() && Probability.ofPercent(10).evaluate()) {
                 ItemUtils.spawnItem(getPlayer(),
-                        Misc.getBlockCenter(block),
+                        getBlockCenter(block),
                         new ItemStack(block.getType()),
                         ItemSpawnReason.BLAST_MINING_DEBRIS_NON_ORES); // Initial block that would have been dropped
             }
@@ -234,14 +235,14 @@ public class MiningManager extends SkillManager {
                     Collection<ItemStack> oreDrops = isPickaxe(mmoPlayer.getPlayer().getInventory().getItemInMainHand())
                             ? block.getDrops(mmoPlayer.getPlayer().getInventory().getItemInMainHand())
                             : List.of(new ItemStack(block.getType()));
-                    ItemUtils.spawnItems(getPlayer(), Misc.getBlockCenter(block),
+                    ItemUtils.spawnItems(getPlayer(), getBlockCenter(block),
                             oreDrops, BLAST_MINING_BLACKLIST, ItemSpawnReason.BLAST_MINING_ORES);
 
                     if (mcMMO.p.getAdvancedConfig().isBlastMiningBonusDropsEnabled()) {
                         if (Probability.ofValue(0.5F).evaluate()) {
                             for (int i = 1; i < dropMultiplier; i++) {
                                 ItemUtils.spawnItems(getPlayer(),
-                                        Misc.getBlockCenter(block),
+                                        getBlockCenter(block),
                                         oreDrops,
                                         BLAST_MINING_BLACKLIST,
                                         ItemSpawnReason.BLAST_MINING_ORES_BONUS_DROP);

+ 2 - 1
src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java

@@ -109,7 +109,8 @@ public class UnarmedManager extends SkillManager {
             if (UserManager.getPlayer(defender) == null)
                 return;
 
-            Item item = ItemUtils.spawnItem(getPlayer(), defender.getLocation(), defender.getInventory().getItemInMainHand(), ItemSpawnReason.UNARMED_DISARMED_ITEM);
+            final Item item = ItemUtils.spawnItem(getPlayer(), defender.getLocation(),
+                    defender.getInventory().getItemInMainHand(), ItemSpawnReason.UNARMED_DISARMED_ITEM);
 
             if (item != null && mcMMO.p.getAdvancedConfig().getDisarmProtected()) {
                 item.setMetadata(MetadataConstants.METADATA_KEY_DISARMED_ITEM, UserManager.getPlayer(defender).getPlayerMetadata());

+ 2 - 2
src/main/java/com/gmail/nossr50/util/ItemUtils.java

@@ -759,7 +759,7 @@ public final class ItemUtils {
         }
 
         // We can't get the item until we spawn it and we want to make it cancellable, so we have a custom event.
-        McMMOItemSpawnEvent event = new McMMOItemSpawnEvent(location, itemStack, itemSpawnReason, player);
+        final McMMOItemSpawnEvent event = new McMMOItemSpawnEvent(location, itemStack, itemSpawnReason, player);
         mcMMO.p.getServer().getPluginManager().callEvent(event);
 
         if (event.isCancelled()) {
@@ -786,7 +786,7 @@ public final class ItemUtils {
         }
 
         // We can't get the item until we spawn it and we want to make it cancellable, so we have a custom event.
-        McMMOItemSpawnEvent event = new McMMOItemSpawnEvent(location, itemStack, itemSpawnReason, player);
+        final McMMOItemSpawnEvent event = new McMMOItemSpawnEvent(location, itemStack, itemSpawnReason, player);
         mcMMO.p.getServer().getPluginManager().callEvent(event);
 
         if (event.isCancelled()) {

+ 1 - 1
src/main/java/com/gmail/nossr50/util/Misc.java

@@ -109,7 +109,7 @@ public final class Misc {
     }
 
     public static Location getBlockCenter(Location location) {
-        return location.add(0.5, 0.5, 0.5);
+        return location.clone().add(0.5, 0.5, 0.5);
     }
 
     public static void profileCleanup(@NotNull String playerName) {