NoiseRangeCarverSystem.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using Content.Server.Worldgen.Components.Carvers;
  2. using Content.Server.Worldgen.Systems.Debris;
  3. namespace Content.Server.Worldgen.Systems.Carvers;
  4. /// <summary>
  5. /// This handles carving out holes in world generation according to a noise channel.
  6. /// </summary>
  7. public sealed class NoiseRangeCarverSystem : EntitySystem
  8. {
  9. [Dependency] private readonly NoiseIndexSystem _index = default!;
  10. [Dependency] private readonly SharedTransformSystem _transform = default!;
  11. /// <inheritdoc />
  12. public override void Initialize()
  13. {
  14. SubscribeLocalEvent<NoiseRangeCarverComponent, PrePlaceDebrisFeatureEvent>(OnPrePlaceDebris);
  15. }
  16. private void OnPrePlaceDebris(EntityUid uid, NoiseRangeCarverComponent component,
  17. ref PrePlaceDebrisFeatureEvent args)
  18. {
  19. var coords = WorldGen.WorldToChunkCoords(args.Coords.ToMapPos(EntityManager, _transform));
  20. var val = _index.Evaluate(uid, component.NoiseChannel, coords);
  21. foreach (var (low, high) in component.Ranges)
  22. {
  23. if (low > val || high < val)
  24. continue;
  25. args.Handled = true;
  26. return;
  27. }
  28. }
  29. }