From 2da5219739dde7e4fa79db0c6f74bcc92c4b3d47 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Wed, 24 Aug 2022 11:57:04 +0700 Subject: [PATCH] minor corrections --- .../mc/otm/capability/drive/DrivePool.kt | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/drive/DrivePool.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/drive/DrivePool.kt index 93d67dbff..d733637e6 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/drive/DrivePool.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/drive/DrivePool.kt @@ -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 > 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