<commit_before>package com.pg85.otg.gen.biome.layers;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import com.pg85.otg.gen.biome.NewBiomeData;
import com.pg85.otg.gen.biome.layers.type.ParentedLayer;
import com.pg85.otg.gen.biome.layers.util.LayerRandomnessSource;
import com.pg85.otg.gen.biome.layers.util.LayerSampleContext;
import com.pg85.otg.gen.biome.layers.util.LayerSampler;

/**
 * Places the biomes at a specific depth, given the biome groups.
 */
class BiomeLayer implements ParentedLayer
{
	private final BiomeLayerData data;
	private final int depth;

	private final Map<NewBiomeGroup, Integer> groupToMaxRarity = new HashMap<>();
	private final Map<NewBiomeGroup, Map<Integer, NewBiomeData>> groupBiomes = new HashMap<>();
	BiomeLayer(BiomeLayerData data, int depth) {
		this.data = data;
		this.depth = depth;

		// Iterate through all of the groups
		for (Map.Entry<Integer, List<NewBiomeGroup>> entry : data.groups.entrySet())
		{
			for (NewBiomeGroup group : entry.getValue())
			{
				int maxRarity = 0;

				Map<Integer, NewBiomeData> biomes = new TreeMap<>();

				for (NewBiomeData biome : group.biomes)
				{
					if (depth == biome.biomeSize)
					{
						maxRarity += biome.rarity;
						biomes.put(maxRarity, biome);
					}
				}

				if (maxRarity > 0)
				{
					this.groupToMaxRarity.put(group, maxRarity);
					this.groupBiomes.put(group, biomes);
				}
			}
		}
	}

	@Override
	public int sample(LayerSampleContext<?> context, LayerSampler parent, int x, int z)
	{
		int sample = parent.sample(x, z);

		if (BiomeLayers.isLand(sample)) {
			int biomeGroupId = BiomeLayers.getGroupId(sample);
			if (biomeGroupId > 0)
			{
				NewBiomeGroup group = data.groupRegistry.get(biomeGroupId);

				if (groupToMaxRarity.containsKey(group) && groupBiomes.containsKey(group))
				{
					int biome = getBiomeFromGroup(context, groupToMaxRarity.get(group), groupBiomes.get(group));

					return sample | biome;
				}
			}
		}

		return sample;
	}

	private int getBiomeFromGroup(LayerRandomnessSource random, int maxRarity, Map<Integer, NewBiomeData> rarityMap)
	{
		// Get a random rarity number from our max rarity
		int chosenRarity = random.nextInt(maxRarity);

		// Iterate through the rarity map and see if the chosen rarity is less than the rarity for each group, if it is then return.
		for (Map.Entry<Integer, NewBiomeData> entry : rarityMap.entrySet())
		{
			if (chosenRarity < entry.getKey()) {
				return entry.getValue().id;
			}
		}

		// Fallback
		return 0;
	}

}<commit_msg>1.16.3 - 0.0.1: BiomeLayer biomebits fix<commit_after>package com.pg85.otg.gen.biome.layers;

import static com.pg85.otg.gen.biome.layers.BiomeLayers.BIOME_BITS;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import com.pg85.otg.gen.biome.NewBiomeData;
import com.pg85.otg.gen.biome.layers.type.ParentedLayer;
import com.pg85.otg.gen.biome.layers.util.LayerRandomnessSource;
import com.pg85.otg.gen.biome.layers.util.LayerSampleContext;
import com.pg85.otg.gen.biome.layers.util.LayerSampler;

/**
 * Places the biomes at a specific depth, given the biome groups.
 */
class BiomeLayer implements ParentedLayer
{
	private final BiomeLayerData data;
	private final int depth;

	private final Map<NewBiomeGroup, Integer> groupToMaxRarity = new HashMap<>();
	private final Map<NewBiomeGroup, Map<Integer, NewBiomeData>> groupBiomes = new HashMap<>();
	BiomeLayer(BiomeLayerData data, int depth) {
		this.data = data;
		this.depth = depth;

		// Iterate through all of the groups
		for (Map.Entry<Integer, List<NewBiomeGroup>> entry : data.groups.entrySet())
		{
			for (NewBiomeGroup group : entry.getValue())
			{
				int maxRarity = 0;

				Map<Integer, NewBiomeData> biomes = new TreeMap<>();

				for (NewBiomeData biome : group.biomes)
				{
					if (depth == biome.biomeSize)
					{
						maxRarity += biome.rarity;
						biomes.put(maxRarity, biome);
					}
				}

				if (maxRarity > 0)
				{
					this.groupToMaxRarity.put(group, maxRarity);
					this.groupBiomes.put(group, biomes);
				}
			}
		}
	}

	@Override
	public int sample(LayerSampleContext<?> context, LayerSampler parent, int x, int z)
	{
		int sample = parent.sample(x, z);

		if (
			// If biome bits have not yet been set (this column has not been cached), do so now.
			(sample & BIOME_BITS) == 0 && 
			BiomeLayers.isLand(sample)
		)
		{
			int biomeGroupId = BiomeLayers.getGroupId(sample);
			if (biomeGroupId > 0)
			{
				NewBiomeGroup group = data.groupRegistry.get(biomeGroupId);

				if (groupToMaxRarity.containsKey(group) && groupBiomes.containsKey(group))
				{
					int biome = getBiomeFromGroup(context, groupToMaxRarity.get(group), groupBiomes.get(group));				
					return sample | biome;
				}
			}
		}

		return sample;
	}

	private int getBiomeFromGroup(LayerRandomnessSource random, int maxRarity, Map<Integer, NewBiomeData> rarityMap)
	{
		// Get a random rarity number from our max rarity
		int chosenRarity = random.nextInt(maxRarity);

		// Iterate through the rarity map and see if the chosen rarity is less than the rarity for each group, if it is then return.
		for (Map.Entry<Integer, NewBiomeData> entry : rarityMap.entrySet())
		{
			if (chosenRarity < entry.getKey()) {
				return entry.getValue().id;
			}
		}

		// Fallback
		return 0;
	}
}
{'fraction_non_alphanumeric': 0.11434433874277188, 'fraction_numerical': 0.00783435926133184, 'mean_word_length': 3.6666666666666665, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3406753', 'n_tokens_mistral': 2156, 'n_tokens_neox': 1855, 'n_words': 435}