load minosoft meta, fixes

This commit is contained in:
Moritz Zwerger 2023-10-06 00:18:07 +02:00
parent 24f09194b5
commit 37389b3bfc
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
8 changed files with 49 additions and 17 deletions

View File

@ -13,42 +13,70 @@
package de.bixilon.minosoft.assets.meta
import de.bixilon.kutil.cast.CastUtil.unsafeCast
import de.bixilon.kutil.cast.CastUtil.unsafeNull
import de.bixilon.kutil.json.JsonObject
import de.bixilon.kutil.string.StringUtil.formatPlaceholder
import de.bixilon.kutil.url.URLUtil.toURL
import de.bixilon.mbf.MBFBinaryReader
import de.bixilon.minosoft.Minosoft
import de.bixilon.minosoft.assets.util.FileAssetsTypes
import de.bixilon.minosoft.assets.util.FileAssetsUtil
import de.bixilon.minosoft.assets.util.HashTypes
import de.bixilon.minosoft.assets.util.InputStreamUtil.readJson
import de.bixilon.minosoft.assets.util.InputStreamUtil.readJsonObject
import de.bixilon.minosoft.config.profile.profiles.resources.ResourcesProfile
import de.bixilon.minosoft.data.registries.identified.Namespaces.minosoft
import de.bixilon.minosoft.protocol.versions.Version
import de.bixilon.minosoft.protocol.versions.Versions
import java.io.FileInputStream
import java.io.ByteArrayInputStream
object MinosoftMeta {
private val INDEX = minosoft("mapping/minosoft-meta.json")
var root: MetaRoot = unsafeNull()
private set
fun load() {
val file = FileInputStream("/home/moritz/git/gitlab.bixilon.de/bixilon/minosoft-meta/index.json")
this.root = file.readJson<MetaRoot>()
this.root = Minosoft.MINOSOFT_ASSETS_MANAGER[INDEX].readJson<MetaRoot>()
}
private fun MetaVersionEntry.load(type: String): JsonObject {
val file = FileInputStream("/home/moritz/git/gitlab.bixilon.de/bixilon/minosoft-meta/${this.version}/$type.json")
return file.readJsonObject()
private fun ByteArray.load(): JsonObject {
return MBFBinaryReader(ByteArrayInputStream(this)).readMBF().data.unsafeCast()
}
fun MetaTypeEntry.load(type: String, version: Version): JsonObject? {
private fun MetaVersionEntry.load(profile: ResourcesProfile): JsonObject {
FileAssetsUtil.readOrNull(this.hash, FileAssetsTypes.META, compress = false)?.let { return it.load() }
val data = FileAssetsUtil.read(profile.source.minosoftMeta.formatPlaceholder(
"hashPrefix" to hash.substring(0, 2),
"fullHash" to hash,
).toURL().openStream(), type = FileAssetsTypes.META, compress = false, hash = HashTypes.SHA256)
if (data.hash != hash) {
throw IllegalStateException("Pixlyzer data mismatch (expected=$hash, hash=${data.hash}!")
}
return data.data.load()
}
fun MetaTypeEntry.load(profile: ResourcesProfile, version: Version): JsonObject? {
var previous: MetaVersionEntry? = null
var previousVersion: Version? = null
for (entry in this) {
if (entry.version == "_") {
previous = entry
continue
}
val entryVersion = Versions[entry.version] ?: throw IllegalArgumentException("Unknown meta version ${entry.version}")
if (entryVersion > version) break
previous = entry
if (entryVersion > version) continue
if (previousVersion != null && previousVersion > entryVersion) {
continue
}
previousVersion = entryVersion
}
if (previous == null) return null
return previous.load(type)
return previous.load(profile)
}
}

View File

@ -33,7 +33,7 @@ object PreFlattening {
// val worker = UnconditionalWorker()
for ((type, data) in MinosoftMeta.root) {
// worker += { data.load(type, version) }
json[type] = data.load(type, version) ?: continue
json[type] = data.load(profile, version) ?: continue
}
// worker.work(latch)

View File

@ -18,6 +18,7 @@ object FileAssetsTypes {
const val SKINS = "skins"
const val SOUNDS = "sounds"
const val PIXLYZER = "pixlyzer"
const val META = "meta"
const val FAVICON = "favicon"
}

View File

@ -18,6 +18,7 @@ import de.bixilon.minosoft.config.profile.profiles.resources.ResourcesProfile
class SourceC(profile: ResourcesProfile) {
var pixlyzer by StringDelegate(profile, "https://gitlab.bixilon.de/bixilon/pixlyzer-data/-/raw/master/hash/\${hashPrefix}/\${fullHash}.mbf?inline=false")
var minosoftMeta by StringDelegate(profile, "https://gitlab.bixilon.de/bixilon/minosoft-meta-bin/-/raw/master/hash/\${hashPrefix}/\${fullHash}.mbf?inline=false")
var minecraftResources by StringDelegate(profile, "https://resources.download.minecraft.net/\${hashPrefix}/\${fullHash}")
var mojangPackages by StringDelegate(profile, "https://launchermeta.mojang.com/v1/packages/\${fullHash}/\${filename}")
var pistonObjects by StringDelegate(profile, "https://piston-data.mojang.com/v1/objects/\${fullHash}/\${filename}")

View File

@ -79,7 +79,7 @@ class LegacyUnicodeFontType(
}
private fun tryLoadPage(pageId: Int, textureFile: ResourceLocation, chars: Array<UnicodeCodeRenderer?>, sizes: InputStream, assets: AssetsManager, textures: StaticTextureArray) {
if (textureFile !in assets) {
if (textureFile !in assets) { // TODO: cache assets manger
// file not present, skip entire page
sizes.skip(PAGE_SIZE.toLong())
return

View File

@ -0,0 +1 @@
{"particle_type":[{"version":"_","hash":"8ada2d0dd9cb614a6ac3a0bfcdb63e84be5cee09c896e0eafc13c9c1cf1af555"}],"entities":[{"version":"1.8.9","hash":"b94f653357cc8e2d324a3897fe9f40f5737957d28e1af43ec39eef1eab0f670d"},{"version":"1.12.2","hash":"af6296721c2442c0d2aa1766c16e7c8c0e1a32f5ec5662a1a2d55f06c3658883"},{"version":"_","hash":"74bab04098f1d8a9cd869d9261509dbbdd8c3508f5efc866f72c4d58c69c15b8"}],"sound_events":[{"version":"1.12.2","hash":"e72a064aee687400e7fadb3209c9a450ae1f9f4a8bdf40a1c0338a550369837f"}],"biomes":[{"version":"_","hash":"ed82a8b6bc63d6fc7d579d8c874543e296974d17418d17e828fc01a166d24723"}],"blocks":[{"version":"_","hash":"2e2240d12a3ff84464aca2daaa02c5a22b6c134cb5b33b4ac59cb5fd3c5172aa"}],"status_effects":[{"version":"_","hash":"77999cb49b256dd9e771f2ca7f45da64f95dc581043e4974bc94fccdb8bce065"}],"motif":[{"version":"_","hash":"c7fb478986b060adda3f7e18bc47ff3be31a97ac1149d60e0bb9ba02f021d009"}],"enchantments":[{"version":"_","hash":"cf6e3c455c072332db9d2f163e6781078915e6332ade7f4987de27171a74f506"}],"items":[{"version":"_","hash":"a0a420a933b316be69c22489cd6dc3ba659fec84659c6cec2344f7c3636e0668"}],"dimensions":[{"version":"_","hash":"5874083553da355d162cf65b696ef017632d4f3e2168a4db781d7c4c4c28975e"}],"fluids":[{"version":"_","hash":"238a960fca28dd36eed0512d6ace12134d3c50661aec91196ef7b2646a9d1f28"}]}

View File

@ -286,14 +286,15 @@ internal class ChatComponentTest {
val hover = EntityHoverEvent("0d2dc333-f629-4b59-bdf9-074f58b99c06".toUUID(), minecraft("item"), name = TextComponent("item.item.slimeball"))
val expected = BaseComponent(
BaseComponent(
TextComponent("[").color(ChatColors.GRAY).italic(),
TextComponent("Bixilon").color(ChatColors.GRAY).italic(),
TextComponent(": ").color(ChatColors.GRAY).italic(),
BaseComponent(
TextComponent("Killed ").color(ChatColors.GRAY).italic(),
TextComponent("item.item.slimeball").color(ChatColors.GRAY).italic().hoverEvent(hover),
),
TextComponent("]").color(ChatColors.GRAY).italic(),
))
)
assertEquals(text, expected)
}

View File

@ -14,7 +14,7 @@
package de.bixilon.minosoft.data.text.events.hover
import de.bixilon.kutil.uuid.UUIDUtil.toUUID
import de.bixilon.minosoft.data.registries.identified.Namespaces
import de.bixilon.minosoft.data.registries.identified.Namespaces.minecraft
import de.bixilon.minosoft.data.text.TextComponent
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
@ -26,7 +26,7 @@ class EntityHoverEventTest {
val data = mapOf("text" to """{name:"item.item.slimeball",id:"0d2dc333-f629-4b59-bdf9-074f58b99c06",type:"minecraft:item"}""")
val event = EntityHoverEvent.build(data, false)
val expected = EntityHoverEvent("0d2dc333-f629-4b59-bdf9-074f58b99c06".toUUID(), Namespaces.minecraft("item"), name = TextComponent("item.item.slimeball"))
val expected = EntityHoverEvent("0d2dc333-f629-4b59-bdf9-074f58b99c06".toUUID(), minecraft("item"), name = TextComponent("item.item.slimeball"))
assertEquals(expected, event)
}