Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
  2. {
  3. this.setDefaultFacing(worldIn, pos, state);
  4. }
  5.  
  6. private void setDefaultFacing(World worldIn, BlockPos pos, IBlockState state)
  7. {
  8. if (!worldIn.isRemote)
  9. {
  10. IBlockState iblockstate = worldIn.getBlockState(pos.north());
  11. IBlockState iblockstate1 = worldIn.getBlockState(pos.south());
  12. IBlockState iblockstate2 = worldIn.getBlockState(pos.west());
  13. IBlockState iblockstate3 = worldIn.getBlockState(pos.east());
  14. EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
  15.  
  16. if (enumfacing == EnumFacing.NORTH && iblockstate.isFullBlock() && !iblockstate1.isFullBlock())
  17. {
  18. enumfacing = EnumFacing.SOUTH;
  19. }
  20. else if (enumfacing == EnumFacing.SOUTH && iblockstate1.isFullBlock() && !iblockstate.isFullBlock())
  21. {
  22. enumfacing = EnumFacing.NORTH;
  23. }
  24. else if (enumfacing == EnumFacing.WEST && iblockstate2.isFullBlock() && !iblockstate3.isFullBlock())
  25. {
  26. enumfacing = EnumFacing.EAST;
  27. }
  28. else if (enumfacing == EnumFacing.EAST && iblockstate3.isFullBlock() && !iblockstate2.isFullBlock())
  29. {
  30. enumfacing = EnumFacing.WEST;
  31. }
  32.  
  33. worldIn.setBlockState(pos, state.withProperty(FACING, enumfacing), 2);
  34. }
  35. }
  36.  
  37. public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
  38. {
  39. return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
  40. }
  41.  
  42. public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
  43. {
  44. worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
  45. }
  46.  
  47. @Override
  48. public EnumBlockRenderType getRenderType(IBlockState state)
  49. {
  50. return EnumBlockRenderType.MODEL;
  51. }
  52.  
  53. public IBlockState getStateFromMeta(int meta)
  54. {
  55. EnumFacing enumfacing = EnumFacing.getFront(meta);
  56.  
  57. if (enumfacing.getAxis() == EnumFacing.Axis.Y)
  58. {
  59. enumfacing = EnumFacing.NORTH;
  60. }
  61.  
  62. return this.getDefaultState().withProperty(FACING, enumfacing);
  63. }
  64.  
  65. public int getMetaFromState(IBlockState state)
  66. {
  67. return ((EnumFacing)state.getValue(FACING)).getIndex();
  68. }
  69.  
  70. public IBlockState withRotation(IBlockState state, Rotation rot)
  71. {
  72. return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
  73. }
  74.  
  75. public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
  76. {
  77. return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement