registries: properly update flattened state

This commit is contained in:
Bixilon 2023-03-22 11:05:44 +01:00
parent 5e0116a15e
commit ef4de01564
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
4 changed files with 15 additions and 10 deletions

View File

@ -52,6 +52,7 @@ object ConnectionTestUtil {
connection::account.forceSet(TestAccount) connection::account.forceSet(TestAccount)
connection::version.forceSet(version) connection::version.forceSet(version)
connection::registries.forceSet(Registries()) connection::registries.forceSet(Registries())
connection.registries.updateFlattened(version.flattened)
connection.registries.parent = if (version == IT.VERSION) IT.REGISTRIES else ITUtil.loadRegistries(version) connection.registries.parent = if (version == IT.VERSION) IT.REGISTRIES else ITUtil.loadRegistries(version)
connection::world.forceSet(createWorld(connection, light, (worldSize * 2 + 1).pow(2))) connection::world.forceSet(createWorld(connection, light, (worldSize * 2 + 1).pow(2)))
connection::player.forceSet(LocalPlayerEntity(connection.account, connection, SignatureKeyManagement(connection, TestAccount))) connection::player.forceSet(LocalPlayerEntity(connection.account, connection, SignatureKeyManagement(connection, TestAccount)))

View File

@ -132,8 +132,6 @@ class Registries(
var isFullyLoaded = false var isFullyLoaded = false
private set private set
private var isFlattened = false
override var parent: Registries? = null override var parent: Registries? = null
set(value) { set(value) {
@ -146,11 +144,15 @@ class Registries(
return entityDataIndexMap[field] ?: parent?.getEntityDataIndex(field) return entityDataIndexMap[field] ?: parent?.getEntityDataIndex(field)
} }
fun updateFlattened(flattened: Boolean) {
block.flattened = flattened
blockState.flattened = flattened
item.flattened = flattened
}
fun load(version: Version, pixlyzerData: Map<String, Any>, latch: AbstractLatch) { fun load(version: Version, pixlyzerData: Map<String, Any>, latch: AbstractLatch) {
isFlattened = version.flattened updateFlattened(version.flattened)
block.flattened = isFlattened
blockState.flattened = isFlattened
item.flattened = isFlattened
var error: Throwable? = null var error: Throwable? = null
val worker = TaskWorker(errorHandler = { _, it -> if (error == null) error = it }) val worker = TaskWorker(errorHandler = { _, it -> if (error == null) error = it })

View File

@ -62,6 +62,7 @@ class BlockStateRegistry(var flattened: Boolean) : AbstractRegistry<BlockState?>
fun forceGet(id: Int): BlockState? { fun forceGet(id: Int): BlockState? {
val state = _get(id) val state = _get(id)
if (state != null) return state if (state != null) return state
if (flattened) return null
return _get((id shr 4) shl 4) // Remove meta and try again return _get((id shr 4) shl 4) // Remove meta and try again
} }
@ -73,10 +74,11 @@ class BlockStateRegistry(var flattened: Boolean) : AbstractRegistry<BlockState?>
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
override fun getOrNull(id: Int): BlockState? { override fun getOrNull(id: Int): BlockState? {
if (id == ProtocolDefinition.AIR_BLOCK_ID) { if (flattened) {
return null if (id == ProtocolDefinition.AIR_BLOCK_ID) return null
} else {
if (id shr 4 == ProtocolDefinition.AIR_BLOCK_ID) return null
} }
if (!flattened && id shr 4 == ProtocolDefinition.AIR_BLOCK_ID) return null
val state = forceGet(id) ?: return null val state = forceGet(id) ?: return null
if (state.block is AirBlock) { if (state.block is AirBlock) {
return null return null

View File

@ -83,7 +83,7 @@ class PlayConnection(
) : Connection() { ) : Connection() {
val sessionId = KUtil.secureRandomUUID() val sessionId = KUtil.secureRandomUUID()
val settingsManager = ClientSettingsManager(this) val settingsManager = ClientSettingsManager(this)
val registries = Registries() val registries = Registries().apply { updateFlattened(version.flattened) }
val world = World(this) val world = World(this)
val tabList = TabList() val tabList = TabList()
val scoreboardManager = ScoreboardManager(this) val scoreboardManager = ScoreboardManager(this)