#823: Add Block#isPreferredTool

By: Flo0 <unconfigured@null.spigotmc.org>
This commit is contained in:
CraftBukkit/Spigot 2021-04-21 17:31:47 +10:00
parent 1eb2ceea36
commit d6327a1b65

View file

@ -658,7 +658,7 @@ public class CraftBlock implements Block {
net.minecraft.world.item.ItemStack nms = CraftItemStack.asNMSCopy(item);
// Modelled off EntityHuman#hasBlock
if (item == null || !iblockdata.isRequiresSpecialTool() || nms.canDestroySpecialBlock(iblockdata)) {
if (item == null || isPreferredTool(iblockdata, nms)) {
return net.minecraft.world.level.block.Block.getDrops(iblockdata, (WorldServer) world.getMinecraftWorld(), position, world.getTileEntity(position), entity == null ? null : ((CraftEntity) entity).getHandle(), nms)
.stream().map(CraftItemStack::asBukkitCopy).collect(Collectors.toList());
} else {
@ -666,6 +666,17 @@ public class CraftBlock implements Block {
}
}
@Override
public boolean isPreferredTool(ItemStack item) {
IBlockData iblockdata = getNMS();
net.minecraft.world.item.ItemStack nms = CraftItemStack.asNMSCopy(item);
return isPreferredTool(iblockdata, nms);
}
private boolean isPreferredTool(IBlockData iblockdata, net.minecraft.world.item.ItemStack nmsItem) {
return !iblockdata.isRequiresSpecialTool() || nmsItem.canDestroySpecialBlock(iblockdata);
}
@Override
public void setMetadata(String metadataKey, MetadataValue newMetadataValue) {
getCraftWorld().getBlockMetadata().setMetadata(this, metadataKey, newMetadataValue);