BasicWorldGenerator implements WorldGenerator { public boolean addRiver(int x1, int y1, int x2, int y2) throws Exception { if (currentWorld == null) throw new Exception(NO_WORLD_EXCEPTION_MESSAGE); if (x1 == x2 && y1 == y2) { return true; } Tile current = currentWorld.getTile(x1, y1); int currElevation = (int) current.getProperty(TileProperty.ELEVATION); ArrayList<Tile> adjacent = new ArrayList<>(); Point[] points = {new Point(x1 - 1, y1 - 1), new Point(x1, y1 - 1), new Point(x1 + 1, y1 - 1), new Point(x1 + 1, y1), new Point(x1 + 1, y1 + 1), new Point(x1, y1 + 1), new Point(x1 - 1, y1 + 1), new Point(x1 - 1, y1)}; for (Point point : points) { if (point.getX() < 0 || point.getX() >= currentWorld.getWidth() || point.getY() < 0 || point.getY() >= currentWorld.getHeight()) { continue; } Tile tile = currentWorld.getTile((int) point.getX(), (int) point.getY()); if ((int) tile.getProperty(TileProperty.ELEVATION) <= currElevation && getDistance((int) point.getX(), (int) point.getY(), x2, y2) < getDistance(x1, y1, x2, y2)) { adjacent.add(tile); } } if (adjacent.isEmpty()) { return false; } Tile next = getNearestSource(adjacent, x2, y2); Random random = new Random(Integer.hashCode(x1) * Integer.hashCode(y1)); for (int i = 0; i < 2; i++) { if (random.nextDouble() < 0.5) { adjacent.remove(next); if (!adjacent.isEmpty()) { next = getNearestSource(adjacent, x2, y2); } } } if (addRiver((int) next.getWorldX(), (int) next.getWorldY(), x2, y2)) { current.setTileEntity(new Water(current)); return true; } else { return false; } } BasicWorldGenerator(); @Override void configureWorld(World world); void configureWorld(String name, int width, int height, long seed); void setExtensionSize(int minX, int minY, int maxX, int maxY); void createRivers(); void riverPoints(long seed); boolean addRiver(int x1, int y1, int x2, int y2); void addLakes(); void setBaseTileTypes(int[] tileTypes); void setTileWaterLevel(); void setElevation(); void setMoisture(); void updateMoisture(); void setBiomes(); void addBiomeEntities(); void addSecretGold(); void placeStaffHouse(); @Override World build();  }
@Test public void testAddRiver() throws Exception { BasicWorldGenerator gen = new BasicWorldGenerator(); Assert.assertTrue("Error!! Current World is Null.",gen !=null); }