| 1 | package net.minecraft.world.level.block;
|
| 2 |
|
| 3 | import com.mojang.math.OctahedralGroup;
|
| 4 | import java.util.Map;
|
| 5 | import java.util.function.Function;
|
| 6 | import net.minecraft.core.BlockPos;
|
| 7 | import net.minecraft.core.Direction;
|
| 8 | import net.minecraft.network.chat.Component;
|
| 9 | import net.minecraft.stats.Stats;
|
| 10 | import net.minecraft.world.InteractionResult;
|
| 11 | import net.minecraft.world.MenuProvider;
|
| 12 | import net.minecraft.world.SimpleMenuProvider;
|
| 13 | import net.minecraft.world.entity.player.Player;
|
| 14 | import net.minecraft.world.inventory.ContainerLevelAccess;
|
| 15 | import net.minecraft.world.inventory.GrindstoneMenu;
|
| 16 | import net.minecraft.world.level.BlockGetter;
|
| 17 | import net.minecraft.world.level.Level;
|
| 18 | import net.minecraft.world.level.LevelReader;
|
| 19 | import net.minecraft.world.level.block.state.BlockBehaviour;
|
| 20 | import net.minecraft.world.level.block.state.BlockState;
|
| 21 | import net.minecraft.world.level.block.state.StateDefinition;
|
| 22 | import net.minecraft.world.level.block.state.properties.AttachFace;
|
| 23 | import net.minecraft.world.level.pathfinder.PathComputationType;
|
| 24 | import net.minecraft.world.phys.BlockHitResult;
|
| 25 | import net.minecraft.world.phys.shapes.CollisionContext;
|
| 26 | import net.minecraft.world.phys.shapes.Shapes;
|
| 27 | import net.minecraft.world.phys.shapes.VoxelShape;
|
| 28 |
|
| 29 | /**
|
| 30 | * Access widened by fabric-transitive-access-wideners-v1 to accessible
|
| 31 | */
|
| 32 | public class GrindstoneBlock extends FaceAttachedHorizontalDirectionalBlock {
|
| 33 | private static final Component CONTAINER_TITLE = Component.translatable("container.grindstone_title");
|
| 34 | private final Function<BlockState, VoxelShape> shapes;
|
| 35 |
|
| 36 | /**
|
| 37 | * Access widened by fabric-transitive-access-wideners-v1 to accessible
|
| 38 | */
|
| 39 | public GrindstoneBlock(final BlockBehaviour.Properties properties) {
|
| 40 | super(properties);
|
| 41 | this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(FACE, AttachFace.WALL));
|
| 42 | this.shapes = this.makeShapes();
|
| 43 | }
|
| 44 |
|
| 45 | private Function<BlockState, VoxelShape> makeShapes() {
|
| 46 | VoxelShape leftLegs = Shapes.or(Block.box(2.0, 6.0, 7.0, 4.0, 10.0, 16.0), Block.box(2.0, 5.0, 3.0, 4.0, 11.0, 9.0));
|
| 47 | VoxelShape rightLegs = Shapes.rotate(leftLegs, OctahedralGroup.INVERT_X);
|
| 48 | VoxelShape north = Shapes.or(Block.boxZ(8.0, 2.0, 14.0, 0.0, 12.0), leftLegs, rightLegs);
|
| 49 | Map<AttachFace, Map<Direction, VoxelShape>> attachFace = Shapes.rotateAttachFace(north);
|
| 50 | return this.getShapeForEachState(state -> attachFace.get(state.getValue(FACE)).get(state.getValue(FACING)));
|
| 51 | }
|
| 52 |
|
| 53 | private VoxelShape getVoxelShape(final BlockState state) {
|
| 54 | return this.shapes.apply(state);
|
| 55 | }
|
| 56 |
|
| 57 | @Override
|
| 58 | protected VoxelShape getCollisionShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
|
| 59 | return this.getVoxelShape(state);
|
| 60 | }
|
| 61 |
|
| 62 | @Override
|
| 63 | protected VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
|
| 64 | return this.getVoxelShape(state);
|
| 65 | }
|
| 66 |
|
| 67 | @Override
|
| 68 | protected boolean canSurvive(final BlockState state, final LevelReader level, final BlockPos pos) {
|
| 69 | return true;
|
| 70 | }
|
| 71 |
|
| 72 | @Override
|
| 73 | protected InteractionResult useWithoutItem(final BlockState state, final Level level, final BlockPos pos, final Player player, final BlockHitResult hitResult) {
|
| 74 | if (!level.isClientSide()) {
|
| 75 | player.openMenu(state.getMenuProvider(level, pos));
|
| 76 | player.awardStat(Stats.INTERACT_WITH_GRINDSTONE);
|
| 77 | }
|
| 78 |
|
| 79 | return InteractionResult.SUCCESS;
|
| 80 | }
|
| 81 |
|
| 82 | @Override
|
| 83 | protected MenuProvider getMenuProvider(final BlockState state, final Level level, final BlockPos pos) {
|
| 84 | return new SimpleMenuProvider(
|
| 85 | (containerId, inventory, player) -> new GrindstoneMenu(containerId, inventory, ContainerLevelAccess.create(level, pos)), CONTAINER_TITLE
|
| 86 | );
|
| 87 | }
|
| 88 |
|
| 89 | @Override
|
| 90 | protected BlockState rotate(final BlockState state, final Rotation rotation) {
|
| 91 | return state.setValue(FACING, rotation.rotate(state.getValue(FACING)));
|
| 92 | }
|
| 93 |
|
| 94 | @Override
|
| 95 | protected BlockState mirror(final BlockState state, final Mirror mirror) {
|
| 96 | return state.rotate(mirror.getRotation(state.getValue(FACING)));
|
| 97 | }
|
| 98 |
|
| 99 | @Override
|
| 100 | protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) {
|
| 101 | builder.add(FACING, FACE);
|
| 102 | }
|
| 103 |
|
| 104 | @Override
|
| 105 | protected boolean isPathfindable(final BlockState state, final PathComputationType type) {
|
| 106 | return false;
|
| 107 | }
|
| 108 | }
|
| 109 |
|