mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 03:15:35 -04:00
version: remove registries
This fixes a design issue when using different render contexts in the same version
This commit is contained in:
parent
4a7b834100
commit
14db02194a
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
* Copyright (C) 2020-2023 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
@ -76,6 +76,8 @@ internal object MinosoftSIT {
|
||||
}
|
||||
|
||||
fun loadPixlyzerData() {
|
||||
IT.VERSION = ITUtil.loadPixlyzerData(IT.TEST_VERSION_NAME)
|
||||
val (version, registries) = ITUtil.loadPixlyzerData(IT.TEST_VERSION_NAME)
|
||||
IT.VERSION = version
|
||||
IT.REGISTRIES = registries
|
||||
}
|
||||
}
|
||||
|
@ -28,8 +28,8 @@ import de.bixilon.minosoft.util.KUtil.minosoft
|
||||
|
||||
object ContainerTestUtil {
|
||||
private val container = ContainerType(minosoft("test"), factory = GenericContainerFactory)
|
||||
private val chest = IT.VERSION.registries!!.containerTypeRegistry[Generic9x3Container]!!
|
||||
private val furnace = IT.VERSION.registries!!.containerTypeRegistry[FurnaceContainer]!!
|
||||
private val chest = IT.REGISTRIES.containerTypeRegistry[Generic9x3Container]!!
|
||||
private val furnace = IT.REGISTRIES.containerTypeRegistry[FurnaceContainer]!!
|
||||
|
||||
|
||||
init {
|
||||
|
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2023 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.data.registries
|
||||
|
||||
import de.bixilon.minosoft.data.registries.registries.Registries
|
||||
import de.bixilon.minosoft.protocol.versions.Version
|
||||
|
||||
data class VersionRegistry(
|
||||
val version: Version,
|
||||
val registries: Registries,
|
||||
)
|
@ -32,7 +32,7 @@ abstract class BlockTest<T : Block> {
|
||||
}
|
||||
|
||||
fun retrieveBlock(name: ResourceLocation) {
|
||||
val block = IT.VERSION.registries!!.blockRegistry[name]
|
||||
val block = IT.REGISTRIES.blockRegistry[name]
|
||||
Assert.assertNotNull(block)
|
||||
block!!
|
||||
assertEquals(block.identifier, name)
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
* Copyright (C) 2020-2023 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
@ -25,12 +25,12 @@ class IntegratedRegistryIT {
|
||||
|
||||
fun integratedSharpness() {
|
||||
val expected = WeaponEnchantment.Sharpness
|
||||
val current = IT.VERSION.registries!!.enchantmentRegistry["minecraft:sharpness".toResourceLocation()]
|
||||
val current = IT.REGISTRIES.enchantmentRegistry["minecraft:sharpness".toResourceLocation()]
|
||||
Assert.assertSame(current, expected)
|
||||
}
|
||||
|
||||
fun goldenApple() {
|
||||
val current = IT.VERSION.registries!!.itemRegistry["minecraft:golden_apple".toResourceLocation()]
|
||||
val current = IT.REGISTRIES.itemRegistry["minecraft:golden_apple".toResourceLocation()]
|
||||
if (current !is AppleItem.GoldenAppleItem) {
|
||||
Assert.fail("Not an golden apple: $current")
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ abstract class ItemTest<T : Item> {
|
||||
}
|
||||
|
||||
fun retrieveItem(name: ResourceLocation) {
|
||||
val item = IT.VERSION.registries!!.itemRegistry[name]
|
||||
val item = IT.REGISTRIES.itemRegistry[name]
|
||||
Assert.assertNotNull(item)
|
||||
item!!
|
||||
assertEquals(item.identifier, name)
|
||||
@ -39,7 +39,7 @@ abstract class ItemTest<T : Item> {
|
||||
}
|
||||
|
||||
fun retrieveItem(factory: ItemFactory<T>) {
|
||||
val item = IT.VERSION.registries!!.itemRegistry[factory]
|
||||
val item = IT.REGISTRIES.itemRegistry[factory]
|
||||
Assert.assertNotNull(item)
|
||||
item!!
|
||||
assertEquals(item.identifier, factory.identifier)
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
* Copyright (C) 2020-2023 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
@ -14,10 +14,10 @@
|
||||
package de.bixilon.minosoft.data.registries.versions
|
||||
|
||||
import de.bixilon.minosoft.data.entities.entities.monster.Zombie
|
||||
import de.bixilon.minosoft.data.registries.VersionRegistry
|
||||
import de.bixilon.minosoft.data.registries.blocks.MinecraftBlocks
|
||||
import de.bixilon.minosoft.data.registries.item.MinecraftItems
|
||||
import de.bixilon.minosoft.protocol.protocol.VersionSupport
|
||||
import de.bixilon.minosoft.protocol.versions.Version
|
||||
import de.bixilon.minosoft.protocol.versions.Versions
|
||||
import de.bixilon.minosoft.test.ITUtil
|
||||
import org.testng.Assert
|
||||
@ -26,10 +26,8 @@ import org.testng.annotations.Test
|
||||
@Test(groups = ["pixlyzer"], dependsOnGroups = ["version"], singleThreaded = false, threadPoolSize = 8)
|
||||
class PixLyzerLoadingTest {
|
||||
|
||||
private fun Version.test() {
|
||||
private fun VersionRegistry.test() {
|
||||
val registries = this.registries
|
||||
Assert.assertNotNull(this.registries)
|
||||
registries!!
|
||||
Assert.assertNotNull(registries.blockRegistry[MinecraftBlocks.DIRT])
|
||||
Assert.assertNotNull(registries.itemRegistry[MinecraftItems.COAL])
|
||||
Assert.assertNotNull(registries.entityTypeRegistry[Zombie])
|
||||
@ -102,7 +100,7 @@ class PixLyzerLoadingTest {
|
||||
fun latest() {
|
||||
val version = Versions.getById(VersionSupport.LATEST_VERSION)!!
|
||||
println("Latest version $version")
|
||||
ITUtil.loadPixlyzerData(version)
|
||||
version.test()
|
||||
val registries = ITUtil.loadPixlyzerData(version)
|
||||
VersionRegistry(version, registries).test()
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
* Copyright (C) 2020-2023 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
@ -39,7 +39,7 @@ object ConnectionTestUtil {
|
||||
connection::account.forceSet(OfflineAccount("dummy"))
|
||||
connection::version.forceSet(IT.VERSION)
|
||||
connection::registries.forceSet(Registries())
|
||||
connection.registries.parentRegistries = IT.VERSION.registries
|
||||
connection.registries.parent = IT.REGISTRIES
|
||||
connection::world.forceSet(createWorld(connection))
|
||||
connection::player.forceSet(LocalPlayerEntity(connection.account, connection, null))
|
||||
connection::network.forceSet(TestNetwork())
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
* Copyright (C) 2020-2023 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
@ -14,6 +14,7 @@
|
||||
package de.bixilon.minosoft.test
|
||||
|
||||
import de.bixilon.kutil.cast.CastUtil.unsafeNull
|
||||
import de.bixilon.minosoft.data.registries.registries.Registries
|
||||
import de.bixilon.minosoft.protocol.versions.Version
|
||||
import org.objenesis.ObjenesisStd
|
||||
|
||||
@ -21,6 +22,7 @@ object IT {
|
||||
val OBJENESIS = ObjenesisStd()
|
||||
const val TEST_VERSION_NAME = "1.18.2"
|
||||
var VERSION: Version = unsafeNull()
|
||||
var REGISTRIES: Registries = unsafeNull()
|
||||
|
||||
val references: MutableList<Any> = mutableListOf()
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
* Copyright (C) 2020-2023 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
@ -15,6 +15,8 @@ package de.bixilon.minosoft.test
|
||||
|
||||
import de.bixilon.kutil.latch.CountUpAndDownLatch
|
||||
import de.bixilon.minosoft.config.profile.profiles.resources.ResourcesProfile
|
||||
import de.bixilon.minosoft.data.registries.VersionRegistry
|
||||
import de.bixilon.minosoft.data.registries.registries.Registries
|
||||
import de.bixilon.minosoft.protocol.versions.Version
|
||||
import de.bixilon.minosoft.protocol.versions.Versions
|
||||
|
||||
@ -25,18 +27,13 @@ object ITUtil {
|
||||
return ResourcesProfile()
|
||||
}
|
||||
|
||||
fun loadPixlyzerData(name: String): Version {
|
||||
fun loadPixlyzerData(name: String): VersionRegistry {
|
||||
val version = Versions[name]!!
|
||||
if (version.registries != null) {
|
||||
// already loaded
|
||||
return version
|
||||
}
|
||||
|
||||
loadPixlyzerData(version)
|
||||
return version
|
||||
val registries = loadPixlyzerData(version)
|
||||
return VersionRegistry(version, registries)
|
||||
}
|
||||
|
||||
fun loadPixlyzerData(version: Version) {
|
||||
version.load(profile, CountUpAndDownLatch(0))
|
||||
fun loadPixlyzerData(version: Version): Registries {
|
||||
return version.load(profile, CountUpAndDownLatch(0))
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
* Copyright (C) 2020-2023 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
@ -75,7 +75,7 @@ import java.lang.reflect.Field
|
||||
import kotlin.reflect.jvm.javaField
|
||||
|
||||
|
||||
class Registries {
|
||||
class Registries : Parentable<Registries> {
|
||||
val registries: MutableMap<ResourceLocation, AbstractRegistry<*>> = mutableMapOf()
|
||||
var shapes: Array<VoxelShape> = emptyArray()
|
||||
val motifRegistry: Registry<Motif> = register("motif", Registry(codec = Motif))
|
||||
@ -135,17 +135,19 @@ class Registries {
|
||||
private var isFlattened = false
|
||||
|
||||
|
||||
var parentRegistries: Registries? = null
|
||||
override var parent: Registries? = null
|
||||
set(value) {
|
||||
field = value
|
||||
|
||||
for (parentableField in PARENTABLE_FIELDS) {
|
||||
PARENTABLE_SET_PARENT_METHOD(parentableField.get(this), value?.let { parentableField.get(it) })
|
||||
for (field in PARENTABLE_FIELDS) {
|
||||
val method = field.get(this) ?: continue
|
||||
val value = value?.let { field.get(it) }
|
||||
PARENTABLE_SET_PARENT_METHOD(method, value)
|
||||
}
|
||||
}
|
||||
|
||||
fun getEntityDataIndex(field: EntityDataField): Int? {
|
||||
return entityDataIndexMap[field] ?: parentRegistries?.getEntityDataIndex(field)
|
||||
return entityDataIndexMap[field] ?: parent?.getEntityDataIndex(field)
|
||||
}
|
||||
|
||||
fun load(version: Version, pixlyzerData: Map<String, Any>, latch: CountUpAndDownLatch) {
|
||||
|
@ -183,8 +183,7 @@ class PlayConnection(
|
||||
val taskWorker = TaskWorker(errorHandler = { _, exception -> if (error == null) error = exception }, criticalErrorHandler = { _, exception -> if (error == null) error = exception })
|
||||
taskWorker += {
|
||||
events.fire(RegistriesLoadEvent(this, registries, RegistriesLoadEvent.States.PRE))
|
||||
version.load(profiles.resources, latch)
|
||||
registries.parentRegistries = version.registries
|
||||
registries.parent = version.load(profiles.resources, latch)
|
||||
events.fire(RegistriesLoadEvent(this, registries, RegistriesLoadEvent.States.POST))
|
||||
}
|
||||
|
||||
@ -230,7 +229,6 @@ class PlayConnection(
|
||||
state = PlayConnectionStates.ESTABLISHING
|
||||
} catch (exception: Throwable) {
|
||||
Log.log(LogMessageType.VERSION_LOADING, level = LogLevels.FATAL) { exception }
|
||||
version.unload()
|
||||
if (this::assetsManager.isInitialized) {
|
||||
assetsManager.unload()
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
* Copyright (C) 2020-2023 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
@ -35,22 +35,10 @@ class Version(
|
||||
val c2sPackets: Map<ProtocolStates, AbstractBiMap<C2SPacketType, Int>>,
|
||||
) {
|
||||
val sortingId: Int = (versionId == -1).decide(Int.MAX_VALUE, versionId)
|
||||
var registries: Registries? = null
|
||||
private set
|
||||
|
||||
|
||||
@Synchronized
|
||||
fun load(profile: ResourcesProfile, latch: CountUpAndDownLatch) {
|
||||
if (registries != null) {
|
||||
// already loaded
|
||||
return
|
||||
}
|
||||
registries = RegistriesLoader.load(profile, this, latch)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun unload() {
|
||||
this.registries = null
|
||||
fun load(profile: ResourcesProfile, latch: CountUpAndDownLatch): Registries {
|
||||
return RegistriesLoader.load(profile, this, latch)
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
|
Loading…
x
Reference in New Issue
Block a user