mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-24 09:11:26 +01:00
#1079: Add support checking/survivability methods for BlockData
By: Parker Hawke <hawkeboyz2@hotmail.com>
This commit is contained in:
parent
2f0d31aa17
commit
86d63605da
@ -0,0 +1,28 @@
|
|||||||
|
package org.bukkit.craftbukkit.block;
|
||||||
|
|
||||||
|
import net.minecraft.world.level.block.EnumBlockSupport;
|
||||||
|
import org.bukkit.block.BlockSupport;
|
||||||
|
|
||||||
|
public final class CraftBlockSupport {
|
||||||
|
|
||||||
|
private CraftBlockSupport() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BlockSupport toBukkit(EnumBlockSupport support) {
|
||||||
|
return switch (support) {
|
||||||
|
case FULL -> BlockSupport.FULL;
|
||||||
|
case CENTER -> BlockSupport.CENTER;
|
||||||
|
case RIGID -> BlockSupport.RIGID;
|
||||||
|
default -> throw new IllegalArgumentException("Unsupported EnumBlockSupport type: " + support + ". This is a bug.");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static EnumBlockSupport toNMS(BlockSupport support) {
|
||||||
|
return switch (support) {
|
||||||
|
case FULL -> EnumBlockSupport.FULL;
|
||||||
|
case CENTER -> EnumBlockSupport.CENTER;
|
||||||
|
case RIGID -> EnumBlockSupport.RIGID;
|
||||||
|
default -> throw new IllegalArgumentException("Unsupported BlockSupport type: " + support + ". This is a bug.");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -10,10 +10,12 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import net.minecraft.commands.arguments.blocks.ArgumentBlock;
|
import net.minecraft.commands.arguments.blocks.ArgumentBlock;
|
||||||
|
import net.minecraft.core.BlockPosition;
|
||||||
import net.minecraft.core.EnumDirection;
|
import net.minecraft.core.EnumDirection;
|
||||||
import net.minecraft.core.IRegistry;
|
import net.minecraft.core.IRegistry;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.INamable;
|
import net.minecraft.util.INamable;
|
||||||
|
import net.minecraft.world.level.BlockAccessAir;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.state.IBlockData;
|
import net.minecraft.world.level.block.state.IBlockData;
|
||||||
import net.minecraft.world.level.block.state.IBlockDataHolder;
|
import net.minecraft.world.level.block.state.IBlockDataHolder;
|
||||||
@ -21,12 +23,16 @@ import net.minecraft.world.level.block.state.properties.BlockStateBoolean;
|
|||||||
import net.minecraft.world.level.block.state.properties.BlockStateEnum;
|
import net.minecraft.world.level.block.state.properties.BlockStateEnum;
|
||||||
import net.minecraft.world.level.block.state.properties.BlockStateInteger;
|
import net.minecraft.world.level.block.state.properties.BlockStateInteger;
|
||||||
import net.minecraft.world.level.block.state.properties.IBlockState;
|
import net.minecraft.world.level.block.state.properties.IBlockState;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.SoundGroup;
|
import org.bukkit.SoundGroup;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
|
import org.bukkit.block.BlockSupport;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.craftbukkit.CraftSoundGroup;
|
import org.bukkit.craftbukkit.CraftSoundGroup;
|
||||||
|
import org.bukkit.craftbukkit.CraftWorld;
|
||||||
import org.bukkit.craftbukkit.block.CraftBlock;
|
import org.bukkit.craftbukkit.block.CraftBlock;
|
||||||
|
import org.bukkit.craftbukkit.block.CraftBlockSupport;
|
||||||
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||||
|
|
||||||
public class CraftBlockData implements BlockData {
|
public class CraftBlockData implements BlockData {
|
||||||
@ -541,4 +547,31 @@ public class CraftBlockData implements BlockData {
|
|||||||
public SoundGroup getSoundGroup() {
|
public SoundGroup getSoundGroup() {
|
||||||
return CraftSoundGroup.getSoundGroup(state.getSoundType());
|
return CraftSoundGroup.getSoundGroup(state.getSoundType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSupported(org.bukkit.block.Block block) {
|
||||||
|
Preconditions.checkArgument(block != null, "block must not be null");
|
||||||
|
|
||||||
|
CraftBlock craftBlock = (CraftBlock) block;
|
||||||
|
return state.canSurvive(craftBlock.getCraftWorld().getHandle(), craftBlock.getPosition());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSupported(Location location) {
|
||||||
|
Preconditions.checkArgument(location != null, "location must not be null");
|
||||||
|
|
||||||
|
CraftWorld world = (CraftWorld) location.getWorld();
|
||||||
|
Preconditions.checkArgument(world != null, "location must not have a null world");
|
||||||
|
|
||||||
|
BlockPosition position = new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||||
|
return state.canSurvive(world.getHandle(), position);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isFaceSturdy(BlockFace face, BlockSupport support) {
|
||||||
|
Preconditions.checkArgument(face != null, "face must not be null");
|
||||||
|
Preconditions.checkArgument(support != null, "support must not be null");
|
||||||
|
|
||||||
|
return state.isFaceSturdy(BlockAccessAir.INSTANCE, BlockPosition.ZERO, CraftBlock.blockFaceToNotch(face), CraftBlockSupport.toNMS(support));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user