package net.minecraft.world.level.block; import com.mojang.serialization.Codec; import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap; import java.util.Map; import net.minecraft.core.BlockPos; import net.minecraft.util.StringRepresentable; import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.block.state.properties.IntegerProperty; import net.minecraft.world.level.block.state.properties.RotationSegment; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; /** * Access widened by fabric-transitive-access-wideners-v1 to accessible */ public class SkullBlock extends AbstractSkullBlock { public static final MapCodec CODEC = RecordCodecBuilder.mapCodec( i -> i.group(SkullBlock.Type.CODEC.fieldOf("kind").forGetter(AbstractSkullBlock::getType), propertiesCodec()).apply(i, SkullBlock::new) ); public static final int MAX = RotationSegment.getMaxSegmentIndex(); private static final int ROTATIONS = MAX + 1; public static final IntegerProperty ROTATION = BlockStateProperties.ROTATION_16; private static final VoxelShape SHAPE = Block.column(8.0, 0.0, 8.0); private static final VoxelShape SHAPE_PIGLIN = Block.column(10.0, 0.0, 8.0); @Override public MapCodec codec() { return CODEC; } /** * Access widened by fabric-transitive-access-wideners-v1 to accessible */ public SkullBlock(final SkullBlock.Type type, final BlockBehaviour.Properties properties) { super(type, properties); this.registerDefaultState(this.defaultBlockState().setValue(ROTATION, 0)); } @Override protected VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) { return this.getType() == SkullBlock.Types.PIGLIN ? SHAPE_PIGLIN : SHAPE; } @Override public BlockState getStateForPlacement(final BlockPlaceContext context) { return super.getStateForPlacement(context).setValue(ROTATION, RotationSegment.convertToSegment(context.getRotation())); } @Override protected BlockState rotate(final BlockState state, final Rotation rotation) { return state.setValue(ROTATION, rotation.rotate((Integer)state.getValue(ROTATION), ROTATIONS)); } @Override protected BlockState mirror(final BlockState state, final Mirror mirror) { return state.setValue(ROTATION, mirror.mirror((Integer)state.getValue(ROTATION), ROTATIONS)); } @Override protected void createBlockStateDefinition(final StateDefinition.Builder builder) { super.createBlockStateDefinition(builder); builder.add(ROTATION); } public interface Type extends StringRepresentable { Map TYPES = new Object2ObjectArrayMap<>(); Codec CODEC = Codec.stringResolver(StringRepresentable::getSerializedName, TYPES::get); } public static enum Types implements SkullBlock.Type { SKELETON("skeleton"), WITHER_SKELETON("wither_skeleton"), PLAYER("player"), ZOMBIE("zombie"), CREEPER("creeper"), PIGLIN("piglin"), DRAGON("dragon"); private final String name; private Types(final String name) { this.name = name; TYPES.put(name, this); } @Override public String getSerializedName() { return this.name; } } }