minor corrections

This commit is contained in:
DBotThePony 2022-08-24 11:57:04 +07:00
parent 017e9dee7f
commit 2da5219739
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -1,13 +1,11 @@
package ru.dbotthepony.mc.otm.capability.drive
import it.unimi.dsi.fastutil.objects.Object2ObjectAVLTreeMap
import java.util.HashMap
import java.util.UUID
import net.minecraft.ReportedException
import net.minecraft.nbt.CompoundTag
import net.minecraft.nbt.NbtIo
import net.minecraft.CrashReport
import net.minecraft.server.MinecraftServer
import java.util.concurrent.locks.LockSupport
import net.minecraftforge.eventbus.api.SubscribeEvent
import net.minecraftforge.eventbus.api.EventPriority
@ -50,8 +48,8 @@ object DrivePool {
@JvmStatic
operator fun <T : IMatteryDrive<*>> get(
id: UUID,
factory_stored: (CompoundTag) -> T,
factory_empty: () -> T
deserializer: (CompoundTag) -> T,
factory: () -> T
): T {
if (!isLegalAccess())
throw IllegalAccessException("Can not access drive pool from outside of server thread.")
@ -73,20 +71,19 @@ object DrivePool {
if (file.exists()) {
try {
val factorize = factory_stored(NbtIo.readCompressed(file))
val factorize = deserializer(NbtIo.readCompressed(file))
pool[id] = WeakDriveReference(factorize)
return factorize
} catch (error: Throwable) {
val report = CrashReport("Reading OTM Drive from disk", error)
val category = report.addCategory("Corrupt drive")
category.setDetail("UUID", id)
category.setDetail("File location", file)
throw ReportedException(report)
}
}
val factorize = factory_empty()
pool[id] = WeakDriveReference(factorize)
return factorize
return factory().also { pool[id] = WeakDriveReference(it) }
}
@JvmStatic