Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //On block added
- @Override
- public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
- if(!worldIn.isRemote) {
- IBlockState north = worldIn.getBlockState(pos.north());
- IBlockState south = worldIn.getBlockState(pos.south());
- IBlockState west = worldIn.getBlockState(pos.west());
- IBlockState east = worldIn.getBlockState(pos.east());
- EnumFacing face = (EnumFacing)state.getValue(FACING);
- if (face == EnumFacing.NORTH && north.isFullBlock() && !south.isFullBlock()) face = EnumFacing.SOUTH;
- else if (face == EnumFacing.SOUTH && south.isFullBlock() && !north.isFullBlock()) face = EnumFacing.NORTH;
- else if (face == EnumFacing.WEST && west.isFullBlock() && !east.isFullBlock()) face = EnumFacing.EAST;
- else if (face == EnumFacing.EAST && east.isFullBlock() && !west.isFullBlock()) face = EnumFacing.WEST;
- boolean bool = false;
- if(face.equals(EnumFacing.NORTH)) {
- if(worldIn.isAirBlock(pos.offset(EnumFacing.EAST))) {
- bool = true;
- }
- } else if(face.equals(EnumFacing.SOUTH)) {
- if(worldIn.isAirBlock(pos.offset(EnumFacing.EAST.getOpposite()))) {
- bool = true;
- }
- } else if(face.equals(EnumFacing.EAST)) {
- if(worldIn.isAirBlock(pos.offset(EnumFacing.SOUTH))) {
- bool = true;
- }
- } else if (face.equals(EnumFacing.WEST)) {
- if(worldIn.isAirBlock(pos.offset(EnumFacing.SOUTH.getOpposite()))) {
- bool = true;
- }
- }
- if(bool == true) {
- worldIn.setBlockState(pos, state.withProperty(FACING, face), 2);
- if(face.equals(EnumFacing.NORTH)) {
- BlockFluxCrafterLeftSide.setBlock(worldIn, pos.offset(EnumFacing.EAST), face);
- } else if(face.equals(EnumFacing.SOUTH)) {
- BlockFluxCrafterLeftSide.setBlock(worldIn, pos.offset(EnumFacing.EAST.getOpposite()), face);
- } else if(face.equals(EnumFacing.EAST)) {
- BlockFluxCrafterLeftSide.setBlock(worldIn, pos.offset(EnumFacing.SOUTH), face);
- } else if (face.equals(EnumFacing.WEST)) {
- BlockFluxCrafterLeftSide.setBlock(worldIn, pos.offset(EnumFacing.SOUTH.getOpposite()), face);
- }
- } else {
- worldIn.destroyBlock(pos, true);
- }
- }
- }
- //Break block
- @Override
- public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
- TileEntityFluxCrafter tileentity = (TileEntityFluxCrafter)worldIn.getTileEntity(pos);
- worldIn.spawnEntity(new EntityItem(worldIn, pos.getX(), pos.getY(), pos.getZ(), tileentity.handler.getStackInSlot(0)));
- if(state.getValue(FACING).equals(EnumFacing.NORTH) && worldIn.getBlockState(pos.offset(EnumFacing.EAST)).getBlock() instanceof BlockFluxCrafterLeftSide) {
- worldIn.destroyBlock(pos.offset(EnumFacing.EAST), false);
- } else if(state.getValue(FACING).equals(EnumFacing.SOUTH) && worldIn.getBlockState(pos.offset(EnumFacing.EAST.getOpposite())).getBlock() instanceof BlockFluxCrafterLeftSide) {
- worldIn.destroyBlock(pos.offset(EnumFacing.EAST.getOpposite()), false);
- } else if(state.getValue(FACING).equals(EnumFacing.EAST) && worldIn.getBlockState(pos.offset(EnumFacing.SOUTH)).getBlock() instanceof BlockFluxCrafterLeftSide) {
- worldIn.destroyBlock(pos.offset(EnumFacing.SOUTH), false);
- } else if (state.getValue(FACING).equals(EnumFacing.WEST) && worldIn.getBlockState(pos.offset(EnumFacing.SOUTH.getOpposite())).getBlock() instanceof BlockFluxCrafterLeftSide) {
- worldIn.destroyBlock(pos.offset(EnumFacing.SOUTH.getOpposite()), false);
- }
- super.breakBlock(worldIn, pos, state);
- }
Advertisement
Add Comment
Please, Sign In to add comment