geforkt von Mirrors/Paper
#810: Add option for a consumer before spawning an item
By: Martoph <sager1018@gmail.com>
Dieser Commit ist enthalten in:
Ursprung
11d6de6800
Commit
52fe52d83d
@ -596,15 +596,28 @@ public class CraftWorld implements World {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public org.bukkit.entity.Item dropItem(Location loc, ItemStack item) {
|
public org.bukkit.entity.Item dropItem(Location loc, ItemStack item) {
|
||||||
|
return dropItem(loc, item, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public org.bukkit.entity.Item dropItem(Location loc, ItemStack item, Consumer<org.bukkit.entity.Item> function) {
|
||||||
Validate.notNull(item, "Cannot drop a Null item.");
|
Validate.notNull(item, "Cannot drop a Null item.");
|
||||||
EntityItem entity = new EntityItem(world, loc.getX(), loc.getY(), loc.getZ(), CraftItemStack.asNMSCopy(item));
|
EntityItem entity = new EntityItem(world, loc.getX(), loc.getY(), loc.getZ(), CraftItemStack.asNMSCopy(item));
|
||||||
entity.pickupDelay = 10;
|
entity.pickupDelay = 10;
|
||||||
|
if (function != null) {
|
||||||
|
function.accept((org.bukkit.entity.Item) entity.getBukkitEntity());
|
||||||
|
}
|
||||||
world.addEntity(entity, SpawnReason.CUSTOM);
|
world.addEntity(entity, SpawnReason.CUSTOM);
|
||||||
return (org.bukkit.entity.Item) entity.getBukkitEntity();
|
return (org.bukkit.entity.Item) entity.getBukkitEntity();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public org.bukkit.entity.Item dropItemNaturally(Location loc, ItemStack item) {
|
public org.bukkit.entity.Item dropItemNaturally(Location loc, ItemStack item) {
|
||||||
|
return dropItemNaturally(loc, item, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public org.bukkit.entity.Item dropItemNaturally(Location loc, ItemStack item, Consumer<org.bukkit.entity.Item> function) {
|
||||||
double xs = (world.random.nextFloat() * 0.5F) + 0.25D;
|
double xs = (world.random.nextFloat() * 0.5F) + 0.25D;
|
||||||
double ys = (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;
|
double zs = (world.random.nextFloat() * 0.5F) + 0.25D;
|
||||||
@ -612,7 +625,7 @@ public class CraftWorld implements World {
|
|||||||
loc.setX(loc.getX() + xs);
|
loc.setX(loc.getX() + xs);
|
||||||
loc.setY(loc.getY() + ys);
|
loc.setY(loc.getY() + ys);
|
||||||
loc.setZ(loc.getZ() + zs);
|
loc.setZ(loc.getZ() + zs);
|
||||||
return dropItem(loc, item);
|
return dropItem(loc, item, function);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren