SPIGOT-4569: Implement more BlockData API

By: Parker Hawke <hawkeboyz2@hotmail.com>
This commit is contained in:
CraftBukkit/Spigot 2023-02-11 18:59:34 +11:00
parent abeb7e6d0c
commit 000270a286
2 changed files with 37 additions and 6 deletions

View File

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

View File

@ -28,12 +28,15 @@ import org.bukkit.Material;
import org.bukkit.SoundGroup;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockSupport;
import org.bukkit.block.PistonMoveReaction;
import org.bukkit.block.data.BlockData;
import org.bukkit.craftbukkit.CraftSoundGroup;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.block.CraftBlock;
import org.bukkit.craftbukkit.block.CraftBlockSupport;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.inventory.ItemStack;
public class CraftBlockData implements BlockData {
@ -551,6 +554,38 @@ public class CraftBlockData implements BlockData {
return CraftSoundGroup.getSoundGroup(state.getSoundType());
}
@Override
public int getLightEmission() {
return state.getLightEmission();
}
@Override
public boolean isOccluding() {
return state.canOcclude();
}
@Override
public boolean requiresCorrectToolForDrops() {
return state.requiresCorrectToolForDrops();
}
@Override
public boolean isPreferredTool(ItemStack tool) {
Preconditions.checkArgument(tool != null, "tool must not be null");
net.minecraft.world.item.ItemStack nms = CraftItemStack.asNMSCopy(tool);
return isPreferredTool(state, nms);
}
public static boolean isPreferredTool(IBlockData iblockdata, net.minecraft.world.item.ItemStack nmsItem) {
return !iblockdata.requiresCorrectToolForDrops() || nmsItem.isCorrectToolForDrops(iblockdata);
}
@Override
public PistonMoveReaction getPistonMoveReaction() {
return PistonMoveReaction.getById(state.getPistonPushReaction().ordinal());
}
@Override
public boolean isSupported(org.bukkit.block.Block block) {
Preconditions.checkArgument(block != null, "block must not be null");