package twilightforest.world.layer;

import net.minecraft.util.registry.Registry;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.INoiseRandom;
import net.minecraft.world.gen.area.IArea;
import net.minecraft.world.gen.layer.traits.IAreaTransformer2;
import net.minecraft.world.gen.layer.traits.IDimOffset0Transformer;
import twilightforest.worldgen.biomes.BiomeKeys;
import twilightforest.world.TFBiomeProvider;

public enum GenLayerTFRiverMix implements IAreaTransformer2, IDimOffset0Transformer {

	INSTANCE;

//	private GenLayer biomeLayer;
//	private GenLayer riverLayer;

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

	private Registry<Biome> registry;

	GenLayerTFRiverMix() { }

	public GenLayerTFRiverMix setup(Registry<Biome> registry) {
		this.registry = registry;
		return this;
	}

	/**
	 * 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;
//	}


	@Override
	public int apply(INoiseRandom iNoiseRandom, IArea area1, IArea area2, int val1, int val2) {
		int biomeInputs = area1.getValue(this.getOffsetX(val1), this.getOffsetZ(val2));
		int riverInputs = area2.getValue(this.getOffsetX(val1), this.getOffsetZ(val2));

		int stream = TFBiomeProvider.getBiomeId(BiomeKeys.STREAM, registry);

		if (riverInputs == stream) {
			return riverInputs;
		} else {
			return biomeInputs;
		}
	}
}
