From 5d05fe3bb49e6dea8812e59b9d13f6ec0dcdf7c7 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Mon, 24 Mar 2025 19:22:35 +0700 Subject: [PATCH] Use tree set --- .../dbotthepony/mc/otm/core/collect/BlockPosHashStrategy.kt | 1 + .../mc/otm/worldgen/placement/EnhancedPlacementModifier.kt | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/core/collect/BlockPosHashStrategy.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/core/collect/BlockPosHashStrategy.kt index ba32c3ad8..2d7c5c79f 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/core/collect/BlockPosHashStrategy.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/core/collect/BlockPosHashStrategy.kt @@ -9,6 +9,7 @@ object BlockPosHashStrategy : Hash.Strategy, Comparator { return a == b } + // while this avoids collisions, it is rather slow when compared to just using a tree set here override fun hashCode(o: BlockPos?): Int { o ?: return 0 return HashCommon.murmurHash3(o.x.toLong().and(1 shl 26 - 1) or o.z.toLong().and(1 shl 26 - 1).shl(26) or o.y.toLong().and(1 shl 12 - 1).shl(52)).toInt() diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/worldgen/placement/EnhancedPlacementModifier.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/worldgen/placement/EnhancedPlacementModifier.kt index 6f7ac934a..4cf2d005b 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/worldgen/placement/EnhancedPlacementModifier.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/worldgen/placement/EnhancedPlacementModifier.kt @@ -4,6 +4,7 @@ import com.mojang.serialization.Codec import com.mojang.serialization.MapCodec import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenCustomHashSet import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet +import it.unimi.dsi.fastutil.objects.ObjectRBTreeSet import net.minecraft.core.BlockPos import net.minecraft.world.level.levelgen.placement.PlacementModifier import net.neoforged.bus.api.IEventBus @@ -26,7 +27,8 @@ interface EnhancedPlacementModifier { override fun evaluate(context: EnhancedPlacementContext, positions: Set): Set { return positions.stream() .flatMap { parent.getPositions(context.vanillaContext, context.random, it) } - .collect(Collectors.toCollection { ObjectLinkedOpenCustomHashSet(BlockPosHashStrategy) }) + // use Red-Black tree set instead of AVL tree set because we are write-intense + .collect(Collectors.toCollection { ObjectRBTreeSet(BlockPosHashStrategy) }) } override val type: Type<*>