| 1 | package net.minecraft.world.level.block;
|
| 2 |
|
| 3 | import com.mojang.serialization.Codec;
|
| 4 | import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap;
|
| 5 | import java.util.Map;
|
| 6 | import net.minecraft.core.BlockPos;
|
| 7 | import net.minecraft.util.StringRepresentable;
|
| 8 | import net.minecraft.world.item.context.BlockPlaceContext;
|
| 9 | import net.minecraft.world.level.BlockGetter;
|
| 10 | import net.minecraft.world.level.block.state.BlockBehaviour;
|
| 11 | import net.minecraft.world.level.block.state.BlockState;
|
| 12 | import net.minecraft.world.level.block.state.StateDefinition;
|
| 13 | import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
| 14 | import net.minecraft.world.level.block.state.properties.IntegerProperty;
|
| 15 | import net.minecraft.world.level.block.state.properties.RotationSegment;
|
| 16 | import net.minecraft.world.phys.shapes.CollisionContext;
|
| 17 | import net.minecraft.world.phys.shapes.VoxelShape;
|
| 18 |
|
| 19 | /**
|
| 20 | * Access widened by fabric-transitive-access-wideners-v1 to accessible
|
| 21 | */
|
| 22 | public class SkullBlock extends AbstractSkullBlock {
|
| 23 | public static final int MAX = RotationSegment.getMaxSegmentIndex();
|
| 24 | private static final int ROTATIONS = MAX + 1;
|
| 25 | public static final IntegerProperty ROTATION = BlockStateProperties.ROTATION_16;
|
| 26 | private static final VoxelShape SHAPE = Block.column(8.0, 0.0, 8.0);
|
| 27 | private static final VoxelShape SHAPE_PIGLIN = Block.column(10.0, 0.0, 8.0);
|
| 28 | private static final VoxelShape SHAPE_DRAGON_OUTLINE = Block.column(8.0, 0.0, 8.5);
|
| 29 |
|
| 30 | /**
|
| 31 | * Access widened by fabric-transitive-access-wideners-v1 to accessible
|
| 32 | */
|
| 33 | public SkullBlock(final SkullBlock.Type type, final BlockBehaviour.Properties properties) {
|
| 34 | super(type, properties);
|
| 35 | this.registerDefaultState(this.defaultBlockState().setValue(ROTATION, 0));
|
| 36 | }
|
| 37 |
|
| 38 | @Override
|
| 39 | protected VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
|
| 40 | return this.getType() == SkullBlock.Types.DRAGON ? SHAPE_DRAGON_OUTLINE : this.getCollisionShape(state, level, pos, context);
|
| 41 | }
|
| 42 |
|
| 43 | @Override
|
| 44 | protected VoxelShape getCollisionShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
|
| 45 | return this.getType() == SkullBlock.Types.PIGLIN ? SHAPE_PIGLIN : SHAPE;
|
| 46 | }
|
| 47 |
|
| 48 | @Override
|
| 49 | public BlockState getStateForPlacement(final BlockPlaceContext context) {
|
| 50 | return super.getStateForPlacement(context).setValue(ROTATION, RotationSegment.convertToSegment(context.getRotation()));
|
| 51 | }
|
| 52 |
|
| 53 | @Override
|
| 54 | protected BlockState rotate(final BlockState state, final Rotation rotation) {
|
| 55 | return state.setValue(ROTATION, rotation.rotate(state.getValue(ROTATION), ROTATIONS));
|
| 56 | }
|
| 57 |
|
| 58 | @Override
|
| 59 | protected BlockState mirror(final BlockState state, final Mirror mirror) {
|
| 60 | return state.setValue(ROTATION, mirror.mirror(state.getValue(ROTATION), ROTATIONS));
|
| 61 | }
|
| 62 |
|
| 63 | @Override
|
| 64 | protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) {
|
| 65 | super.createBlockStateDefinition(builder);
|
| 66 | builder.add(ROTATION);
|
| 67 | }
|
| 68 |
|
| 69 | public interface Type extends StringRepresentable {
|
| 70 | Map<String, SkullBlock.Type> TYPES = new Object2ObjectArrayMap<>();
|
| 71 | Codec<SkullBlock.Type> CODEC = Codec.stringResolver(StringRepresentable::getSerializedName, TYPES::get);
|
| 72 | }
|
| 73 |
|
| 74 | public enum Types implements SkullBlock.Type {
|
| 75 | SKELETON("skeleton"),
|
| 76 | WITHER_SKELETON("wither_skeleton"),
|
| 77 | PLAYER("player"),
|
| 78 | ZOMBIE("zombie"),
|
| 79 | CREEPER("creeper"),
|
| 80 | PIGLIN("piglin"),
|
| 81 | DRAGON("dragon");
|
| 82 |
|
| 83 | private final String name;
|
| 84 |
|
| 85 | Types(final String name) {
|
| 86 | this.name = name;
|
| 87 | TYPES.put(name, this);
|
| 88 | }
|
| 89 |
|
| 90 | @Override
|
| 91 | public String getSerializedName() {
|
| 92 | return this.name;
|
| 93 | }
|
| 94 | }
|
| 95 | }
|
| 96 |
|