public static TileEntity getTileEntity(IBlockAccess blockaccess, int x, int y, int z) { HashSet<ChunkCoordinates> visited = Sets.newHashSet(); Block block = blockaccess.getBlock(x, y, z); while (block != NailedBlocks.portalController) { if (isValidLinkPortalBlock(block) == 0) { return null; } ChunkCoordinates pos = new ChunkCoordinates(x, y, z); if (!visited.add(pos)) { return null; } int meta = blockaccess.getBlockMetadata(x, y, z); if (meta == 0) { return null; } if (meta == 1) { y--; } else if (meta == 2) { y++; } else if (meta == 3) { z--; } else if (meta == 4) { z++; } else if (meta == 5) { x--; } else if (meta == 6) { x++; } else { return null; } block = blockaccess.getBlock(x, y, z); } return blockaccess.getTileEntity(x, y, z); }