From aed3aecbafff223bb8c48ace7cb18f8a7dd0b6d5 Mon Sep 17 00:00:00 2001 From: md_5 Date: Wed, 31 Oct 2018 20:09:21 +1100 Subject: [PATCH] Make natural item dropping mimic Vanilla Make sure we don't regress SPIGOT-260 by using exact drop method like Entity does --- .../org/bukkit/craftbukkit/CraftWorld.java | 37 +++---------------- .../craftbukkit/event/CraftEventFactory.java | 4 +- 2 files changed, 8 insertions(+), 33 deletions(-) diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 16fbf732d9..944595a1c6 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -292,39 +292,14 @@ public class CraftWorld implements World { return new CraftItem(world.getServer(), entity); } - private static void randomLocationWithinBlock(Location loc, double xs, double ys, double zs) { - double prevX = loc.getX(); - double prevY = loc.getY(); - double prevZ = loc.getZ(); - loc.add(xs, ys, zs); - if (loc.getX() < Math.floor(prevX)) { - loc.setX(Math.floor(prevX)); - } - if (loc.getX() >= Math.ceil(prevX)) { - loc.setX(Math.ceil(prevX - 0.01)); - } - if (loc.getY() < Math.floor(prevY)) { - loc.setY(Math.floor(prevY)); - } - if (loc.getY() >= Math.ceil(prevY)) { - loc.setY(Math.ceil(prevY - 0.01)); - } - if (loc.getZ() < Math.floor(prevZ)) { - loc.setZ(Math.floor(prevZ)); - } - if (loc.getZ() >= Math.ceil(prevZ)) { - loc.setZ(Math.ceil(prevZ - 0.01)); - } - } - public org.bukkit.entity.Item dropItemNaturally(Location loc, ItemStack item) { - double xs = world.random.nextFloat() * 0.7F - 0.35D; - double ys = world.random.nextFloat() * 0.7F - 0.35D; - double zs = world.random.nextFloat() * 0.7F - 0.35D; + double xs = (world.random.nextFloat() * 0.5F) + 0.25D; + double ys = (world.random.nextFloat() * 0.5F) + 0.25D; + double zs = (world.random.nextFloat() * 0.5F) + 0.25D; loc = loc.clone(); - // Makes sure the new item is created within the block the location points to. - // This prevents item spill in 1-block wide farms. - randomLocationWithinBlock(loc, xs, ys, zs); + loc.setX(loc.getX() + xs); + loc.setY(loc.getY() + ys); + loc.setZ(loc.getZ() + zs); return dropItem(loc, item); } diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index 4e69ccc76e..df8e99f2c2 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -438,7 +438,7 @@ public class CraftEventFactory { for (org.bukkit.inventory.ItemStack stack : event.getDrops()) { if (stack == null || stack.getType() == Material.AIR || stack.getAmount() == 0) continue; - world.dropItemNaturally(entity.getLocation(), stack); + world.dropItem(entity.getLocation(), stack); } return event; @@ -464,7 +464,7 @@ public class CraftEventFactory { for (org.bukkit.inventory.ItemStack stack : event.getDrops()) { if (stack == null || stack.getType() == Material.AIR) continue; - world.dropItemNaturally(entity.getLocation(), stack); + world.dropItem(entity.getLocation(), stack); } return event;