mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 11:24:56 -04:00
shape registry
This commit is contained in:
parent
b0d81accd8
commit
04810df14e
@ -107,9 +107,9 @@ data class BlockState(
|
||||
|
||||
fun Any.asShape(): VoxelShape {
|
||||
return if (this is Int) {
|
||||
registries.shapes[this]
|
||||
registries.shape[this]
|
||||
} else {
|
||||
VoxelShape(registries.shapes, this)
|
||||
VoxelShape(registries.shape, this)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,6 @@
|
||||
*/
|
||||
package de.bixilon.minosoft.data.registries.registries
|
||||
|
||||
import de.bixilon.kutil.array.ArrayUtil.cast
|
||||
import de.bixilon.kutil.cast.CastUtil.unsafeCast
|
||||
import de.bixilon.kutil.concurrent.pool.DefaultThreadPool
|
||||
import de.bixilon.kutil.concurrent.worker.task.TaskWorker
|
||||
@ -54,8 +53,7 @@ import de.bixilon.minosoft.data.registries.materials.Material
|
||||
import de.bixilon.minosoft.data.registries.misc.MiscData
|
||||
import de.bixilon.minosoft.data.registries.particle.ParticleType
|
||||
import de.bixilon.minosoft.data.registries.registries.registry.*
|
||||
import de.bixilon.minosoft.data.registries.shapes.AABB
|
||||
import de.bixilon.minosoft.data.registries.shapes.VoxelShape
|
||||
import de.bixilon.minosoft.data.registries.shapes.ShapeRegistry
|
||||
import de.bixilon.minosoft.data.registries.sound.SoundGroup
|
||||
import de.bixilon.minosoft.data.registries.statistics.Statistic
|
||||
import de.bixilon.minosoft.datafixer.enumeration.EntityDataTypesFixer
|
||||
@ -77,7 +75,9 @@ import kotlin.reflect.jvm.javaField
|
||||
|
||||
class Registries : Parentable<Registries> {
|
||||
val registries: MutableMap<ResourceLocation, AbstractRegistry<*>> = mutableMapOf()
|
||||
var shapes: Array<VoxelShape> = emptyArray()
|
||||
|
||||
val shape = ShapeRegistry()
|
||||
|
||||
val motif: Registry<Motif> = register("motif", Registry(codec = Motif))
|
||||
val block: Registry<Block> = register("block", Registry(flattened = true, codec = Block, metaType = MetaTypes.BLOCKS))
|
||||
val item: ItemRegistry = register("item", ItemRegistry())
|
||||
@ -160,7 +160,7 @@ class Registries : Parentable<Registries> {
|
||||
val worker = TaskWorker(errorHandler = { _, it -> if (error == null) error = it }, criticalErrorHandler = { _, it -> if (error == null) error = it })
|
||||
val stopwatch = Stopwatch()
|
||||
// enums
|
||||
worker += WorkerTask(this::shapes) { loadShapes(pixlyzerData["shapes"]?.toJsonObject()) }
|
||||
worker += WorkerTask(this::shape) { this.shape.load(pixlyzerData["shapes"]?.toJsonObject()) }
|
||||
|
||||
worker += WorkerTask(this::equipmentSlot) { equipmentSlot.initialize(pixlyzerData["equipment_slots"]) }
|
||||
worker += WorkerTask(this::handEquipmentSlot) { handEquipmentSlot.initialize(pixlyzerData["hand_equipment_slots"]) }
|
||||
@ -194,7 +194,7 @@ class Registries : Parentable<Registries> {
|
||||
worker += WorkerTask(this::biome) { biome.rawUpdate(pixlyzerData["biomes"]?.toJsonObject(), this) }
|
||||
worker += WorkerTask(this::dimension) { dimension.rawUpdate(pixlyzerData["dimensions"]?.toJsonObject(), this) }
|
||||
worker += WorkerTask(this::fluid) { fluid.rawUpdate(pixlyzerData["fluids"]?.toJsonObject(), this) }
|
||||
worker += WorkerTask(this::block, dependencies = arrayOf(this::material, this::fluid, this::shapes, this::soundGroup, this::particleType)) { block.rawUpdate(pixlyzerData["blocks"]?.toJsonObject(), this) }
|
||||
worker += WorkerTask(this::block, dependencies = arrayOf(this::material, this::fluid, this::shape, this::soundGroup, this::particleType)) { block.rawUpdate(pixlyzerData["blocks"]?.toJsonObject(), this) }
|
||||
worker += WorkerTask(this::item, dependencies = arrayOf(this::material, this::block, this::entityType, this::fluid, this::statusEffect, this::soundEvent)) { item.rawUpdate(pixlyzerData["items"]?.toJsonObject(), this) }
|
||||
|
||||
worker += WorkerTask(this::blockEntityType, dependencies = arrayOf(this::block)) { blockEntityType.rawUpdate(pixlyzerData["block_entities"]?.toJsonObject(), this) }
|
||||
@ -232,30 +232,10 @@ class Registries : Parentable<Registries> {
|
||||
inner.dec()
|
||||
inner.await()
|
||||
isFullyLoaded = true
|
||||
shapes = emptyArray()
|
||||
shape.cleanup()
|
||||
Log.log(LogMessageType.VERSION_LOADING, LogLevels.INFO) { "Registries for $version loaded in ${stopwatch.totalTime()}" }
|
||||
}
|
||||
|
||||
private fun loadShapes(data: Map<String, Any>?) {
|
||||
data ?: return
|
||||
val aabbs = loadAABBs(data["aabbs"].unsafeCast())
|
||||
loadVoxelShapes(data["shapes"].unsafeCast(), aabbs)
|
||||
}
|
||||
|
||||
private fun loadVoxelShapes(data: Collection<Any>, aabbs: Array<AABB>) {
|
||||
this.shapes = arrayOfNulls<VoxelShape>(data.size).cast()
|
||||
for ((index, shape) in data.withIndex()) {
|
||||
this.shapes[index] = VoxelShape(shape, aabbs)
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadAABBs(data: Collection<Map<String, Any>>): Array<AABB> {
|
||||
val aabbs: Array<AABB?> = arrayOfNulls(data.size)
|
||||
for ((index, aabb) in data.withIndex()) {
|
||||
aabbs[index] = AABB(aabb)
|
||||
}
|
||||
return aabbs.cast()
|
||||
}
|
||||
|
||||
fun clear() {
|
||||
for (field in this::class.java.fields) {
|
||||
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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.shapes
|
||||
|
||||
import de.bixilon.kutil.array.ArrayUtil.cast
|
||||
import de.bixilon.kutil.cast.CastUtil.unsafeCast
|
||||
import de.bixilon.kutil.json.JsonObject
|
||||
|
||||
class ShapeRegistry {
|
||||
private var shapes: Array<VoxelShape> = emptyArray()
|
||||
|
||||
fun load(data: JsonObject?) {
|
||||
if (data == null) {
|
||||
return
|
||||
}
|
||||
val aabbs = loadAABBs(data["aabbs"].unsafeCast())
|
||||
loadShapes(data["shapes"].unsafeCast(), aabbs)
|
||||
}
|
||||
|
||||
private fun loadShapes(data: Collection<Any>, aabbs: Array<AABB>) {
|
||||
this.shapes = arrayOfNulls<VoxelShape>(data.size).cast()
|
||||
|
||||
for ((index, shape) in data.withIndex()) {
|
||||
this.shapes[index] = VoxelShape(shape, aabbs)
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadAABBs(data: Collection<Map<String, Any>>): Array<AABB> {
|
||||
val aabbs: Array<AABB?> = arrayOfNulls(data.size)
|
||||
|
||||
for ((index, aabb) in data.withIndex()) {
|
||||
aabbs[index] = AABB(aabb)
|
||||
}
|
||||
return aabbs.cast()
|
||||
}
|
||||
|
||||
fun cleanup() {
|
||||
this.shapes = emptyArray()
|
||||
}
|
||||
|
||||
|
||||
operator fun get(index: Int): VoxelShape {
|
||||
return shapes[index]
|
||||
}
|
||||
}
|
@ -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.
|
||||
*
|
||||
@ -46,7 +46,7 @@ class VoxelShape(private val aabbs: MutableList<AABB> = mutableListOf()) : Itera
|
||||
}
|
||||
|
||||
// somehow, the kotlin compiler gives an error if both constructors have the "same" signature JsonElement, List<>
|
||||
constructor(voxelShapes: Array<VoxelShape>, data: Any) : this() {
|
||||
constructor(voxelShapes: ShapeRegistry, data: Any) : this() {
|
||||
when (data) {
|
||||
is Collection<*> -> {
|
||||
for (index in data) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user