screen padding

This commit is contained in:
nea
2022-08-04 04:26:51 +02:00
parent c83890afc8
commit 05a4a5b381
5 changed files with 85 additions and 21 deletions

6
TODO.txt Normal file
View File

@@ -0,0 +1,6 @@
- translations
- recipes
- fairy souls
- and much more that i will add as i go along

View File

@@ -3,6 +3,7 @@ package moe.nea.notenoughupdates
import com.mojang.brigadier.Command
import com.mojang.brigadier.CommandDispatcher
import io.github.cottonmc.cotton.gui.client.CottonClientScreen
import io.github.moulberry.repo.NEURepositoryException
import io.ktor.client.*
import io.ktor.client.plugins.*
import io.ktor.client.plugins.contentnegotiation.*
@@ -18,6 +19,7 @@ import net.fabricmc.api.ModInitializer
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents
import net.fabricmc.loader.api.FabricLoader
import net.fabricmc.loader.api.Version
import net.fabricmc.loader.api.metadata.ModMetadata
@@ -67,10 +69,16 @@ object NotEnoughUpdates : ModInitializer, ClientModInitializer {
) {
dispatcher.register(ClientCommandManager.literal("neureload").executes {
it.source.sendFeedback(Component.literal("Reloading repository from disk. This may lag a bit."))
RepoManager.neuRepo.reload()
try {
RepoManager.reload()
} catch (exc: NEURepositoryException) {
it.source.sendError(Component.literal("There has been an error reloading the repository. Please try again. IF this persists, delete the .notenoughupdates folder in your mincraft folder"))
exc.printStackTrace()
}
Command.SINGLE_SUCCESS
})
dispatcher.register(ClientCommandManager.literal("neu")
dispatcher.register(
ClientCommandManager.literal("neu")
.then(ClientCommandManager.literal("repo").executes {
setScreenLater(CottonClientScreen(RepoManagementGui()))
Command.SINGLE_SUCCESS
@@ -82,6 +90,12 @@ object NotEnoughUpdates : ModInitializer, ClientModInitializer {
RepoManager.initialize()
ConfigHolder.registerEvents()
ClientCommandRegistrationCallback.EVENT.register(this::registerCommands)
ClientLifecycleEvents.CLIENT_STOPPING.register(ClientLifecycleEvents.ClientStopping {
runBlocking {
logger.info("Shutting down NEU coroutines")
globalJob.cancel()
}
})
}
override fun onInitializeClient() {

View File

@@ -4,6 +4,8 @@ import com.mojang.serialization.Dynamic
import io.github.moulberry.repo.IReloadable
import io.github.moulberry.repo.NEURepository
import io.github.moulberry.repo.data.NEUItem
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import moe.nea.notenoughupdates.NotEnoughUpdates
import moe.nea.notenoughupdates.util.LegacyTagParser
import moe.nea.notenoughupdates.util.appendLore
@@ -70,7 +72,18 @@ object ItemCache : IReloadable {
ResourceLocation("skyblockitem", skyblockItemId.lowercase().replace(";", "__"))
var job: Job? = null
override fun reload(repository: NEURepository) {
cache.clear()
val j = job
if (j != null && j.isActive) {
j.cancel()
job = NotEnoughUpdates.coroutineScope.launch {
repository.items?.items?.values?.forEach {
it.asItemStack() // Rebuild cache
}
}
}
}
}

View File

@@ -1,6 +1,7 @@
package moe.nea.notenoughupdates.repo
import io.github.moulberry.repo.NEURepository
import io.github.moulberry.repo.NEURepositoryException
import kotlinx.coroutines.launch
import kotlinx.serialization.Serializable
import kotlinx.serialization.serializer
@@ -9,6 +10,7 @@ import moe.nea.notenoughupdates.NotEnoughUpdates.logger
import moe.nea.notenoughupdates.util.ConfigHolder
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents
import net.minecraft.client.Minecraft
import net.minecraft.network.chat.Component
import net.minecraft.network.protocol.game.ClientboundUpdateRecipesPacket
object RepoManager : ConfigHolder<RepoManager.Config>(serializer(), "repo", ::Config) {
@@ -33,7 +35,9 @@ object RepoManager : ConfigHolder<RepoManager.Config>(serializer(), "repo", ::Co
}
private fun trySendClientboundUpdateRecipesPacket(): Boolean {
return Minecraft.getInstance().level != null && Minecraft.getInstance().connection?.handleUpdateRecipes(ClientboundUpdateRecipesPacket(mutableListOf())) != null
return Minecraft.getInstance().level != null && Minecraft.getInstance().connection?.handleUpdateRecipes(
ClientboundUpdateRecipesPacket(mutableListOf())
) != null
}
init {
@@ -46,7 +50,18 @@ object RepoManager : ConfigHolder<RepoManager.Config>(serializer(), "repo", ::Co
fun launchAsyncUpdate() {
NotEnoughUpdates.coroutineScope.launch {
RepoDownloadManager.downloadUpdate()
reload()
}
}
fun reload() {
try {
neuRepo.reload()
} catch (exc: NEURepositoryException) {
Minecraft.getInstance().player?.sendSystemMessage(
Component.literal("Failed to reload repository. This will result in some mod features not working.")
)
exc.printStackTrace()
}
}
@@ -54,7 +69,7 @@ object RepoManager : ConfigHolder<RepoManager.Config>(serializer(), "repo", ::Co
if (config.autoUpdate) {
launchAsyncUpdate()
} else {
neuRepo.reload()
reload()
}
}

View File

@@ -4,6 +4,7 @@ import kotlinx.serialization.KSerializer
import kotlinx.serialization.SerializationException
import moe.nea.notenoughupdates.NotEnoughUpdates
import moe.nea.notenoughupdates.events.NEUScreenEvents
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents
import net.minecraft.client.Minecraft
import net.minecraft.commands.CommandSource
import net.minecraft.network.chat.Component
@@ -15,9 +16,11 @@ import kotlin.io.path.readText
import kotlin.io.path.writeText
import kotlin.reflect.KClass
abstract class ConfigHolder<T>(val serializer: KSerializer<T>,
abstract class ConfigHolder<T>(
val serializer: KSerializer<T>,
val name: String,
val default: () -> T) {
val default: () -> T
) {
var config: T
private set
@@ -38,10 +41,16 @@ abstract class ConfigHolder<T>(val serializer: KSerializer<T>,
)
} catch (e: IOException) {
badLoads.add(name)
NotEnoughUpdates.logger.error("IO exception during loading of config file $name. This will reset this config.", e)
NotEnoughUpdates.logger.error(
"IO exception during loading of config file $name. This will reset this config.",
e
)
} catch (e: SerializationException) {
badLoads.add(name)
NotEnoughUpdates.logger.error("Serialization exception during loading of config file $name. This will reset this config.", e)
NotEnoughUpdates.logger.error(
"Serialization exception during loading of config file $name. This will reset this config.",
e
)
}
return default()
}
@@ -95,8 +104,12 @@ abstract class ConfigHolder<T>(val serializer: KSerializer<T>,
private fun warnForResetConfigs(player: CommandSource) {
if (badLoads.isNotEmpty()) {
player.sendSystemMessage(Component.literal("The following configs have been reset: ${badLoads.joinToString(", ")}. " +
"This can be intentional, but probably isn't."))
player.sendSystemMessage(
Component.literal(
"The following configs have been reset: ${badLoads.joinToString(", ")}. " +
"This can be intentional, but probably isn't."
)
)
badLoads.clear()
}
}
@@ -110,6 +123,9 @@ abstract class ConfigHolder<T>(val serializer: KSerializer<T>,
}
false
})
ClientLifecycleEvents.CLIENT_STOPPING.register(ClientLifecycleEvents.ClientStopping {
performSaves()
})
}