Skip to content

Commit 0e8fe57

Browse files
committed
ChunkStorage
1 parent 20e4777 commit 0e8fe57

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.lambda.graphics.renderer.esp
2+
3+
import com.lambda.core.Loadable
4+
import com.lambda.event.events.ConnectionEvent
5+
import com.lambda.event.events.WorldEvent
6+
import com.lambda.event.listener.SafeListener.Companion.concurrentListener
7+
import net.minecraft.util.math.ChunkPos
8+
import net.minecraft.world.chunk.WorldChunk
9+
import java.util.concurrent.ConcurrentHashMap
10+
11+
object ChunkStorage : Loadable {
12+
val chunkMap = ChunkMap()
13+
14+
init {
15+
concurrentListener<WorldEvent.ChunkEvent.Load> { event ->
16+
chunkMap[event.chunk.pos] = event.chunk
17+
}
18+
19+
concurrentListener<WorldEvent.ChunkEvent.Unload> { event ->
20+
chunkMap.remove(event.chunk.pos)
21+
}
22+
23+
concurrentListener<ConnectionEvent.Disconnect> {
24+
chunkMap.clear()
25+
}
26+
}
27+
}
28+
29+
typealias ChunkMap = ConcurrentHashMap<ChunkPos, WorldChunk>

0 commit comments

Comments
 (0)