Add getDrops to BlockState

Originally added isPreferredTool to BlockData but
upstream added that.
This commit is contained in:
MelnCat 2022-08-12 23:24:37 -07:00
parent 074f19e7fb
commit 492ebf1459

View file

@ -347,5 +347,24 @@ public class CraftBlockState implements BlockState {
public boolean isCollidable() {
return this.data.getBlock().hasCollision;
}
@Override
public java.util.Collection<org.bukkit.inventory.ItemStack> getDrops(org.bukkit.inventory.ItemStack item, org.bukkit.entity.Entity entity) {
this.requirePlaced();
net.minecraft.world.item.ItemStack nms = org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(item);
// Modelled off EntityHuman#hasBlock
if (item == null || !data.requiresCorrectToolForDrops() || nms.isCorrectToolForDrops(data)) {
return net.minecraft.world.level.block.Block.getDrops(
data,
world.getHandle(),
position,
world.getHandle().getBlockEntity(position), entity == null ? null :
((org.bukkit.craftbukkit.entity.CraftEntity) entity).getHandle(), nms
).stream().map(org.bukkit.craftbukkit.inventory.CraftItemStack::asBukkitCopy).toList();
} else {
return java.util.Collections.emptyList();
}
}
// Paper end
}