mirror of
https://github.com/GayPizzaSpecifications/foundation.git
synced 2025-08-03 21:41:32 +00:00
Heimdall: Keep track of block data.
This commit is contained in:
@ -33,7 +33,7 @@ class GenerateWorldLoadFile : CliktCommand(name = "generate-world-load", help =
|
||||
for ((id, changelog) in worldChangelogs) {
|
||||
val tracker = BlockLogTracker()
|
||||
tracker.replay(changelog)
|
||||
val sparse = tracker.buildBlockMap { ExportedBlock(it.type) }
|
||||
val sparse = tracker.buildBlockMap { ExportedBlock(it.type, it.data) }
|
||||
val blocks = sparse.blocks
|
||||
worlds[id.toString().lowercase()] = WorldLoadWorld(
|
||||
worldNames[id] ?: "unknown_$id",
|
||||
|
@ -47,7 +47,7 @@ class ChunkExportLoader(
|
||||
}
|
||||
|
||||
val coordinate = BlockCoordinate(x.toLong(), y.toLong(), z.toLong())
|
||||
val state = BlockState.cached(block.type)
|
||||
val state = BlockState(block.type, block.data)
|
||||
map?.put(coordinate, state)
|
||||
if (allBlocks != null) {
|
||||
allBlocks[coordinate] = state
|
||||
|
@ -68,10 +68,11 @@ class BlockChangelog(
|
||||
val y = row[BlockChangeView.y]
|
||||
val z = row[BlockChangeView.z]
|
||||
val block = row[BlockChangeView.block]
|
||||
val blockData = row[BlockChangeView.blockData]
|
||||
val location = BlockCoordinate(x.toLong(), y.toLong(), z.toLong())
|
||||
|
||||
val fromBlock = if (changeIsBreak) {
|
||||
BlockState.cached(block)
|
||||
BlockState(block, blockData)
|
||||
} else {
|
||||
BlockState.AirBlock
|
||||
}
|
||||
@ -79,7 +80,7 @@ class BlockChangelog(
|
||||
val toBlock = if (changeIsBreak) {
|
||||
BlockState.AirBlock
|
||||
} else {
|
||||
BlockState.cached(block)
|
||||
BlockState(block, blockData)
|
||||
}
|
||||
|
||||
BlockChange(
|
||||
|
@ -1,15 +1,13 @@
|
||||
package gay.pizza.foundation.heimdall.tool.state
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable(BlockStateSerializer::class)
|
||||
data class BlockState(val type: String) {
|
||||
@Serializable
|
||||
data class BlockState(
|
||||
val type: String,
|
||||
val data: String? = null
|
||||
) {
|
||||
companion object {
|
||||
private val cache = ConcurrentHashMap<String, BlockState>()
|
||||
|
||||
val AirBlock: BlockState = cached("minecraft:air")
|
||||
|
||||
fun cached(type: String): BlockState = cache.computeIfAbsent(type) { BlockState(type) }
|
||||
val AirBlock: BlockState = BlockState("minecraft:air")
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +0,0 @@
|
||||
package gay.pizza.foundation.heimdall.tool.state
|
||||
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
|
||||
class BlockStateSerializer : KSerializer<BlockState> {
|
||||
override val descriptor: SerialDescriptor
|
||||
get() = String.serializer().descriptor
|
||||
|
||||
override fun deserialize(decoder: Decoder): BlockState {
|
||||
return BlockState.cached(decoder.decodeString())
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, value: BlockState) {
|
||||
encoder.encodeString(value.type)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user