diff --git a/common/src/main/java/hunternif/mc/impl/atlas/core/scanning/TileDetectorBase.java b/common/src/main/java/hunternif/mc/impl/atlas/core/scanning/TileDetectorBase.java index 41c662279..a42014477 100644 --- a/common/src/main/java/hunternif/mc/impl/atlas/core/scanning/TileDetectorBase.java +++ b/common/src/main/java/hunternif/mc/impl/atlas/core/scanning/TileDetectorBase.java @@ -1,5 +1,8 @@ package hunternif.mc.impl.atlas.core.scanning; +import com.google.common.collect.HashMultiset; +import com.google.common.collect.Multiset; +import com.google.common.collect.Ordering; import dev.architectury.injectables.annotations.ExpectPlatform; import hunternif.mc.impl.atlas.AntiqueAtlasMod; import hunternif.mc.impl.atlas.core.TileIdMap; @@ -17,11 +20,6 @@ import net.minecraft.world.biome.BiomeKeys; import net.minecraft.world.chunk.Chunk; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Map; - /** * Detects the 256 vanilla biomes, water pools and lava pools. * Water and beach biomes are given priority because shore line is the defining @@ -62,23 +60,6 @@ static int priorityForBiome(RegistryEntry biomeTag) { } } - /* these are the values used by vanilla, but it just doesn't work for me. - protected static TileHeightType getHeightType(double weirdness) { - if (weirdness < (double) VanillaTerrainParameters.getNormalizedWeirdness(0.05f)) { - return TileHeightType.VALLEY; - } - if (weirdness < (double) VanillaTerrainParameters.getNormalizedWeirdness(0.26666668f)) { - return TileHeightType.LOW; - } - if (weirdness < (double) VanillaTerrainParameters.getNormalizedWeirdness(0.4f)) { - return TileHeightType.MID; - } - if (weirdness < (double) VanillaTerrainParameters.getNormalizedWeirdness(0.56666666f)) { - return TileHeightType.HIGH; - } - return TileHeightType.PEAK; - } */ - protected static TileHeightType getHeightTypeFromY(int y, int sealevel) { if (y < sealevel + 10) { return TileHeightType.VALLEY; @@ -100,18 +81,14 @@ protected static Identifier getBiomeIdentifier(World world, Biome biome) { return world.getRegistryManager().get(Registry.BIOME_KEY).getId(biome); } - protected static void updateOccurrencesMap(Map map, Identifier biome, int weight) { - int occurrence = map.getOrDefault(biome, 0) + weight; - map.put(biome, occurrence); + protected static void updateOccurrencesMap(Multiset map, Identifier biome, int weight) { + map.add(biome, weight); } - protected static void updateOccurrencesMap(Map map, World world, Biome biome, TileHeightType type, int weight) { + protected static void updateOccurrencesMap(Multiset map, World world, Biome biome, TileHeightType type, int weight) { Identifier id = getBiomeIdentifier(world, biome); - id = Identifier.tryParse(id.toString() + "_" + type.getName()); - - - int occurrence = map.getOrDefault(id, 0) + weight; - map.put(id, occurrence); + id = new Identifier(id.getNamespace(), id.getPath() + "_" + type.getName()); + map.add(id, weight); } @Override @@ -126,7 +103,7 @@ public int getScanRadius() { */ @Override public Identifier getBiomeID(World world, Chunk chunk) { - Map biomeOccurrences = new HashMap<>(BuiltinRegistries.BIOME.getIds().size()); + Multiset biomeOccurrences = HashMultiset.create(BuiltinRegistries.BIOME.getIds().size()); Registry biomeRegistry = world.getRegistryManager().get(Registry.BIOME_KEY); for (int x = 0; x < 16; x++) { @@ -135,20 +112,9 @@ public Identifier getBiomeID(World world, Chunk chunk) { Biome biome = chunk.getBiomeForNoiseGen(x, world.getSeaLevel(), z).value(); RegistryEntry biomeTag = biomeRegistry.entryOf(biomeRegistry.getKey(biome).orElse(null)); - // get top block int y = chunk.getHeightmap(Heightmap.Type.MOTION_BLOCKING).get(x, z); - - //this code runs on the server -// ServerChunkManager man = (ServerChunkManager) world.getChunkManager(); -// MultiNoiseUtil.MultiNoiseSampler sampler = man.getChunkGenerator().getMultiNoiseSampler(); -// ChunkPos pos = chunk.getPos(); -// MultiNoiseUtil.NoiseValuePoint sample = sampler.sample(pos.getStartX() + x, y + 10, pos.getStartZ() + z); - -// float m = MultiNoiseUtil.method_38666(sample.weirdnessNoise()); -// double weirdness = VanillaTerrainParameters.getNormalizedWeirdness(m); - if (AntiqueAtlasMod.CONFIG.doScanPonds) { if (y > 0) { Block topBlock = chunk.getBlockState(new BlockPos(x, y - 1, z)).getBlock(); @@ -172,14 +138,11 @@ public Identifier getBiomeID(World world, Chunk chunk) { } } -// updateOccurrencesMap(biomeOccurrences, world, biome, getHeightType(weirdness), priorityForBiome(getBiomeIdentifier(world, biome))); updateOccurrencesMap(biomeOccurrences, world, biome, getHeightTypeFromY(y, world.getSeaLevel()), priorityForBiome(biomeTag)); } } if (biomeOccurrences.isEmpty()) return null; - - Map.Entry meanBiome = Collections.max(biomeOccurrences.entrySet(), Comparator.comparingInt(Map.Entry::getValue)); - return meanBiome.getKey(); + return biomeOccurrences.entrySet().stream().max(Ordering.natural().onResultOf(Multiset.Entry::getCount)).orElseThrow().getElement(); } } diff --git a/common/src/main/java/hunternif/mc/impl/atlas/core/scanning/TileDetectorEnd.java b/common/src/main/java/hunternif/mc/impl/atlas/core/scanning/TileDetectorEnd.java index c800f2854..811502b87 100644 --- a/common/src/main/java/hunternif/mc/impl/atlas/core/scanning/TileDetectorEnd.java +++ b/common/src/main/java/hunternif/mc/impl/atlas/core/scanning/TileDetectorEnd.java @@ -1,5 +1,8 @@ package hunternif.mc.impl.atlas.core.scanning; +import com.google.common.collect.HashMultiset; +import com.google.common.collect.Multiset; +import com.google.common.collect.Ordering; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.util.Identifier; @@ -11,11 +14,6 @@ import net.minecraft.world.biome.BiomeKeys; import net.minecraft.world.chunk.Chunk; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Map; - /** * Detects seas of lava, cave ground and cave walls in the Nether. * @@ -25,7 +23,7 @@ public class TileDetectorEnd extends TileDetectorBase implements ITileDetector { @Override public Identifier getBiomeID(World world, Chunk chunk) { - Map biomeOccurrences = new HashMap<>(BuiltinRegistries.BIOME.getIds().size()); + Multiset biomeOccurrences = HashMultiset.create(BuiltinRegistries.BIOME.getIds().size()); for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { @@ -53,11 +51,7 @@ public Identifier getBiomeID(World world, Chunk chunk) { } } - if (biomeOccurrences.isEmpty()) - return null; - - Map.Entry meanBiome = Collections.max(biomeOccurrences.entrySet(), Comparator - .comparingInt(Map.Entry::getValue)); - return meanBiome.getKey(); + if (biomeOccurrences.isEmpty()) return null; + return biomeOccurrences.entrySet().stream().max(Ordering.natural().onResultOf(Multiset.Entry::getCount)).orElseThrow().getElement(); } } diff --git a/common/src/main/java/hunternif/mc/impl/atlas/core/scanning/TileDetectorNether.java b/common/src/main/java/hunternif/mc/impl/atlas/core/scanning/TileDetectorNether.java index 4d3970ab6..0a89186fc 100644 --- a/common/src/main/java/hunternif/mc/impl/atlas/core/scanning/TileDetectorNether.java +++ b/common/src/main/java/hunternif/mc/impl/atlas/core/scanning/TileDetectorNether.java @@ -1,5 +1,8 @@ package hunternif.mc.impl.atlas.core.scanning; +import com.google.common.collect.HashMultiset; +import com.google.common.collect.Multiset; +import com.google.common.collect.Ordering; import hunternif.mc.impl.atlas.core.TileIdMap; import net.minecraft.block.Block; import net.minecraft.block.BlockState; @@ -14,11 +17,6 @@ import net.minecraft.world.biome.Biome; import net.minecraft.world.chunk.Chunk; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Map; - /** * Detects seas of lava, cave ground and cave walls in the Nether. * @@ -42,7 +40,7 @@ public class TileDetectorNether extends TileDetectorBase implements ITileDetecto @Override public Identifier getBiomeID(World world, Chunk chunk) { - Map biomeOccurrences = new HashMap<>(BuiltinRegistries.BIOME.getIds().size()); + Multiset biomeOccurrences = HashMultiset.create(BuiltinRegistries.BIOME.getIds().size()); Registry biomeRegistry = world.getRegistryManager().get(Registry.BIOME_KEY); for (int x = 0; x < 16; x++) { @@ -71,11 +69,7 @@ public Identifier getBiomeID(World world, Chunk chunk) { } if (biomeOccurrences.isEmpty()) return null; - - Map.Entry meanBiome = Collections.max(biomeOccurrences.entrySet(), Comparator - .comparingInt(Map.Entry::getValue)); - - return meanBiome.getKey(); + return biomeOccurrences.entrySet().stream().max(Ordering.natural().onResultOf(Multiset.Entry::getCount)).orElseThrow().getElement(); } @Override