3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-18 20:40:08 +01:00

Make natural item dropping mimic Vanilla

Make sure we don't regress SPIGOT-260 by using exact drop method like Entity does
Dieser Commit ist enthalten in:
md_5 2018-10-31 20:09:21 +11:00
Ursprung 1057710a78
Commit aed3aecbaf
2 geänderte Dateien mit 8 neuen und 33 gelöschten Zeilen

Datei anzeigen

@ -292,39 +292,14 @@ public class CraftWorld implements World {
return new CraftItem(world.getServer(), entity); 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) { public org.bukkit.entity.Item dropItemNaturally(Location loc, ItemStack item) {
double xs = world.random.nextFloat() * 0.7F - 0.35D; double xs = (world.random.nextFloat() * 0.5F) + 0.25D;
double ys = world.random.nextFloat() * 0.7F - 0.35D; double ys = (world.random.nextFloat() * 0.5F) + 0.25D;
double zs = world.random.nextFloat() * 0.7F - 0.35D; double zs = (world.random.nextFloat() * 0.5F) + 0.25D;
loc = loc.clone(); loc = loc.clone();
// Makes sure the new item is created within the block the location points to. loc.setX(loc.getX() + xs);
// This prevents item spill in 1-block wide farms. loc.setY(loc.getY() + ys);
randomLocationWithinBlock(loc, xs, ys, zs); loc.setZ(loc.getZ() + zs);
return dropItem(loc, item); return dropItem(loc, item);
} }

Datei anzeigen

@ -438,7 +438,7 @@ public class CraftEventFactory {
for (org.bukkit.inventory.ItemStack stack : event.getDrops()) { for (org.bukkit.inventory.ItemStack stack : event.getDrops()) {
if (stack == null || stack.getType() == Material.AIR || stack.getAmount() == 0) continue; if (stack == null || stack.getType() == Material.AIR || stack.getAmount() == 0) continue;
world.dropItemNaturally(entity.getLocation(), stack); world.dropItem(entity.getLocation(), stack);
} }
return event; return event;
@ -464,7 +464,7 @@ public class CraftEventFactory {
for (org.bukkit.inventory.ItemStack stack : event.getDrops()) { for (org.bukkit.inventory.ItemStack stack : event.getDrops()) {
if (stack == null || stack.getType() == Material.AIR) continue; if (stack == null || stack.getType() == Material.AIR) continue;
world.dropItemNaturally(entity.getLocation(), stack); world.dropItem(entity.getLocation(), stack);
} }
return event; return event;