static void DeconstructPart(TextWriter output, IScriptRootData root, IStructure S, DeconstructData deconstructData, IContainer target, VectorInt3 targetPos, string N) { IDeviceLock locked = null; var startTime = DateTime.Now; var maxMilliSeconds = EmpyrionScripting.Configuration.Current.InGameScriptsIntervallMS; try { for (; deconstructData.Y >= deconstructData.MinPos.y; deconstructData.Y--) { for (; deconstructData.X <= deconstructData.MaxPos.x; deconstructData.X++) { for (; deconstructData.Z <= deconstructData.MaxPos.z; deconstructData.Z++) { deconstructData.CheckedBlocks++; var block = S.GetBlock(deconstructData.X, 128 + deconstructData.Y, deconstructData.Z); if (block != null) { block.Get(out var blockType, out _, out _, out _); if (blockType > 0 && blockType != PlayerCoreType) { locked = locked ?? CreateDeviceLock(EmpyrionScripting.ModApi?.Playfield, root.E.S.GetCurrent(), targetPos); if (!locked.Success) { deconstructData.CheckedBlocks--; output.WriteLine($"Container '{N}' is locked"); return; } if (target.AddItems(blockType, 1) > 0) { deconstructData.CheckedBlocks--; output.WriteLine($"Container '{N}' is full"); return; } block.Set(0); deconstructData.RemovedBlocks++; if (deconstructData.RemovedBlocks > 100 && deconstructData.RemovedBlocks % 100 == 0 && (DateTime.Now - startTime).TotalMilliseconds > maxMilliSeconds) { return; } } } } deconstructData.Z = deconstructData.MinPos.z; } deconstructData.X = deconstructData.MinPos.x; } } finally { locked?.Dispose(); } }