mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-13 09:26:11 -04:00
registry iterator
This commit is contained in:
parent
25a89cc8f7
commit
b55d24ca89
@ -587,8 +587,8 @@ abstract class Entity(
|
||||
return // ToDo
|
||||
}
|
||||
|
||||
connection.registries.fluidRegistry.forEachItem {
|
||||
updateFluidState(it.resourceLocation)
|
||||
for (fluid in connection.registries.fluidRegistry) {
|
||||
updateFluidState(fluid.resourceLocation)
|
||||
}
|
||||
|
||||
submergedFluid = null
|
||||
|
@ -23,4 +23,10 @@ interface AbstractRegistry<T> : Iterable<T>, Clearable, Parentable<AbstractRegis
|
||||
operator fun get(id: Int): T?
|
||||
|
||||
fun getId(value: T): Int
|
||||
|
||||
fun noParentIterator(): Iterator<T>
|
||||
|
||||
override fun iterator(): Iterator<T> {
|
||||
return RegistryIterator(this)
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ package de.bixilon.minosoft.data.registries.registries.registry
|
||||
|
||||
import de.bixilon.minosoft.data.registries.blocks.BlockState
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
||||
import de.bixilon.minosoft.util.KUtil.toSynchronizedMap
|
||||
|
||||
class BlockStateRegistry(var flattened: Boolean) : AbstractRegistry<BlockState?> {
|
||||
override var parent: AbstractRegistry<BlockState?>? = null
|
||||
@ -30,8 +29,8 @@ class BlockStateRegistry(var flattened: Boolean) : AbstractRegistry<BlockState?>
|
||||
return value
|
||||
}
|
||||
|
||||
override fun iterator(): Iterator<BlockState> {
|
||||
return idMap.toSynchronizedMap().values.iterator()
|
||||
override fun noParentIterator(): Iterator<BlockState?> {
|
||||
return idMap.values.iterator()
|
||||
}
|
||||
|
||||
override fun clear() {
|
||||
|
@ -19,7 +19,6 @@ import de.bixilon.minosoft.data.registries.MultiResourceLocationAble
|
||||
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||
import de.bixilon.minosoft.data.registries.ResourceLocationAble
|
||||
import de.bixilon.minosoft.data.registries.registries.Registries
|
||||
import de.bixilon.minosoft.util.KUtil.nullCast
|
||||
import de.bixilon.minosoft.util.KUtil.toInt
|
||||
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
||||
import de.bixilon.minosoft.util.json.ResourceLocationJsonMap.toResourceLocationMap
|
||||
@ -171,14 +170,6 @@ open class Registry<T : RegistryItem>(
|
||||
this.valueIdMap.putAll(valueIdMap)
|
||||
}
|
||||
|
||||
@Deprecated("Too slow, should be used with a ToDo: RegistryIterator")
|
||||
fun forEachItem(lambda: (T) -> Unit) {
|
||||
for (item in resourceLocationMap.values) {
|
||||
lambda(item)
|
||||
}
|
||||
parent.nullCast<Registry<T>>()?.forEachItem(lambda)
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return super.toString() + ": ${resourceLocationMap.size}x"
|
||||
}
|
||||
@ -195,8 +186,7 @@ open class Registry<T : RegistryItem>(
|
||||
BITS_16,
|
||||
}
|
||||
|
||||
@Deprecated("TODO")
|
||||
override fun iterator(): Iterator<T> {
|
||||
override fun noParentIterator(): Iterator<T> {
|
||||
return resourceLocationMap.values.iterator()
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,21 @@
|
||||
package de.bixilon.minosoft.data.registries.registries.registry
|
||||
|
||||
class RegistryIterator<T>(
|
||||
private var registry: AbstractRegistry<T>,
|
||||
) : Iterator<T> {
|
||||
private var iterator = registry.noParentIterator()
|
||||
|
||||
override fun hasNext(): Boolean {
|
||||
val hasNext = iterator.hasNext()
|
||||
if (hasNext) {
|
||||
return true
|
||||
}
|
||||
registry = registry.parent ?: return false
|
||||
iterator = registry.noParentIterator()
|
||||
return iterator.hasNext()
|
||||
}
|
||||
|
||||
override fun next(): T {
|
||||
return iterator.next()
|
||||
}
|
||||
}
|
@ -74,8 +74,7 @@ class ResourceLocationRegistry(
|
||||
return super.toString() + ": ${idValueMap.size}x"
|
||||
}
|
||||
|
||||
@Deprecated("TODO")
|
||||
override fun iterator(): Iterator<ResourceLocation> {
|
||||
override fun noParentIterator(): Iterator<ResourceLocation> {
|
||||
return idValueMap.values.iterator()
|
||||
}
|
||||
}
|
||||
|
@ -88,12 +88,12 @@ class ModelLoader(
|
||||
fun load() {
|
||||
// ToDo: Optimize performance
|
||||
Log.log(LogMessageType.VERSION_LOADING, LogLevels.VERBOSE) { "Loading block models..." }
|
||||
registry.blockRegistry.forEachItem {
|
||||
loadBlockStates(it)
|
||||
for (block in registry.blockRegistry) {
|
||||
loadBlockStates(block)
|
||||
}
|
||||
Log.log(LogMessageType.VERSION_LOADING, LogLevels.VERBOSE) { "Loading item models..." }
|
||||
registry.itemRegistry.forEachItem {
|
||||
loadItemModel(it.resourceLocation.prefix("item/"))
|
||||
for (item in registry.itemRegistry) {
|
||||
loadItemModel(item.resourceLocation.prefix("item/"))
|
||||
}
|
||||
Log.log(LogMessageType.VERSION_LOADING, LogLevels.VERBOSE) { "Done loading unbaked models!" }
|
||||
|
||||
|
@ -118,8 +118,8 @@ class ParticleRenderer(
|
||||
|
||||
transparentMesh.load()
|
||||
translucentMesh.load()
|
||||
connection.registries.particleTypeRegistry.forEachItem {
|
||||
for (resourceLocation in it.textures) {
|
||||
for (particle in connection.registries.particleTypeRegistry) {
|
||||
for (resourceLocation in particle.textures) {
|
||||
renderWindow.textureManager.staticTextures.createTexture(resourceLocation)
|
||||
}
|
||||
}
|
||||
|
@ -13,10 +13,6 @@
|
||||
|
||||
package de.bixilon.minosoft.gui.rendering.world
|
||||
|
||||
import de.bixilon.minosoft.assets.properties.version.AssetsVersionProperties
|
||||
import de.bixilon.minosoft.assets.util.FileAssetsUtil
|
||||
import de.bixilon.minosoft.assets.util.FileUtil
|
||||
import de.bixilon.minosoft.assets.util.FileUtil.readArchive
|
||||
import de.bixilon.minosoft.config.key.KeyAction
|
||||
import de.bixilon.minosoft.config.key.KeyBinding
|
||||
import de.bixilon.minosoft.config.key.KeyCodes
|
||||
@ -129,16 +125,14 @@ class WorldRenderer(
|
||||
val preparingTasksSize: Int by preparingTasks::size
|
||||
|
||||
override fun init() {
|
||||
val asset = AssetsVersionProperties[connection.version]!!
|
||||
val zip = FileUtil.readFile(FileAssetsUtil.getPath(asset.jarAssetsHash)).readArchive()
|
||||
val modelLoader = ModelLoader(renderWindow)
|
||||
modelLoader.load()
|
||||
|
||||
connection.registries.fluidRegistry.forEachItem {
|
||||
if (it is FlowableFluid) {
|
||||
it.flowingTexture = renderWindow.textureManager.staticTextures.createTexture(it.flowingTextureName!!.texture())
|
||||
for (fluid in connection.registries.fluidRegistry) {
|
||||
if (fluid is FlowableFluid) {
|
||||
fluid.flowingTexture = renderWindow.textureManager.staticTextures.createTexture(fluid.flowingTextureName!!.texture())
|
||||
}
|
||||
it.stillTexture = it.stillTextureName?.let { texture -> renderWindow.textureManager.staticTextures.createTexture(texture.texture()) }
|
||||
fluid.stillTexture = fluid.stillTextureName?.let { texture -> renderWindow.textureManager.staticTextures.createTexture(texture.texture()) }
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user