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::version.forceSet(version)
connection::registries.forceSet(Registries())
connection.registries.updateFlattened(version.flattened)
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::player.forceSet(LocalPlayerEntity(connection.account, connection, SignatureKeyManagement(connection, TestAccount)))

View File

@ -132,8 +132,6 @@ class Registries(
var isFullyLoaded = false
private set
private var isFlattened = false
override var parent: Registries? = null
set(value) {
@ -146,11 +144,15 @@ class Registries(
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) {
isFlattened = version.flattened
block.flattened = isFlattened
blockState.flattened = isFlattened
item.flattened = isFlattened
updateFlattened(version.flattened)
var error: Throwable? = null
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? {
val state = _get(id)
if (state != null) return state
if (flattened) return null
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")
override fun getOrNull(id: Int): BlockState? {
if (id == ProtocolDefinition.AIR_BLOCK_ID) {
return null
if (flattened) {
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
if (state.block is AirBlock) {
return null

View File

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