Advertisement
Jamesthe1

Chest Orientation Code

Sep 18th, 2020 (edited)
1,139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.99 KB | None | 0 0
  1.     public IBlockState getStateForPlacement (World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
  2.         return this.getDefaultState ().withProperty (FACING, placer.getHorizontalFacing ());
  3.     }
  4.  
  5.     public IBlockState correctFacing (World worldIn, BlockPos pos, IBlockState state) {
  6.         EnumFacing enumfacing = null;
  7.  
  8.         for (EnumFacing enumfacing1 : EnumFacing.Plane.HORIZONTAL) {
  9.             IBlockState iblockstate = worldIn.getBlockState (pos.offset (enumfacing1));
  10.  
  11.             if (iblockstate.getBlock () == this)
  12.                 return state;
  13.  
  14.             if (iblockstate.isFullBlock ()) {
  15.                 if (enumfacing != null) {
  16.                     enumfacing = null;
  17.                     break;
  18.                 }
  19.  
  20.                 enumfacing = enumfacing1;
  21.             }
  22.         }
  23.  
  24.         if (enumfacing != null)
  25.             return state.withProperty (FACING, enumfacing.getOpposite ());
  26.         else {
  27.             EnumFacing enumfacing2 = (EnumFacing)state.getValue (FACING);
  28.  
  29.             if (worldIn.getBlockState (pos.offset (enumfacing2)).isFullBlock ())
  30.                 enumfacing2 = enumfacing2.getOpposite ();
  31.  
  32.             if (worldIn.getBlockState (pos.offset (enumfacing2)).isFullBlock ())
  33.                 enumfacing2 = enumfacing2.rotateY ();
  34.  
  35.             if (worldIn.getBlockState (pos.offset (enumfacing2)).isFullBlock ())
  36.                 enumfacing2 = enumfacing2.getOpposite ();
  37.  
  38.             return state.withProperty (FACING, enumfacing2);
  39.         }
  40.     }
  41.  
  42.     public IBlockState getStateFromMeta (int meta) {
  43.         EnumFacing enumfacing = EnumFacing.byIndex (meta);
  44.  
  45.         if (enumfacing.getAxis () == EnumFacing.Axis.Y)
  46.             enumfacing = EnumFacing.NORTH;
  47.  
  48.         return this.getDefaultState ().withProperty (FACING, enumfacing);
  49.     }
  50.    
  51.     public int getMetaFromState (IBlockState state) {
  52.         return ((EnumFacing)state.getValue (FACING)).getIndex ();
  53.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement