tigres810

Untitled

Mar 1st, 2019
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.82 KB | None | 0 0
  1. //On block added
  2. @Override
  3. public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
  4. if(!worldIn.isRemote) {
  5. IBlockState north = worldIn.getBlockState(pos.north());
  6. IBlockState south = worldIn.getBlockState(pos.south());
  7. IBlockState west = worldIn.getBlockState(pos.west());
  8. IBlockState east = worldIn.getBlockState(pos.east());
  9. EnumFacing face = (EnumFacing)state.getValue(FACING);
  10.  
  11. if (face == EnumFacing.NORTH && north.isFullBlock() && !south.isFullBlock()) face = EnumFacing.SOUTH;
  12. else if (face == EnumFacing.SOUTH && south.isFullBlock() && !north.isFullBlock()) face = EnumFacing.NORTH;
  13. else if (face == EnumFacing.WEST && west.isFullBlock() && !east.isFullBlock()) face = EnumFacing.EAST;
  14. else if (face == EnumFacing.EAST && east.isFullBlock() && !west.isFullBlock()) face = EnumFacing.WEST;
  15. boolean bool = false;
  16. if(face.equals(EnumFacing.NORTH)) {
  17. if(worldIn.isAirBlock(pos.offset(EnumFacing.EAST))) {
  18. bool = true;
  19. }
  20. } else if(face.equals(EnumFacing.SOUTH)) {
  21. if(worldIn.isAirBlock(pos.offset(EnumFacing.EAST.getOpposite()))) {
  22. bool = true;
  23. }
  24. } else if(face.equals(EnumFacing.EAST)) {
  25. if(worldIn.isAirBlock(pos.offset(EnumFacing.SOUTH))) {
  26. bool = true;
  27. }
  28. } else if (face.equals(EnumFacing.WEST)) {
  29. if(worldIn.isAirBlock(pos.offset(EnumFacing.SOUTH.getOpposite()))) {
  30. bool = true;
  31. }
  32. }
  33.  
  34. if(bool == true) {
  35. worldIn.setBlockState(pos, state.withProperty(FACING, face), 2);
  36. if(face.equals(EnumFacing.NORTH)) {
  37. BlockFluxCrafterLeftSide.setBlock(worldIn, pos.offset(EnumFacing.EAST), face);
  38. } else if(face.equals(EnumFacing.SOUTH)) {
  39. BlockFluxCrafterLeftSide.setBlock(worldIn, pos.offset(EnumFacing.EAST.getOpposite()), face);
  40. } else if(face.equals(EnumFacing.EAST)) {
  41. BlockFluxCrafterLeftSide.setBlock(worldIn, pos.offset(EnumFacing.SOUTH), face);
  42. } else if (face.equals(EnumFacing.WEST)) {
  43. BlockFluxCrafterLeftSide.setBlock(worldIn, pos.offset(EnumFacing.SOUTH.getOpposite()), face);
  44. }
  45. } else {
  46. worldIn.destroyBlock(pos, true);
  47. }
  48. }
  49. }
  50.  
  51.  
  52. //Break block
  53. @Override
  54. public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
  55. TileEntityFluxCrafter tileentity = (TileEntityFluxCrafter)worldIn.getTileEntity(pos);
  56. worldIn.spawnEntity(new EntityItem(worldIn, pos.getX(), pos.getY(), pos.getZ(), tileentity.handler.getStackInSlot(0)));
  57. if(state.getValue(FACING).equals(EnumFacing.NORTH) && worldIn.getBlockState(pos.offset(EnumFacing.EAST)).getBlock() instanceof BlockFluxCrafterLeftSide) {
  58. worldIn.destroyBlock(pos.offset(EnumFacing.EAST), false);
  59. } else if(state.getValue(FACING).equals(EnumFacing.SOUTH) && worldIn.getBlockState(pos.offset(EnumFacing.EAST.getOpposite())).getBlock() instanceof BlockFluxCrafterLeftSide) {
  60. worldIn.destroyBlock(pos.offset(EnumFacing.EAST.getOpposite()), false);
  61. } else if(state.getValue(FACING).equals(EnumFacing.EAST) && worldIn.getBlockState(pos.offset(EnumFacing.SOUTH)).getBlock() instanceof BlockFluxCrafterLeftSide) {
  62. worldIn.destroyBlock(pos.offset(EnumFacing.SOUTH), false);
  63. } else if (state.getValue(FACING).equals(EnumFacing.WEST) && worldIn.getBlockState(pos.offset(EnumFacing.SOUTH.getOpposite())).getBlock() instanceof BlockFluxCrafterLeftSide) {
  64. worldIn.destroyBlock(pos.offset(EnumFacing.SOUTH.getOpposite()), false);
  65. }
  66. super.breakBlock(worldIn, pos, state);
  67. }
Advertisement
Add Comment
Please, Sign In to add comment