aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowHelper.kt12
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt3
2 files changed, 8 insertions, 7 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowHelper.kt
index 55b893938..3458bd2a3 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowHelper.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowHelper.kt
@@ -8,7 +8,7 @@ import at.hannibal2.skyhanni.utils.LocationUtils
import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayer
import at.hannibal2.skyhanni.utils.LorenzColor
import at.hannibal2.skyhanni.utils.LorenzUtils
-import at.hannibal2.skyhanni.utils.LorenzUtils.makeSyncMap
+import at.hannibal2.skyhanni.utils.LorenzUtils.editThreadSave
import at.hannibal2.skyhanni.utils.LorenzVec
import at.hannibal2.skyhanni.utils.RenderUtils.draw3DLine
import at.hannibal2.skyhanni.utils.RenderUtils.drawColor
@@ -23,7 +23,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class GriffinBurrowHelper {
private var guessLocation: LorenzVec? = null
- private val particleBurrows = makeSyncMap(mutableMapOf<LorenzVec, BurrowType>())
+ private var particleBurrows = mapOf<LorenzVec, BurrowType>()
private var animationLocation: LorenzVec? = null
private var lastDug: LorenzVec? = null
private var teleportedLocation: LorenzVec? = null
@@ -51,7 +51,7 @@ class GriffinBurrowHelper {
@SubscribeEvent
fun onBurrowDetect(event: BurrowDetectEvent) {
EntityMovementData.addToTrack(Minecraft.getMinecraft().thePlayer)
- particleBurrows[event.burrowLocation] = event.type
+ particleBurrows = particleBurrows.editThreadSave { this[event.burrowLocation] = event.type }
if (SkyHanniMod.feature.diana.burrowsNearbyDetection) {
checkRemoveGuess(true)
@@ -73,7 +73,7 @@ class GriffinBurrowHelper {
@SubscribeEvent
fun onBurrowDug(event: BurrowDugEvent) {
val location = event.burrowLocation
- particleBurrows.remove(location)
+ particleBurrows = particleBurrows.editThreadSave { remove(location) }
if (particleBurrows.isNotEmpty()) {
animationLocation = location
}
@@ -92,7 +92,7 @@ class GriffinBurrowHelper {
@SubscribeEvent
fun onChatMessage(event: LorenzChatEvent) {
if (event.message.startsWith("§c ☠ §r§7You were killed by §r")) {
- particleBurrows.keys.removeIf { particleBurrows[it] == BurrowType.MOB }
+ particleBurrows = particleBurrows.editThreadSave { keys.removeIf { this[it] == BurrowType.MOB } }
}
}
@@ -101,7 +101,7 @@ class GriffinBurrowHelper {
guessLocation = null
animationLocation = null
lastDug = null
- particleBurrows.clear()
+ particleBurrows = particleBurrows.editThreadSave { clear() }
}
private fun findBlock(point: LorenzVec): LorenzVec {
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
index fbb0272f6..043cfe45f 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
@@ -263,5 +263,6 @@ object LorenzUtils {
whenChanged { _, _ -> observer.run() }
}
- fun <K, V> makeSyncMap(originalMap: MutableMap<K, V>) = Collections.synchronizedMap(originalMap)
+ fun <K, V> Map<K, V>.editThreadSave(function: MutableMap<K, V>.() -> Unit) =
+ toMutableMap().also { function(it) }.toMap()
} \ No newline at end of file