Int sets to hashmap where we don't iterate

This commit is contained in:
DBotThePony 2022-12-05 00:19:50 +07:00
parent 1b4dfc4321
commit e971a6014d
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 5 additions and 3 deletions

View File

@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableList
import com.google.common.collect.ImmutableMap
import com.google.common.collect.ImmutableSet
import it.unimi.dsi.fastutil.ints.IntAVLTreeSet
import it.unimi.dsi.fastutil.ints.IntOpenHashSet
import it.unimi.dsi.fastutil.objects.Object2ObjectFunction
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap
import net.minecraft.world.Container
@ -50,11 +51,11 @@ open class ContainerProxy(containers: Stream<Pair<Container, Iterator<Int>>>) :
init {
val list = ImmutableList.Builder<ContainerSlot>()
var i = 0
val validationMap = Reference2ObjectOpenHashMap<Container, IntAVLTreeSet>()
val validationMap = Reference2ObjectOpenHashMap<Container, IntOpenHashSet>()
val slotsMap = Reference2ObjectOpenHashMap<Container, ArrayList<ContainerSlot>>()
for ((container, slots) in containers) {
val validator = validationMap.computeIfAbsent(container, Object2ObjectFunction { IntAVLTreeSet() })
val validator = validationMap.computeIfAbsent(container, Object2ObjectFunction { IntOpenHashSet() })
val slotList = slotsMap.computeIfAbsent(container, Object2ObjectFunction { ArrayList() })
for (slot in slots) {

View File

@ -3,6 +3,7 @@ package ru.dbotthepony.mc.otm.item
import it.unimi.dsi.fastutil.ints.Int2ObjectAVLTreeMap
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap
import it.unimi.dsi.fastutil.ints.IntAVLTreeSet
import it.unimi.dsi.fastutil.ints.IntOpenHashSet
import net.minecraft.ChatFormatting
import net.minecraft.core.Direction
import net.minecraft.nbt.ByteArrayTag
@ -391,7 +392,7 @@ class QuantumBatteryItem : Item {
fun tick(event: ServerTickEvent) {
if (event.phase == TickEvent.Phase.END) {
for (ply in event.server.playerList.players) {
val networkedChannels = IntAVLTreeSet()
val networkedChannels = IntOpenHashSet(0)
for (item in ply.allItemsStream().filter { !it.isEmpty && it.item is QuantumBatteryItem }) {
val power = item.getCapability(MatteryCapability.ENERGY).orThrow() as Power