| 1 | package net.minecraft.world.level.block;
|
| 2 |
|
| 3 | import net.minecraft.core.BlockPos;
|
| 4 | import net.minecraft.core.Direction;
|
| 5 | import net.minecraft.network.chat.Component;
|
| 6 | import net.minecraft.stats.Stats;
|
| 7 | import net.minecraft.world.InteractionResult;
|
| 8 | import net.minecraft.world.MenuProvider;
|
| 9 | import net.minecraft.world.SimpleMenuProvider;
|
| 10 | import net.minecraft.world.entity.player.Player;
|
| 11 | import net.minecraft.world.inventory.ContainerLevelAccess;
|
| 12 | import net.minecraft.world.inventory.StonecutterMenu;
|
| 13 | import net.minecraft.world.item.context.BlockPlaceContext;
|
| 14 | import net.minecraft.world.level.BlockGetter;
|
| 15 | import net.minecraft.world.level.Level;
|
| 16 | import net.minecraft.world.level.block.state.BlockBehaviour;
|
| 17 | import net.minecraft.world.level.block.state.BlockState;
|
| 18 | import net.minecraft.world.level.block.state.StateDefinition;
|
| 19 | import net.minecraft.world.level.block.state.properties.EnumProperty;
|
| 20 | import net.minecraft.world.level.pathfinder.PathComputationType;
|
| 21 | import net.minecraft.world.phys.BlockHitResult;
|
| 22 | import net.minecraft.world.phys.shapes.CollisionContext;
|
| 23 | import net.minecraft.world.phys.shapes.VoxelShape;
|
| 24 | import org.jspecify.annotations.Nullable;
|
| 25 |
|
| 26 | public class StonecutterBlock extends Block {
|
| 27 | private static final Component CONTAINER_TITLE = Component.translatable("container.stonecutter");
|
| 28 | public static final EnumProperty<Direction> FACING = HorizontalDirectionalBlock.FACING;
|
| 29 | private static final VoxelShape SHAPE = Block.column(16.0, 0.0, 9.0);
|
| 30 |
|
| 31 | public StonecutterBlock(final BlockBehaviour.Properties properties) {
|
| 32 | super(properties);
|
| 33 | this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH));
|
| 34 | }
|
| 35 |
|
| 36 | @Override
|
| 37 | public BlockState getStateForPlacement(final BlockPlaceContext context) {
|
| 38 | return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite());
|
| 39 | }
|
| 40 |
|
| 41 | @Override
|
| 42 | protected InteractionResult useWithoutItem(final BlockState state, final Level level, final BlockPos pos, final Player player, final BlockHitResult hitResult) {
|
| 43 | if (!level.isClientSide()) {
|
| 44 | player.openMenu(state.getMenuProvider(level, pos));
|
| 45 | player.awardStat(Stats.INTERACT_WITH_STONECUTTER);
|
| 46 | }
|
| 47 |
|
| 48 | return InteractionResult.SUCCESS;
|
| 49 | }
|
| 50 |
|
| 51 | @Override
|
| 52 | protected @Nullable MenuProvider getMenuProvider(final BlockState state, final Level level, final BlockPos pos) {
|
| 53 | return new SimpleMenuProvider(
|
| 54 | (containerId, inventory, player) -> new StonecutterMenu(containerId, inventory, ContainerLevelAccess.create(level, pos)), CONTAINER_TITLE
|
| 55 | );
|
| 56 | }
|
| 57 |
|
| 58 | @Override
|
| 59 | protected VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
|
| 60 | return SHAPE;
|
| 61 | }
|
| 62 |
|
| 63 | @Override
|
| 64 | protected boolean useShapeForLightOcclusion(final BlockState state) {
|
| 65 | return true;
|
| 66 | }
|
| 67 |
|
| 68 | @Override
|
| 69 | protected BlockState rotate(final BlockState state, final Rotation rotation) {
|
| 70 | return state.setValue(FACING, rotation.rotate(state.getValue(FACING)));
|
| 71 | }
|
| 72 |
|
| 73 | @Override
|
| 74 | protected BlockState mirror(final BlockState state, final Mirror mirror) {
|
| 75 | return state.rotate(mirror.getRotation(state.getValue(FACING)));
|
| 76 | }
|
| 77 |
|
| 78 | @Override
|
| 79 | protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) {
|
| 80 | builder.add(FACING);
|
| 81 | }
|
| 82 |
|
| 83 | @Override
|
| 84 | protected boolean isPathfindable(final BlockState state, final PathComputationType type) {
|
| 85 | return false;
|
| 86 | }
|
| 87 | }
|
| 88 |
|