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);

View File

@ -245,6 +245,8 @@ public class Block extends UnlockableContent implements Senseable{
public boolean allowDiagonal = true;
/** Whether to swap the diagonal placement modes. */
public boolean swapDiagonalPlacement;
/** Whether to allow rectangular placement, as opposed to a line. Only supported for 1x1 blocks currently! */
public boolean allowRectanglePlacement = false;
/** Build queue priority in schematics. */
public int schematicPriority = 0;
/**
@ -322,6 +324,8 @@ public class Block extends UnlockableContent implements Senseable{
public float deconstructThreshold = 0f;
/** If true, this block deconstructs immediately. Instant deconstruction implies no resource refund. */
public boolean instantDeconstruct = false;
/** If true, this block constructs immediately. This implies no resource requirement, and ignores configs - do not use, this is for performance only! */
public boolean instantBuild = false;
/** Effect for placing the block. Passes size as rotation. */
public Effect placeEffect = Fx.placeBlock;
/** Effect for breaking the block. Passes size as rotation. */

View File

@ -122,6 +122,14 @@ public class Build{
}
});
//complete it immediately
if(result.instantBuild){
Events.fire(new BlockBuildBeginEvent(tile, team, unit, false));
result.placeBegan(tile, tile.block, unit);
ConstructBlock.constructFinish(tile, result, unit, (byte)rotation, team, null);
return;
}
Block previous = tile.block();
Block sub = ConstructBlock.get(result.size);
var prevBuild = new Seq<Building>(9);

View File

@ -83,7 +83,7 @@ public class ConstructBlock extends Block{
tile.setBlock(block, team, rotation);
}
if(tile.build != null){
if(tile.build != null && tile.build.block == block){
tile.build.health = block.health * healthf;
if(config != null){
@ -100,11 +100,11 @@ public class ConstructBlock extends Block{
//make sure block indexer knows it's damaged
indexer.notifyHealthChanged(tile.build);
}
//last builder was this local client player, call placed()
if(tile.build != null && !headless && builder == player.unit()){
tile.build.playerPlaced(config);
//last builder was this local client player, call placed()
if(!headless && builder == player.unit()){
tile.build.playerPlaced(config);
}
}
if(fogControl.isVisibleTile(team, tile.x, tile.y)){

View File

@ -90,6 +90,8 @@ public class Floor extends Block{
super(name);
this.variants = variants;
placeableLiquid = true;
allowRectanglePlacement = true;
instantBuild = true;
}
@Override

View File

@ -20,6 +20,8 @@ public class StaticWall extends Prop{
solid = true;
variants = 2;
cacheLayer = CacheLayer.walls;
allowRectanglePlacement = true;
instantBuild = true;
}
@Override