diff --git a/src/main/java/com/github/zly2006/reden/Reden.kt b/src/main/java/com/github/zly2006/reden/Reden.kt index ac351396..05c6ce75 100644 --- a/src/main/java/com/github/zly2006/reden/Reden.kt +++ b/src/main/java/com/github/zly2006/reden/Reden.kt @@ -9,6 +9,7 @@ import com.github.zly2006.reden.carpet.RedenCarpetSettings import com.github.zly2006.reden.indexing.blockId import com.github.zly2006.reden.indexing.entityId import com.github.zly2006.reden.indexing.propertyId +import com.github.zly2006.reden.mixinhelper.UpdateMonitorHelper import com.github.zly2006.reden.network.registerChannels import com.github.zly2006.reden.rvc.registerRvc import com.github.zly2006.reden.transformers.ThisIsReden @@ -82,7 +83,10 @@ class Reden : ModInitializer, CarpetExtension { @OptIn(DelicateCoroutinesApi::class) override fun onInitialize() { - ServerLifecycleEvents.SERVER_STARTING.register { server = it } + ServerLifecycleEvents.SERVER_STARTING.register { + UpdateMonitorHelper.cleanup() + server = it + } registerChannels() CarpetServer.manageExtension(this) CommandRegistrationCallback.EVENT.register { dispatcher, access, _ -> diff --git a/src/main/java/com/github/zly2006/reden/mixinhelper/UpdateMonitorHelper.kt b/src/main/java/com/github/zly2006/reden/mixinhelper/UpdateMonitorHelper.kt index 0701fcfd..1b4a1d01 100644 --- a/src/main/java/com/github/zly2006/reden/mixinhelper/UpdateMonitorHelper.kt +++ b/src/main/java/com/github/zly2006/reden/mixinhelper/UpdateMonitorHelper.kt @@ -21,7 +21,6 @@ import com.github.zly2006.reden.mixinhelper.UpdateMonitorHelper.undoRecordsMap import com.github.zly2006.reden.utils.debugLogger import com.github.zly2006.reden.utils.isClient import com.github.zly2006.reden.utils.server -import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents import net.minecraft.block.BlockState import net.minecraft.entity.Entity @@ -88,6 +87,14 @@ object UpdateMonitorHelper { val undoRecordsMap: MutableMap = HashMap() internal val undoRecords = mutableListOf() + /** + * Used for crash recovery. + */ + fun cleanup() { + undoRecordsMap.clear() + undoRecords.clear() + } + private fun filterLogById(undoId: Long) = undoId != 0L || if (isClient) !DEBUG_LOGGER_IGNORE_UNDO_ID_0.booleanValue else true @@ -114,12 +121,6 @@ object UpdateMonitorHelper { } return undoRecords.removeLast() } - data class Changed( - val record: PlayerData.UndoRecord, - val pos: BlockPos - ) - var lastTickChanged: MutableSet = hashSetOf(); private set - var thisTickChanged: MutableSet = hashSetOf(); private set val recording: PlayerData.UndoRecord? get() = undoRecords.lastOrNull()?.record /** @@ -297,9 +298,5 @@ object UpdateMonitorHelper { init { ServerPlayConnectionEvents.DISCONNECT.register { handler, _ -> playerQuit(handler.player) } - ServerTickEvents.START_SERVER_TICK.register { - lastTickChanged = thisTickChanged - thisTickChanged = hashSetOf() - } } }