int wMass = 12; // sx,sy are camera coordinates. renw,rnh are the bounds of the processed area in blocks, delta is time since last frame in milliseconds public void tick(int sx, int sy, int renw, int renh, double delta) if (watertime >= 1) { boolean canflow = false; try { for (int x = blockX - 36; x < x1 + 36; x++) { if (x <= 0) continue; for (int y = y1 + 17; y > blockY - 17; y--) { if (y <= 0) continue; if (x >= worldW || y >= worldH) continue; if (waterFall(x, y) == true) { makeW(x, y); makeW(x + 1, y); makeW(x - 1, y); makeW(x, y + 1); } } } canflow = false; for (int x = x1 + 36; x > blockX - 36; x--) { if (x <= 0) continue; for (int y = y1 + 17; y > blockY - 17; y--) { if (y <= 0) continue; if (x >= worldW || y >= worldH) continue; if (block[x][y + 1] != null) { if (water[x][y + 1] == wMass || getState(x, y + 1) == 1) canflow = true; } if (canflow) { if (x <= 1 || y <= 1) continue; if (x >= worldW - 1 || y >= worldH - 1) continue; waterRight(x, y); } } } canflow = false; for (int x = blockX - 36; x < x1 + 36; x++) { if (x <= 0) continue; for (int y = y1 + 17; y > blockY - 17; y--) { if (y <= 0) continue; if (x >= worldW || y >= worldH) continue; if (water[x][y + 1] == wMass || getState(x, y + 1) == 1) canflow = true; if (canflow) { if (x < 0 || y < 0) continue; if (x > worldW || y > worldH) return; if (World.block[x][y] == null) continue; waterLeft(x, y); } // waterUp(x, y); } } } catch (Exception e) { e.printStackTrace(); } watertime = 0; } else { watertime += delta; } } public boolean waterFall(int x, int y) { try { if (y + 1 > worldH) return false; if (block[x][y + 1] == null) return false; if (water[x][y] >= 1) { int lb = water[x][y + 1]; Block bb = block[x][y + 1]; if (bb.id != Art.air) return false; if (lb != wMass && lb == 0) { water[x][y + 1] = water[x][y]; water[x][y] = 0; return true; } else if (lb < wMass) { water[x][y] -= 1; water[x][y + 1] += 1; return true; } return false; } return false; } catch (Exception e) { e.printStackTrace(); } return false; } public void waterRight(int x, int y) { try { int r = water[x + 1][y]; int t = water[x][y]; Block br = block[x + 1][y]; if (br == null) return; if (water[x][y] >= 1) { if (br.id == Art.air && r < t) { water[x][y] -= 1; water[x + 1][y] += 1; makeW(x, y); makeW(x + 1, y); } } } catch (Exception e) { e.printStackTrace(); } } public void waterLeft(int x, int y) { try { int l = water[x - 1][y]; int t = water[x][y]; Block bl = block[x - 1][y]; if (bl == null) return; if (water[x][y] >= 1) { if (bl.id == Art.air && l < t) { water[x][y] -= 1; water[x - 1][y] += 1; makeW(x, y); makeW(x - 1, y); } } } catch (Exception e) { e.printStackTrace(); } } void makeW(int x, int y) { if (x < 2 || y < 2) return; if (x >= worldW || y >= worldH) return; if (water[x][y] > wMass) { water[x][y] = (byte) wMass; } }