package twilightforest.world.components.layer;

import net.minecraft.core.Registry;
import net.minecraft.world.level.biome.Biome;
import twilightforest.world.components.biomesources.TFBiomeProvider;
import twilightforest.world.components.layer.vanillalegacy.area.Area;
import twilightforest.world.components.layer.vanillalegacy.context.Context;
import twilightforest.world.components.layer.vanillalegacy.traits.AreaTransformer2;
import twilightforest.world.components.layer.vanillalegacy.traits.DimensionOffset0Transformer;
import twilightforest.init.BiomeKeys;

public enum GenLayerTFRiverMix implements AreaTransformer2, DimensionOffset0Transformer {

	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 applyPixel(Context iNoiseRandom, Area area1, Area area2, int val1, int val2) {
		int biomeInputs = area1.get(this.getParentX(val1), this.getParentY(val2));
		int riverInputs = area2.get(this.getParentX(val1), this.getParentY(val2));

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

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