mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 11:54:59 -04:00
assets: allow different assets prefix, overwrite assets manager
This commit is contained in:
parent
c031b241f9
commit
d3a0ff5745
@ -58,6 +58,7 @@ import de.bixilon.minosoft.util.task.worker.StartupTasks
|
|||||||
object Minosoft {
|
object Minosoft {
|
||||||
val MAIN_THREAD: Thread = Thread.currentThread()
|
val MAIN_THREAD: Thread = Thread.currentThread()
|
||||||
val MINOSOFT_ASSETS_MANAGER = ResourcesAssetsUtil.create(Minosoft::class.java, canUnload = false)
|
val MINOSOFT_ASSETS_MANAGER = ResourcesAssetsUtil.create(Minosoft::class.java, canUnload = false)
|
||||||
|
val OVERWRITE_ASSETS_MANAGER = ResourcesAssetsUtil.create(Minosoft::class.java, canUnload = false, prefix = "assets_overwrite")
|
||||||
val LANGUAGE_MANAGER = MultiLanguageManager()
|
val LANGUAGE_MANAGER = MultiLanguageManager()
|
||||||
val START_UP_LATCH = CountUpAndDownLatch(1)
|
val START_UP_LATCH = CountUpAndDownLatch(1)
|
||||||
|
|
||||||
@ -66,6 +67,7 @@ object Minosoft {
|
|||||||
CommandLineArguments.parse(args)
|
CommandLineArguments.parse(args)
|
||||||
KUtil.initUtilClasses()
|
KUtil.initUtilClasses()
|
||||||
MINOSOFT_ASSETS_MANAGER.load(CountUpAndDownLatch(0))
|
MINOSOFT_ASSETS_MANAGER.load(CountUpAndDownLatch(0))
|
||||||
|
OVERWRITE_ASSETS_MANAGER.load(CountUpAndDownLatch(0)) // ToDo: async
|
||||||
|
|
||||||
Log.log(LogMessageType.OTHER, LogLevels.INFO) { "Starting minosoft..." }
|
Log.log(LogMessageType.OTHER, LogLevels.INFO) { "Starting minosoft..." }
|
||||||
if (OSUtil.OS == OSUtil.OSs.MAC && !RunConfiguration.X_START_ON_FIRST_THREAD_SET && !RunConfiguration.DISABLE_RENDERING) {
|
if (OSUtil.OS == OSUtil.OSs.MAC && !RunConfiguration.X_START_ON_FIRST_THREAD_SET && !RunConfiguration.DISABLE_RENDERING) {
|
||||||
|
@ -28,7 +28,8 @@ object AssetsLoader {
|
|||||||
fun create(profile: ResourcesProfile, version: Version, latch: CountUpAndDownLatch, property: AssetsVersionProperty = AssetsVersionProperties[version] ?: throw IllegalAccessException("$version has no assets!")): AssetsManager {
|
fun create(profile: ResourcesProfile, version: Version, latch: CountUpAndDownLatch, property: AssetsVersionProperty = AssetsVersionProperties[version] ?: throw IllegalAccessException("$version has no assets!")): AssetsManager {
|
||||||
val assetsManager = PriorityAssetsManager()
|
val assetsManager = PriorityAssetsManager()
|
||||||
|
|
||||||
for (resourcePack in profile.assets.resourcePacks) {
|
assetsManager += Minosoft.OVERWRITE_ASSETS_MANAGER
|
||||||
|
for (resourcePack in profile.assets.resourcePacks.reversed()) {
|
||||||
resourcePack.type.creator(resourcePack).let {
|
resourcePack.type.creator(resourcePack).let {
|
||||||
it.load(latch)
|
it.load(latch)
|
||||||
assetsManager += it
|
assetsManager += it
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Minosoft
|
* Minosoft
|
||||||
* Copyright (C) 2021 Moritz Zwerger
|
* Copyright (C) 2020-2022 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.
|
||||||
*
|
*
|
||||||
@ -60,4 +60,8 @@ interface AssetsManager {
|
|||||||
* Deletes all assets from memory
|
* Deletes all assets from memory
|
||||||
*/
|
*/
|
||||||
fun unload()
|
fun unload()
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val DEFAULT_ASSETS_PREFIX = "assets"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Minosoft
|
* Minosoft
|
||||||
* Copyright (C) 2021 Moritz Zwerger
|
* Copyright (C) 2020-2022 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.
|
||||||
*
|
*
|
||||||
@ -31,6 +31,7 @@ import java.io.InputStream
|
|||||||
class DirectoryAssetsManager(
|
class DirectoryAssetsManager(
|
||||||
basePath: String,
|
basePath: String,
|
||||||
private val canUnload: Boolean = true,
|
private val canUnload: Boolean = true,
|
||||||
|
val prefix: String = AssetsManager.DEFAULT_ASSETS_PREFIX,
|
||||||
) : AssetsManager {
|
) : AssetsManager {
|
||||||
private val basePath = File(basePath).slashPath
|
private val basePath = File(basePath).slashPath
|
||||||
override val namespaces: MutableSet<String> = mutableSetOf()
|
override val namespaces: MutableSet<String> = mutableSetOf()
|
||||||
@ -47,7 +48,7 @@ class DirectoryAssetsManager(
|
|||||||
scanDirectory(file)
|
scanDirectory(file)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
val path = file.slashPath.removePrefix(basePath).removePrefix("/").toAssetName(false) ?: continue
|
val path = file.slashPath.removePrefix(basePath).removePrefix("/").toAssetName(false, prefix) ?: continue
|
||||||
assets += path
|
assets += path
|
||||||
namespaces += path.namespace
|
namespaces += path.namespace
|
||||||
}
|
}
|
||||||
|
@ -22,16 +22,16 @@ import java.nio.charset.StandardCharsets
|
|||||||
|
|
||||||
object ResourcesAssetsUtil {
|
object ResourcesAssetsUtil {
|
||||||
|
|
||||||
fun create(clazz: Class<*>, canUnload: Boolean = true): AssetsManager {
|
fun create(clazz: Class<*>, canUnload: Boolean = true, prefix: String = AssetsManager.DEFAULT_ASSETS_PREFIX): AssetsManager {
|
||||||
val rootResources = clazz.classLoader.getResource("assets") ?: throw FileNotFoundException("Can not find assets folder in $clazz")
|
val rootResources = clazz.classLoader.getResource("assets") ?: throw FileNotFoundException("Can not find assets folder in $clazz")
|
||||||
|
|
||||||
return when (rootResources.protocol) {
|
return when (rootResources.protocol) {
|
||||||
"file" -> DirectoryAssetsManager(rootResources.path, canUnload) // Read them directly from the folder
|
"file" -> DirectoryAssetsManager(rootResources.path, canUnload, prefix) // Read them directly from the folder
|
||||||
"jar" -> {
|
"jar" -> {
|
||||||
val path: String = rootResources.path
|
val path: String = rootResources.path
|
||||||
val jarPath = path.substring(5, path.indexOf("!"))
|
val jarPath = path.substring(5, path.indexOf("!"))
|
||||||
val zip = URLDecoder.decode(jarPath, StandardCharsets.UTF_8)
|
val zip = URLDecoder.decode(jarPath, StandardCharsets.UTF_8)
|
||||||
ZipAssetsManager(zip, canUnload = canUnload)
|
ZipAssetsManager(zip, canUnload = canUnload, prefix = prefix)
|
||||||
}
|
}
|
||||||
else -> throw IllegalStateException("Can not read resources: $rootResources")
|
else -> throw IllegalStateException("Can not read resources: $rootResources")
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Minosoft
|
* Minosoft
|
||||||
* Copyright (C) 2021 Moritz Zwerger
|
* Copyright (C) 2020-2022 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.assets.file
|
package de.bixilon.minosoft.assets.file
|
||||||
|
|
||||||
import de.bixilon.kutil.latch.CountUpAndDownLatch
|
import de.bixilon.kutil.latch.CountUpAndDownLatch
|
||||||
|
import de.bixilon.minosoft.assets.AssetsManager
|
||||||
import de.bixilon.minosoft.assets.util.FileAssetsUtil.toAssetName
|
import de.bixilon.minosoft.assets.util.FileAssetsUtil.toAssetName
|
||||||
import de.bixilon.minosoft.assets.util.FileUtil.readJson
|
import de.bixilon.minosoft.assets.util.FileUtil.readJson
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@ -27,6 +28,7 @@ import java.util.zip.ZipInputStream
|
|||||||
class ZipAssetsManager(
|
class ZipAssetsManager(
|
||||||
private val inputStream: ZipInputStream,
|
private val inputStream: ZipInputStream,
|
||||||
canUnload: Boolean = true,
|
canUnload: Boolean = true,
|
||||||
|
val prefix: String = AssetsManager.DEFAULT_ASSETS_PREFIX,
|
||||||
) : FileAssetsManager(canUnload) {
|
) : FileAssetsManager(canUnload) {
|
||||||
|
|
||||||
override fun load(latch: CountUpAndDownLatch) {
|
override fun load(latch: CountUpAndDownLatch) {
|
||||||
@ -42,7 +44,7 @@ class ZipAssetsManager(
|
|||||||
"pack.png" -> image = inputStream.readAllBytes()
|
"pack.png" -> image = inputStream.readAllBytes()
|
||||||
"pack.mcmeta" -> properties = inputStream.readJson(false)
|
"pack.mcmeta" -> properties = inputStream.readJson(false)
|
||||||
else -> {
|
else -> {
|
||||||
val resourceLocation = name.toAssetName() ?: continue
|
val resourceLocation = name.toAssetName(prefix = prefix) ?: continue
|
||||||
namespaces += resourceLocation.namespace
|
namespaces += resourceLocation.namespace
|
||||||
assets[resourceLocation] = inputStream.readAllBytes()
|
assets[resourceLocation] = inputStream.readAllBytes()
|
||||||
}
|
}
|
||||||
@ -54,6 +56,6 @@ class ZipAssetsManager(
|
|||||||
loaded = true
|
loaded = true
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(file: File, canUnload: Boolean = true) : this(ZipInputStream(FileInputStream(file)), canUnload)
|
constructor(file: File, canUnload: Boolean = true, prefix: String = AssetsManager.DEFAULT_ASSETS_PREFIX) : this(ZipInputStream(FileInputStream(file)), canUnload, prefix)
|
||||||
constructor(path: String, canUnload: Boolean = true) : this(File(path), canUnload)
|
constructor(path: String, canUnload: Boolean = true, prefix: String = AssetsManager.DEFAULT_ASSETS_PREFIX) : this(File(path), canUnload, prefix)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Minosoft
|
* Minosoft
|
||||||
* Copyright (C) 2021 Moritz Zwerger
|
* Copyright (C) 2020-2022 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.
|
||||||
*
|
*
|
||||||
@ -18,6 +18,7 @@ import com.github.luben.zstd.ZstdOutputStream
|
|||||||
import de.bixilon.kutil.array.ByteArrayUtil.toHex
|
import de.bixilon.kutil.array.ByteArrayUtil.toHex
|
||||||
import de.bixilon.kutil.hex.HexUtil.isHexString
|
import de.bixilon.kutil.hex.HexUtil.isHexString
|
||||||
import de.bixilon.kutil.random.RandomStringUtil.randomString
|
import de.bixilon.kutil.random.RandomStringUtil.randomString
|
||||||
|
import de.bixilon.minosoft.assets.AssetsManager
|
||||||
import de.bixilon.minosoft.data.registries.ResourceLocation
|
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
||||||
import de.bixilon.minosoft.terminal.RunConfiguration
|
import de.bixilon.minosoft.terminal.RunConfiguration
|
||||||
@ -115,11 +116,11 @@ object FileAssetsUtil {
|
|||||||
return saveAndGet(ByteArrayInputStream(data), compress, false, hashType)
|
return saveAndGet(ByteArrayInputStream(data), compress, false, hashType)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun String.toAssetName(verifyPrefix: Boolean = true): ResourceLocation? {
|
fun String.toAssetName(verifyPrefix: Boolean = true, prefix: String = AssetsManager.DEFAULT_ASSETS_PREFIX): ResourceLocation? {
|
||||||
if (verifyPrefix && !startsWith("assets/")) {
|
if (verifyPrefix && !startsWith("$prefix/")) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
val split = removePrefix("assets/").split("/", limit = 2)
|
val split = removePrefix("$prefix/").split("/", limit = 2)
|
||||||
if (split.size != 2) {
|
if (split.size != 2) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
@ -28,9 +28,10 @@ class SignBlockEntityRenderer(
|
|||||||
) : MeshedBlockEntityRenderer<SignBlockEntity> {
|
) : MeshedBlockEntityRenderer<SignBlockEntity> {
|
||||||
|
|
||||||
override fun singleRender(position: Vec3i, mesh: WorldMesh, random: Random, blockState: BlockState, neighbours: Array<BlockState?>, light: ByteArray, ambientLight: FloatArray, tints: IntArray?): Boolean {
|
override fun singleRender(position: Vec3i, mesh: WorldMesh, random: Random, blockState: BlockState, neighbours: Array<BlockState?>, light: ByteArray, ambientLight: FloatArray, tints: IntArray?): Boolean {
|
||||||
val model = this.blockState.block.nullCast<SignBlock>() ?: return false
|
val model = this.blockState.block.nullCast<SignBlock>()?.model ?: return false
|
||||||
println("Rendering sign at $position")
|
println("Rendering sign at $position")
|
||||||
|
|
||||||
|
|
||||||
// ToDo
|
// ToDo
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user