From ebc1762cb60ad0335b8b953319b0083fd94bd38e Mon Sep 17 00:00:00 2001 From: Jason Mitchell Date: Mon, 19 Feb 2024 20:36:33 -0800 Subject: [PATCH] Try a thread safe client map, and guard against a null world (#6) --- src/main/scala/mrtjp/relocation/movement.scala | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/scala/mrtjp/relocation/movement.scala b/src/main/scala/mrtjp/relocation/movement.scala index e1f1adf..89c78ce 100644 --- a/src/main/scala/mrtjp/relocation/movement.scala +++ b/src/main/scala/mrtjp/relocation/movement.scala @@ -17,17 +17,18 @@ import net.minecraft.client.Minecraft import net.minecraft.init.Blocks import net.minecraft.world.{ChunkCoordIntPair, World} import net.minecraftforge.common.DimensionManager - +import scala.collection.concurrent.TrieMap import scala.collection.mutable.{ HashMap => MHashMap, MultiMap => MMultiMap, Set => MSet } + import scala.ref.WeakReference object MovementManager2 { val serverRelocations = MHashMap[Int, WorldStructs]() - val clientRelocations = MHashMap[Int, WorldStructs]() + val clientRelocations = TrieMap[Int, WorldStructs]() def relocationMap(isClient: Boolean) = if (isClient) clientRelocations else serverRelocations @@ -106,8 +107,10 @@ object MovementManager2 { RelocationSPH.forceSendData() } - def isMoving(w: World, x: Int, y: Int, z: Int) = - getWorldStructs(w).contains(x, y, z) + def isMoving(w: World, x: Int, y: Int, z: Int) = { + if (w == null) false + else getWorldStructs(w).contains(x, y, z) + } def addStructToWorld(w: World, b: BlockStruct) { getWorldStructs(w).addStruct(b)