Added allowRectanglePlacement for 1x1 blocks

This commit is contained in:
Anuken
2024-01-22 16:41:43 -05:00
parent 066fa04ded
commit bd4ae0639d
7 changed files with 40 additions and 6 deletions

View File

@@ -1973,11 +1973,13 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
var end = world.build(endX, endY);
if(diagonal && (block == null || block.allowDiagonal)){
if(block != null && start instanceof ChainedBuilding && end instanceof ChainedBuilding
&& block.canReplace(end.block) && block.canReplace(start.block)){
&& block.canReplace(end.block) && block.canReplace(start.block)){
points = Placement.upgradeLine(startX, startY, endX, endY);
}else{
points = Placement.pathfindLine(block != null && block.conveyorPlacement, startX, startY, endX, endY);
}
}else if(block != null && block.size == 1 && block.allowRectanglePlacement){
points = Placement.normalizeRectangle(startX, startY, endX, endY, block.size);
}else{
points = Placement.normalizeLine(startX, startY, endX, endY);
}

View File

@@ -58,6 +58,22 @@ public class Placement{
return points;
}
/** Normalize two points into a rectangle. */
public static Seq<Point2> normalizeRectangle(int startX, int startY, int endX, int endY, int blockSize){
Pools.freeAll(points);
points.clear();
int minX = Math.min(startX, endX), minY = Math.min(startY, endY), maxX = Math.max(startX, endX), maxY = Math.max(startY, endY);
for(int y = minY; y <= maxY; y += blockSize){
for(int x = minX; x <= maxX; x += blockSize){
points.add(Pools.obtain(Point2.class, Point2::new).set(x, y));
}
}
return points;
}
public static Seq<Point2> upgradeLine(int startX, int startY, int endX, int endY){
closed.clear();
Pools.freeAll(points);