Use tree set

This commit is contained in:
DBotThePony 2025-03-24 19:22:35 +07:00
parent bc81103e38
commit 5d05fe3bb4
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 4 additions and 1 deletions

View File

@ -9,6 +9,7 @@ object BlockPosHashStrategy : Hash.Strategy<BlockPos>, Comparator<BlockPos> {
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()

View File

@ -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<BlockPos>): Set<BlockPos> {
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<*>