@@ -259,6 +259,32 @@ public void ResetVoxelArea(float Radius)
259259 }
260260
261261
262+ }
263+
264+ [ Command ( "reset planet area" , "Resets voxel damange in specified radius from player" ) ]
265+ [ Permission ( MyPromoteLevel . Admin ) ]
266+ public void ResetPlanetVoxelArea ( float Radius )
267+ {
268+ if ( Context . Player == null )
269+ Context . Respond ( "Invalid command input! Must be ingame!" ) ;
270+
271+
272+ if ( Radius <= 0 )
273+ {
274+ Context . Respond ( "Inavlid radius!" ) ;
275+ return ;
276+ }
277+
278+
279+ if ( ResetPlanetVoxelsInArea ( Context . Player . GetPosition ( ) , Radius ) ) {
280+ Context . Respond ( "Voxel reset complete!" ) ;
281+ }
282+ else
283+ {
284+ Context . Respond ( "Couldnt reset voxels! Check log for more information!" ) ;
285+ }
286+
287+
262288 }
263289
264290 [ Command ( "reset gps" , "Resets voxel damange in specified radius from given point" ) ]
@@ -342,6 +368,67 @@ private static bool ResetVoxelInArea(Vector3D Center, float Radius)
342368 return false ;
343369 }
344370 }
371+
372+ private static bool ResetPlanetVoxelsInArea ( Vector3D center , float radius )
373+ {
374+ try
375+ {
376+ BoundingSphereD sphere = new BoundingSphereD ( center , radius ) ;
377+ List < MyPlanet > planets = MyEntities . GetEntitiesInSphere ( ref sphere ) . OfType < MyPlanet > ( ) . ToList ( ) ;
378+ if ( planets . Count == 0 )
379+ return true ;
380+
381+ foreach ( var planet in planets )
382+ {
383+ using ( planet . Pin ( ) )
384+ {
385+ if ( planet . MarkedForClose )
386+ {
387+ continue ;
388+ }
389+
390+ MyShapeSphere shape = new MyShapeSphere
391+ {
392+ Center = center ,
393+ Radius = radius
394+ } ;
395+
396+ // Planet-specific adjustment to voxel coordinates
397+ Vector3I minCorner , maxCorner ;
398+ BoundingBoxD shapeAabb = shape . GetWorldBoundaries ( ) ;
399+ Vector3I storageSize = planet . Storage . Size ;
400+ MyVoxelCoordSystems . WorldPositionToVoxelCoord ( planet . PositionLeftBottomCorner , ref shapeAabb . Min , out minCorner ) ;
401+ MyVoxelCoordSystems . WorldPositionToVoxelCoord ( planet . PositionLeftBottomCorner , ref shapeAabb . Max , out maxCorner ) ;
402+ minCorner += planet . StorageMin ;
403+ maxCorner += planet . StorageMin ;
404+ maxCorner += 1 ;
405+ storageSize -= 1 ;
406+
407+ Vector3I . Clamp ( ref minCorner , ref Vector3I . Zero , ref storageSize , out minCorner ) ;
408+ Vector3I . Clamp ( ref maxCorner , ref Vector3I . Zero , ref storageSize , out maxCorner ) ;
409+
410+ planet . Storage . DeleteRange ( MyStorageDataTypeFlags . ContentAndMaterial , minCorner , maxCorner , false ) ;
411+
412+ BoundingBoxD cutOutBox = shape . GetWorldBoundaries ( ) ;
413+ MySandboxGame . Static . Invoke ( delegate
414+ {
415+ if ( planet . Storage != null )
416+ {
417+ planet . Storage . NotifyChanged ( minCorner , maxCorner , MyStorageDataTypeFlags . ContentAndMaterial ) ;
418+ MyVoxelGenerator . NotifyVoxelChanged ( MyVoxelBase . OperationType . Revert , planet , ref cutOutBox ) ;
419+ }
420+ } , "ResetPlanetVoxels notify" ) ;
421+ }
422+ }
423+ return true ;
424+ }
425+ catch ( Exception ex )
426+ {
427+ _log . Error ( ex , "Planet voxel reset failed!" ) ;
428+ return false ;
429+ }
430+ }
431+
345432
346433 private static LockToken PinDelete ( )
347434 {
0 commit comments