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

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

There is a newer version: 1.4.5
Show newest version
/* Copyright (c) 2010-2014 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;

import se.llbit.chunky.map.CorruptLayer;
import se.llbit.chunky.map.MapTile;
import se.llbit.chunky.map.WorldMapLoader;
import se.llbit.nbt.CompoundTag;

import java.util.Collection;

/**
 * Empty or non-existent chunk.
 *
 * @author Jesper Öqvist 
 */
public class EmptyChunk extends Chunk {

  /**
   * Singleton instance
   */
  public static final EmptyChunk INSTANCE = new EmptyChunk();

  private static final int COLOR = 0xFFFFFFFF;

  @Override public boolean isEmpty() {
    return true;
  }

  private EmptyChunk() {
    super(ChunkPosition.get(0, 0), EmptyWorld.instance);
    surface = CorruptLayer.INSTANCE;
    caves = CorruptLayer.INSTANCE;
    layer = CorruptLayer.INSTANCE;
  }

  @Override public synchronized void getBlockData(byte[] blocks, byte[] data, byte[] biomes,
      Collection tileEntities, Collection entities) {
    for (int i = 0; i < X_MAX * Y_MAX * Z_MAX; ++i) {
      blocks[i] = 0;
    }

    for (int i = 0; i < X_MAX * Z_MAX; ++i) {
      biomes[i] = 0;
    }

    for (int i = 0; i < (X_MAX * Y_MAX * Z_MAX) / 2; ++i) {
      data[i] = 0;
    }
  }

  @Override public void renderLayer(MapTile tile) {
    renderEmpty(tile);
  }

  @Override public int layerColor() {
    return 0xFFEEEEEE;
  }

  @Override public void renderSurface(MapTile tile) {
    renderEmpty(tile);
  }

  @Override public int surfaceColor() {
    return 0xFFEEEEEE;
  }

  @Override public void renderCaves(MapTile tile) {
    renderEmpty(tile);
  }

  @Override public int caveColor() {
    return 0xFFEEEEEE;
  }

  @Override public void renderBiomes(MapTile tile) {
    renderEmpty(tile);
  }

  @Override public int biomeColor() {
    return 0xFFEEEEEE;
  }

  private void renderEmpty(MapTile tile) {
    int[] pixels = new int[tile.size * tile.size];
    for (int z = 0; z < tile.size; ++z) {
      for (int x = 0; x < tile.size; ++x) {
        if (x == z || x - tile.size / 2 == z || x + tile.size / 2 == z) {
          pixels[z * tile.size + x] = 0xFF000000;
        } else {
          pixels[z * tile.size + x] = COLOR;
        }
      }
    }
    tile.setPixels(pixels);
  }

  @Override public synchronized void reset() {
    // Do nothing.
  }

  @Override public synchronized void loadChunk(WorldMapLoader loader) {
    // Do nothing.
  }

  @Override public String toString() {
    return "Chunk: [empty]";
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy