Fixed certain structures generating out of bounds

This commit is contained in:
kuroppoi 2022-04-16 21:20:40 +02:00
parent b2c7b3727a
commit 2269b4eb5f
2 changed files with 5 additions and 4 deletions

View file

@ -44,6 +44,9 @@ public class GeneratorContext {
}
public void placePrefab(Prefab prefab, int x, int y) {
x = Math.max(1, Math.min(x, getWidth() - prefab.getWidth() - 1));
y = Math.max(1, Math.min(y, getHeight() - prefab.getHeight() - 3));
if(!willPrefabOverlap(prefab, x, y)) {
zone.placePrefab(prefab, x, y, random);
prefabs.put(new BlockPosition(x, y), prefab);

View file

@ -33,9 +33,9 @@ public class StructureGenerator implements GeneratorTask {
placeRandomSpawnTower(ctx, (int)(width * 0.8));
for(Prefab structure : uniqueStructures) {
int x = ctx.nextInt(width - 2) + 1;
int x = ctx.nextInt(width);
int minY = ctx.getZone().getSurface()[x];
int y = ctx.nextInt(height - minY - 2) + minY;
int y = ctx.nextInt(height - minY) + minY;
ctx.placePrefab(structure, x, y);
}
@ -49,9 +49,7 @@ public class StructureGenerator implements GeneratorTask {
if(ctx.isUnderground(x, y) && ctx.isUnderground(x + prefabWidth, y)) {
int placeX = x + (prefabWidth >= dungeonRegion.getX() ? x : ctx.nextInt(dungeonRegion.getX() - prefabWidth));
placeX = Math.max(1, Math.min(placeX, width - prefabWidth - 1));
int placeY = y + (prefabHeight >= dungeonRegion.getY() ? y : ctx.nextInt(dungeonRegion.getY() - prefabHeight));
placeY = Math.max(1, Math.min(placeY, height - prefabHeight - 2));
ctx.placePrefab(dungeon, placeX, placeY);
}
}