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