package twilightforest.world.layer;

import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.layer.GenLayer;
import net.minecraft.world.gen.layer.IntCache;
import twilightforest.biomes.TFBiomes;

public class GenLayerTFRiverMix extends GenLayer {

	private GenLayer biomeLayer;
	private GenLayer riverLayer;

	public GenLayerTFRiverMix(long seed, GenLayer biomeLayer, GenLayer riverLayer) {
		super(seed);
		this.biomeLayer = biomeLayer;
		this.riverLayer = riverLayer;
	}

	/**
	 * Initialize layer's local worldGenSeed based on its own baseSeed and the world's global seed (passed in as an
	 * argument).
	 */
	@Override
	public void initWorldGenSeed(long seed) {
		this.biomeLayer.initWorldGenSeed(seed);
		this.riverLayer.initWorldGenSeed(seed);
		super.initWorldGenSeed(seed);
	}

	/**
	 * Returns a list of integer values generated by this layer. These may be
	 * interpreted as temperatures, rainfall amounts, or biomeList[] indices
	 * based on the particular GenLayer subclass.
	 */
	@Override
	public int[] getInts(int x, int z, int width, int depth) {

		int[] biomeInputs = this.biomeLayer.getInts(x, z, width, depth);
		int[] riverInputs = this.riverLayer.getInts(x, z, width, depth);
		int[] outputs = IntCache.getIntCache(width * depth);

		int stream = Biome.getIdForBiome(TFBiomes.stream);

		for (int i = 0; i < width * depth; ++i) {
			if (riverInputs[i] == stream) {
				outputs[i] = riverInputs[i] & 255;
			} else {
				outputs[i] = biomeInputs[i];
			}
		}

		return outputs;
	}
}
