mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 03:44:54 -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
|
* 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.
|
* 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() {
|
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 {
|
object ContainerTestUtil {
|
||||||
private val container = ContainerType(minosoft("test"), factory = GenericContainerFactory)
|
private val container = ContainerType(minosoft("test"), factory = GenericContainerFactory)
|
||||||
private val chest = IT.VERSION.registries!!.containerTypeRegistry[Generic9x3Container]!!
|
private val chest = IT.REGISTRIES.containerTypeRegistry[Generic9x3Container]!!
|
||||||
private val furnace = IT.VERSION.registries!!.containerTypeRegistry[FurnaceContainer]!!
|
private val furnace = IT.REGISTRIES.containerTypeRegistry[FurnaceContainer]!!
|
||||||
|
|
||||||
|
|
||||||
init {
|
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) {
|
fun retrieveBlock(name: ResourceLocation) {
|
||||||
val block = IT.VERSION.registries!!.blockRegistry[name]
|
val block = IT.REGISTRIES.blockRegistry[name]
|
||||||
Assert.assertNotNull(block)
|
Assert.assertNotNull(block)
|
||||||
block!!
|
block!!
|
||||||
assertEquals(block.identifier, name)
|
assertEquals(block.identifier, name)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Minosoft
|
* 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.
|
* 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() {
|
fun integratedSharpness() {
|
||||||
val expected = WeaponEnchantment.Sharpness
|
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)
|
Assert.assertSame(current, expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun goldenApple() {
|
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) {
|
if (current !is AppleItem.GoldenAppleItem) {
|
||||||
Assert.fail("Not an golden apple: $current")
|
Assert.fail("Not an golden apple: $current")
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ abstract class ItemTest<T : Item> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun retrieveItem(name: ResourceLocation) {
|
fun retrieveItem(name: ResourceLocation) {
|
||||||
val item = IT.VERSION.registries!!.itemRegistry[name]
|
val item = IT.REGISTRIES.itemRegistry[name]
|
||||||
Assert.assertNotNull(item)
|
Assert.assertNotNull(item)
|
||||||
item!!
|
item!!
|
||||||
assertEquals(item.identifier, name)
|
assertEquals(item.identifier, name)
|
||||||
@ -39,7 +39,7 @@ abstract class ItemTest<T : Item> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun retrieveItem(factory: ItemFactory<T>) {
|
fun retrieveItem(factory: ItemFactory<T>) {
|
||||||
val item = IT.VERSION.registries!!.itemRegistry[factory]
|
val item = IT.REGISTRIES.itemRegistry[factory]
|
||||||
Assert.assertNotNull(item)
|
Assert.assertNotNull(item)
|
||||||
item!!
|
item!!
|
||||||
assertEquals(item.identifier, factory.identifier)
|
assertEquals(item.identifier, factory.identifier)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Minosoft
|
* 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.
|
* 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
|
package de.bixilon.minosoft.data.registries.versions
|
||||||
|
|
||||||
import de.bixilon.minosoft.data.entities.entities.monster.Zombie
|
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.blocks.MinecraftBlocks
|
||||||
import de.bixilon.minosoft.data.registries.item.MinecraftItems
|
import de.bixilon.minosoft.data.registries.item.MinecraftItems
|
||||||
import de.bixilon.minosoft.protocol.protocol.VersionSupport
|
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.protocol.versions.Versions
|
||||||
import de.bixilon.minosoft.test.ITUtil
|
import de.bixilon.minosoft.test.ITUtil
|
||||||
import org.testng.Assert
|
import org.testng.Assert
|
||||||
@ -26,10 +26,8 @@ import org.testng.annotations.Test
|
|||||||
@Test(groups = ["pixlyzer"], dependsOnGroups = ["version"], singleThreaded = false, threadPoolSize = 8)
|
@Test(groups = ["pixlyzer"], dependsOnGroups = ["version"], singleThreaded = false, threadPoolSize = 8)
|
||||||
class PixLyzerLoadingTest {
|
class PixLyzerLoadingTest {
|
||||||
|
|
||||||
private fun Version.test() {
|
private fun VersionRegistry.test() {
|
||||||
val registries = this.registries
|
val registries = this.registries
|
||||||
Assert.assertNotNull(this.registries)
|
|
||||||
registries!!
|
|
||||||
Assert.assertNotNull(registries.blockRegistry[MinecraftBlocks.DIRT])
|
Assert.assertNotNull(registries.blockRegistry[MinecraftBlocks.DIRT])
|
||||||
Assert.assertNotNull(registries.itemRegistry[MinecraftItems.COAL])
|
Assert.assertNotNull(registries.itemRegistry[MinecraftItems.COAL])
|
||||||
Assert.assertNotNull(registries.entityTypeRegistry[Zombie])
|
Assert.assertNotNull(registries.entityTypeRegistry[Zombie])
|
||||||
@ -102,7 +100,7 @@ class PixLyzerLoadingTest {
|
|||||||
fun latest() {
|
fun latest() {
|
||||||
val version = Versions.getById(VersionSupport.LATEST_VERSION)!!
|
val version = Versions.getById(VersionSupport.LATEST_VERSION)!!
|
||||||
println("Latest version $version")
|
println("Latest version $version")
|
||||||
ITUtil.loadPixlyzerData(version)
|
val registries = ITUtil.loadPixlyzerData(version)
|
||||||
version.test()
|
VersionRegistry(version, registries).test()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Minosoft
|
* 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.
|
* 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::account.forceSet(OfflineAccount("dummy"))
|
||||||
connection::version.forceSet(IT.VERSION)
|
connection::version.forceSet(IT.VERSION)
|
||||||
connection::registries.forceSet(Registries())
|
connection::registries.forceSet(Registries())
|
||||||
connection.registries.parentRegistries = IT.VERSION.registries
|
connection.registries.parent = IT.REGISTRIES
|
||||||
connection::world.forceSet(createWorld(connection))
|
connection::world.forceSet(createWorld(connection))
|
||||||
connection::player.forceSet(LocalPlayerEntity(connection.account, connection, null))
|
connection::player.forceSet(LocalPlayerEntity(connection.account, connection, null))
|
||||||
connection::network.forceSet(TestNetwork())
|
connection::network.forceSet(TestNetwork())
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Minosoft
|
* 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.
|
* 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
|
package de.bixilon.minosoft.test
|
||||||
|
|
||||||
import de.bixilon.kutil.cast.CastUtil.unsafeNull
|
import de.bixilon.kutil.cast.CastUtil.unsafeNull
|
||||||
|
import de.bixilon.minosoft.data.registries.registries.Registries
|
||||||
import de.bixilon.minosoft.protocol.versions.Version
|
import de.bixilon.minosoft.protocol.versions.Version
|
||||||
import org.objenesis.ObjenesisStd
|
import org.objenesis.ObjenesisStd
|
||||||
|
|
||||||
@ -21,6 +22,7 @@ object IT {
|
|||||||
val OBJENESIS = ObjenesisStd()
|
val OBJENESIS = ObjenesisStd()
|
||||||
const val TEST_VERSION_NAME = "1.18.2"
|
const val TEST_VERSION_NAME = "1.18.2"
|
||||||
var VERSION: Version = unsafeNull()
|
var VERSION: Version = unsafeNull()
|
||||||
|
var REGISTRIES: Registries = unsafeNull()
|
||||||
|
|
||||||
val references: MutableList<Any> = mutableListOf()
|
val references: MutableList<Any> = mutableListOf()
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Minosoft
|
* 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.
|
* 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.kutil.latch.CountUpAndDownLatch
|
||||||
import de.bixilon.minosoft.config.profile.profiles.resources.ResourcesProfile
|
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.Version
|
||||||
import de.bixilon.minosoft.protocol.versions.Versions
|
import de.bixilon.minosoft.protocol.versions.Versions
|
||||||
|
|
||||||
@ -25,18 +27,13 @@ object ITUtil {
|
|||||||
return ResourcesProfile()
|
return ResourcesProfile()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun loadPixlyzerData(name: String): Version {
|
fun loadPixlyzerData(name: String): VersionRegistry {
|
||||||
val version = Versions[name]!!
|
val version = Versions[name]!!
|
||||||
if (version.registries != null) {
|
val registries = loadPixlyzerData(version)
|
||||||
// already loaded
|
return VersionRegistry(version, registries)
|
||||||
return version
|
|
||||||
}
|
}
|
||||||
|
|
||||||
loadPixlyzerData(version)
|
fun loadPixlyzerData(version: Version): Registries {
|
||||||
return version
|
return version.load(profile, CountUpAndDownLatch(0))
|
||||||
}
|
|
||||||
|
|
||||||
fun loadPixlyzerData(version: Version) {
|
|
||||||
version.load(profile, CountUpAndDownLatch(0))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Minosoft
|
* 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.
|
* 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
|
import kotlin.reflect.jvm.javaField
|
||||||
|
|
||||||
|
|
||||||
class Registries {
|
class Registries : Parentable<Registries> {
|
||||||
val registries: MutableMap<ResourceLocation, AbstractRegistry<*>> = mutableMapOf()
|
val registries: MutableMap<ResourceLocation, AbstractRegistry<*>> = mutableMapOf()
|
||||||
var shapes: Array<VoxelShape> = emptyArray()
|
var shapes: Array<VoxelShape> = emptyArray()
|
||||||
val motifRegistry: Registry<Motif> = register("motif", Registry(codec = Motif))
|
val motifRegistry: Registry<Motif> = register("motif", Registry(codec = Motif))
|
||||||
@ -135,17 +135,19 @@ class Registries {
|
|||||||
private var isFlattened = false
|
private var isFlattened = false
|
||||||
|
|
||||||
|
|
||||||
var parentRegistries: Registries? = null
|
override var parent: Registries? = null
|
||||||
set(value) {
|
set(value) {
|
||||||
field = value
|
field = value
|
||||||
|
|
||||||
for (parentableField in PARENTABLE_FIELDS) {
|
for (field in PARENTABLE_FIELDS) {
|
||||||
PARENTABLE_SET_PARENT_METHOD(parentableField.get(this), value?.let { parentableField.get(it) })
|
val method = field.get(this) ?: continue
|
||||||
|
val value = value?.let { field.get(it) }
|
||||||
|
PARENTABLE_SET_PARENT_METHOD(method, value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getEntityDataIndex(field: EntityDataField): Int? {
|
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) {
|
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 })
|
val taskWorker = TaskWorker(errorHandler = { _, exception -> if (error == null) error = exception }, criticalErrorHandler = { _, exception -> if (error == null) error = exception })
|
||||||
taskWorker += {
|
taskWorker += {
|
||||||
events.fire(RegistriesLoadEvent(this, registries, RegistriesLoadEvent.States.PRE))
|
events.fire(RegistriesLoadEvent(this, registries, RegistriesLoadEvent.States.PRE))
|
||||||
version.load(profiles.resources, latch)
|
registries.parent = version.load(profiles.resources, latch)
|
||||||
registries.parentRegistries = version.registries
|
|
||||||
events.fire(RegistriesLoadEvent(this, registries, RegistriesLoadEvent.States.POST))
|
events.fire(RegistriesLoadEvent(this, registries, RegistriesLoadEvent.States.POST))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,7 +229,6 @@ class PlayConnection(
|
|||||||
state = PlayConnectionStates.ESTABLISHING
|
state = PlayConnectionStates.ESTABLISHING
|
||||||
} catch (exception: Throwable) {
|
} catch (exception: Throwable) {
|
||||||
Log.log(LogMessageType.VERSION_LOADING, level = LogLevels.FATAL) { exception }
|
Log.log(LogMessageType.VERSION_LOADING, level = LogLevels.FATAL) { exception }
|
||||||
version.unload()
|
|
||||||
if (this::assetsManager.isInitialized) {
|
if (this::assetsManager.isInitialized) {
|
||||||
assetsManager.unload()
|
assetsManager.unload()
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Minosoft
|
* 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.
|
* 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 c2sPackets: Map<ProtocolStates, AbstractBiMap<C2SPacketType, Int>>,
|
||||||
) {
|
) {
|
||||||
val sortingId: Int = (versionId == -1).decide(Int.MAX_VALUE, versionId)
|
val sortingId: Int = (versionId == -1).decide(Int.MAX_VALUE, versionId)
|
||||||
var registries: Registries? = null
|
|
||||||
private set
|
|
||||||
|
|
||||||
|
|
||||||
@Synchronized
|
fun load(profile: ResourcesProfile, latch: CountUpAndDownLatch): Registries {
|
||||||
fun load(profile: ResourcesProfile, latch: CountUpAndDownLatch) {
|
return RegistriesLoader.load(profile, this, latch)
|
||||||
if (registries != null) {
|
|
||||||
// already loaded
|
|
||||||
return
|
|
||||||
}
|
|
||||||
registries = RegistriesLoader.load(profile, this, latch)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Synchronized
|
|
||||||
fun unload() {
|
|
||||||
this.registries = null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user