Advertisement
Xander402

ChoppingBoard.java

Dec 19th, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.91 KB | None | 0 0
  1. package ...
  2.  
  3. import ...
  4.  
  5. public class ChoppingBoard extends HorizontalBlock {
  6.  
  7.     private static final ITextComponent TEXT_COMPONENT = ...;
  8.     private static DirectionProperty FACING = HorizontalBlock.HORIZONTAL_FACING;
  9.  
  10.     public ChoppingBoard(Properties properties) {
  11.         super(properties);
  12.         this.setDefaultState(this.stateContainer.getBaseState().with(HORIZONTAL_FACING, Direction.NORTH));
  13.     }
  14.  
  15.     @Override
  16.     public VoxelShape getShape(BlockState state, IBlockReader world, BlockPos pos, ISelectionContext context) {
  17.         switch (state.get(HORIZONTAL_FACING)) {
  18.             case WEST:
  19.             case EAST:
  20.                 return Block.makeCuboidShape(4.0D, 0.0D, 1.0D,
  21.                         12.0D, 1.0D, 15.0D);
  22.             default:
  23.                 return Block.makeCuboidShape(1.0D, 0.0D, 4.0D,
  24.                         15.0D, 1.0D, 12.0D);
  25.         }
  26.     }
  27.  
  28.     @Override
  29.     public BlockState getStateForPlacement(BlockItemUseContext context) {
  30.         return this.getDefaultState().with(FACING, context.getPlacementHorizontalFacing());
  31.     }
  32.  
  33.     @Override
  34.     protected void fillStateContainer(StateContainer.Builder<Block, BlockState> p_206840_1_) {
  35.         p_206840_1_.add(FACING);
  36.     }
  37.  
  38.     @Override
  39.     public BlockRenderType getRenderType(BlockState state) {
  40.         return BlockRenderType.MODEL;
  41.     }
  42.  
  43.     @Override
  44.     public boolean onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult result) {
  45.         player.openContainer(state.getContainer(world, pos));
  46.         return true;
  47.     }
  48.  
  49.     @Override
  50.     public INamedContainerProvider getContainer(BlockState state, World world, BlockPos pos) {
  51.         return new SimpleNamedContainerProvider((i, playerInventory, playerEntity)
  52.                 -> new ChoppingBoardContainer(playerInventory, IWorldPosCallable.of(world, pos)), TEXT_COMPONENT);
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement