All Downloads are FREE. Search and download functionalities are using the official Maven repository.

se.llbit.chunky.world.Clouds Maven / Gradle / Ivy

There is a newer version: 1.4.5
Show newest version
/* Copyright (c) 2012 Jesper Öqvist 
 *
 * This file is part of Chunky.
 *
 * Chunky is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Chunky is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with Chunky.  If not, see .
 */
package se.llbit.chunky.world;

/**
 * Stores the cloud bits from the cloud texture
 *
 * @author Jesper Öqvist 
 */
public class Clouds {
  private static long[][] clouds = new long[32][32];

  static {
    // zero the cloud data
    for (int i = 0; i < 32; ++i) {
      for (int j = 0; j < 32; ++j) {
        clouds[i][j] = 0L;
      }
    }
  }

  /**
   * Get cloud bit at position (x, y)
   *
   * @return 0 = no cloud, 1 = cloud
   */
  public static int getCloud(int x, int y) {
    x = ((x % 256) + 256) % 256; // Compute modulo 256 >=0.
    y = ((y % 256) + 256) % 256; // Compute modulo 256 >=0.
    int tilex = x / 8;
    int tiley = y / 8;
    int subx = x & 7;
    int suby = y & 7;
    return (int) ((clouds[tilex][tiley] >>> (suby * 8 + subx)) & 1);
  }

  /**
   * Set cloud bit at position (x, y)
   *
   * @param v 0 = no cloud, 1 = cloud
   */
  public static void setCloud(int x, int y, int v) {
    x = ((x % 256) + 256) % 256; // Compute modulo 256 >=0.
    y = ((y % 256) + 256) % 256; // Compute modulo 256 >=0.
    int tilex = x / 8;
    int tiley = y / 8;
    int subx = x & 7;
    int suby = y & 7;
    clouds[tilex][tiley] |= ((long) (v & 1)) << (suby * 8 + subx);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy