Heimdall: Keep track of block data.

This commit is contained in:
2023-02-07 20:36:30 -05:00
parent 760b77364a
commit 688106a6e6
13 changed files with 46 additions and 45 deletions

View File

@ -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",

View File

@ -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

View File

@ -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(

View File

@ -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")
}
}

View File

@ -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)
}
}