mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-22 10:35:38 +01:00
Make natural item dropping mimic Vanilla
Make sure we don't regress SPIGOT-260 by using exact drop method like Entity does
This commit is contained in:
parent
1057710a78
commit
aed3aecbaf
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user