Matter registry dumps

This commit is contained in:
DBotThePony 2022-11-16 09:23:38 +07:00
parent 865d74ed2e
commit 209d639251
Signed by: DBot
GPG Key ID: DCC23B5715498507
3 changed files with 54 additions and 1 deletions

View File

@ -150,6 +150,9 @@ private fun misc(provider: MatteryLanguageProvider) {
misc("exosuit.granted7", "You are now permanently equipped with four dimensional omni-present Exosuit.")
misc("exosuit.granted8", "As of now, this exosuit is not much, but it's built-in AI hints there are upgrade modules out there somewhere...")
misc("dumping_matter_registry", "Dumping matter registry to %s")
misc("dumped_matter_registry", "Dumped matter registry to %s")
misc("iteration", "Iteration %s")
misc("death_reason", "Decommissioned!")

View File

@ -141,7 +141,7 @@ public final class OverdriveThatMatters {
private void setup(final FMLCommonSetupEvent event) {
EVENT_BUS.addListener(EventPriority.LOWEST, DrivePool.INSTANCE::onServerPostTick);
EVENT_BUS.addListener(EventPriority.HIGHEST, DrivePool.INSTANCE::serverStopEvent);
EVENT_BUS.addListener(EventPriority.HIGHEST, DrivePool.INSTANCE::serverStartEvent);
EVENT_BUS.addListener(EventPriority.LOWEST, DrivePool.INSTANCE::serverStartEvent);
EVENT_BUS.addListener(EventPriority.NORMAL, DrivePool.INSTANCE::onWorldSave);
EVENT_BUS.addListener(EventPriority.HIGHEST, GlobalEventHandlerKt::onServerStopped);
@ -171,6 +171,7 @@ public final class OverdriveThatMatters {
EVENT_BUS.addListener(EventPriority.NORMAL, MatterManager.INSTANCE::reloadEvent);
EVENT_BUS.addListener(EventPriority.NORMAL, MatterManager.INSTANCE::onServerStarted);
EVENT_BUS.addListener(EventPriority.NORMAL, MatterManager.INSTANCE::addCommands);
EVENT_BUS.addListener(EventPriority.NORMAL, SynchronizedBlockEntity.Companion::onServerStopping);
EVENT_BUS.addListener(EventPriority.NORMAL, SynchronizedBlockEntity.Companion::onLevelUnload);

View File

@ -9,11 +9,14 @@ import com.google.gson.JsonObject
import com.google.gson.JsonParseException
import com.google.gson.JsonSyntaxException
import com.mojang.blaze3d.platform.InputConstants
import com.mojang.brigadier.context.CommandContext
import it.unimi.dsi.fastutil.objects.Reference2ObjectFunction
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap
import it.unimi.dsi.fastutil.objects.ReferenceLinkedOpenHashSet
import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet
import net.minecraft.ChatFormatting
import net.minecraft.commands.CommandSourceStack
import net.minecraft.commands.Commands
import net.minecraft.network.chat.Component
import net.minecraft.network.chat.MutableComponent
import net.minecraft.resources.ResourceLocation
@ -29,6 +32,7 @@ import net.minecraft.world.item.crafting.Recipe
import net.minecraft.world.item.crafting.RecipeType
import net.minecraft.world.level.ItemLike
import net.minecraftforge.event.AddReloadListenerEvent
import net.minecraftforge.event.RegisterCommandsEvent
import net.minecraftforge.event.entity.player.ItemTooltipEvent
import net.minecraftforge.event.server.ServerStartedEvent
import net.minecraftforge.eventbus.api.IEventBus
@ -36,6 +40,7 @@ import net.minecraftforge.registries.DeferredRegister
import net.minecraftforge.registries.ForgeRegistries
import org.apache.logging.log4j.LogManager
import org.lwjgl.glfw.GLFW
import ru.dbotthepony.mc.otm.MINECRAFT_SERVER
import ru.dbotthepony.mc.otm.OverdriveThatMatters
import ru.dbotthepony.mc.otm.SystemTime
import ru.dbotthepony.mc.otm.capability.MatteryCapability
@ -54,7 +59,10 @@ import ru.dbotthepony.mc.otm.core.registryName
import ru.dbotthepony.mc.otm.core.stream
import ru.dbotthepony.mc.otm.registry.RegistryDelegate
import ru.dbotthepony.mc.otm.storage.ItemStackWrapper
import java.io.File
import java.math.BigInteger
import java.time.Instant
import java.time.format.DateTimeFormatter
import java.util.*
import java.util.stream.Stream
import kotlin.ConcurrentModificationException
@ -137,6 +145,8 @@ internal class KeyEntry(
priority: Int,
) : Entry(modificationChain, matter, complexity, priority)
private fun transformQuotes(it: String?): String = if (it != null) '"' + it.replace("\"", "\"\"") + '"' else "NULL"
object MatterManager {
const val MATTER_DIRECTORY = "otm_matter"
const val FINDER_DIRECTORY = "otm_recipe_finder"
@ -1061,12 +1071,51 @@ object MatterManager {
Resolver.registrar.register(bus)
}
private fun dumpRegistry(stack: CommandContext<CommandSourceStack>): Int {
val targetFile = File(MINECRAFT_SERVER.serverDirectory, "otm/registry_dumps/full_${System.currentTimeMillis() / 1_000L}.csv")
File(MINECRAFT_SERVER.serverDirectory, "otm/registry_dumps").mkdirs()
stack.source.sendSuccess(TranslatableComponent("otm.dumping_matter_registry", targetFile.absolutePath), false)
val writer = targetFile.bufferedWriter(Charsets.UTF_8)
writer.write(arrayOf("Registry ID", "Matter Value", "Complexity", "Commentary").joinToString(";", transform = ::transformQuotes))
writer.write("\n")
for ((key, item) in ForgeRegistries.ITEMS.entries) {
val value = get(item)
if (!value.hasMatterValue) {
writer.write(arrayOf(key.location().toString(), "", "", commentary[item]?.string ?: "").joinToString(";", transform = ::transformQuotes))
} else {
writer.write(arrayOf(key.location().toString(), value.matter.toString(), value.complexity.toString(), commentary[item]?.string ?: "").joinToString(";", transform = ::transformQuotes))
}
writer.write("\n")
}
writer.close()
stack.source.sendSuccess(TranslatableComponent("otm.dumped_matter_registry", targetFile.absolutePath), true)
return 0
}
fun addCommands(event: RegisterCommandsEvent) {
event.dispatcher.register(
Commands.literal("dump_matter_registry")
.requires { it.hasPermission(Commands.LEVEL_OWNERS) }
.executes(::dumpRegistry)
)
}
private val matterValues = Reference2ObjectOpenHashMap<Item, IMatterValue>()
private val validMatterValues = ArrayList<Pair<Item, IMatterValue>>()
val valuesMap: Map<Item, IMatterValue> = Collections.unmodifiableMap(matterValues)
val valuesList: List<Pair<Item, IMatterValue>> = Collections.unmodifiableList(validMatterValues)
// TODO: /reload
fun onServerStarted(event: ServerStartedEvent) {
Resolver.resolve(event.server)