diff --git a/NewHorizons/Builder/Props/ScatterBuilder.cs b/NewHorizons/Builder/Props/ScatterBuilder.cs
index c949d026..cbae6db3 100644
--- a/NewHorizons/Builder/Props/ScatterBuilder.cs
+++ b/NewHorizons/Builder/Props/ScatterBuilder.cs
@@ -52,6 +52,9 @@ namespace NewHorizons.Builder.Props
else prefab = SearchUtilities.Find(propInfo.path);
for (int i = 0; i < propInfo.count; i++)
{
+ // Failsafe
+ if (points.Count == 0) break;
+
var randomInd = (int)Random.Range(0, points.Count - 1);
var point = points[randomInd];
@@ -63,19 +66,25 @@ namespace NewHorizons.Builder.Props
float latitude = sphericals.y;
float sampleX = heightMapTexture.width * longitude / 360f;
+
+ // Fix wrapping issue
+ if (sampleX > heightMapTexture.width) sampleX -= heightMapTexture.width;
+ if (sampleX < 0) sampleX += heightMapTexture.width;
+
float sampleY = heightMapTexture.height * latitude / 180f;
float relativeHeight = heightMapTexture.GetPixel((int)sampleX, (int)sampleY).r;
height = (relativeHeight * (heightMap.maxHeight - heightMap.minHeight) + heightMap.minHeight);
+ if ((propInfo.minHeight != null && height < propInfo.minHeight) || (propInfo.maxHeight != null && height > propInfo.maxHeight))
+ {
+ // Try this point again
+ i--;
+ continue;
+ }
+
// Because heightmaps are dumb gotta rotate it 90 degrees around the x axis bc UHHHHHHHHHHHHH
point = Quaternion.Euler(90, 0, 0) * point;
-
- // Keep things mostly above water
- if (config.Water != null && height - 1f < config.Water.size) continue;
-
- // Move it slightly into the ground
- height -= 0.01f;
}
var prop = DetailBuilder.MakeDetail(go, sector, prefab, (MVector3)(point.normalized * height), null, propInfo.scale, true);
diff --git a/NewHorizons/External/Modules/PropModule.cs b/NewHorizons/External/Modules/PropModule.cs
index 674480d2..4963bb70 100644
--- a/NewHorizons/External/Modules/PropModule.cs
+++ b/NewHorizons/External/Modules/PropModule.cs
@@ -130,6 +130,16 @@ namespace NewHorizons.External.Modules
/// The number used as entropy for scattering the props
///
public int seed;
+
+ ///
+ /// The lowest height that these object will be placed at (only relevant if there's a heightmap)
+ ///
+ public float? minHeight;
+
+ ///
+ /// The highest height that these objects will be placed at (only relevant if there's a heightmap)
+ ///
+ public float? maxHeight;
}
[JsonObject]