Skip to content

Commit

Permalink
Merge branch 'Anuken:master' into id_ID
Browse files Browse the repository at this point in the history
  • Loading branch information
DaGamerFiles authored Jan 23, 2024
2 parents cf29e49 + 76e83c1 commit e942e4b
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 10 deletions.
4 changes: 3 additions & 1 deletion core/src/mindustry/input/InputHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -1973,11 +1973,13 @@ void iterateLine(int startX, int startY, int endX, int endY, Cons<PlaceLine> con
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.allowRectanglePlacement){
points = Placement.normalizeRectangle(startX, startY, endX, endY, block.size);
}else{
points = Placement.normalizeLine(startX, startY, endX, endY);
}
Expand Down
16 changes: 16 additions & 0 deletions core/src/mindustry/input/Placement.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ public static Seq<Point2> normalizeLine(int startX, int startY, int endX, int en
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 = 0; y <= maxY - minY; y += blockSize){
for(int x = 0; x <= maxX - minX; x += blockSize){
points.add(Pools.obtain(Point2.class, Point2::new).set(startX + x * Mathf.sign(endX - startX), startY + y * Mathf.sign(endY - startY)));
}
}

return points;
}

public static Seq<Point2> upgradeLine(int startX, int startY, int endX, int endY){
closed.clear();
Pools.freeAll(points);
Expand Down
4 changes: 4 additions & 0 deletions core/src/mindustry/world/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
public boolean allowRectanglePlacement = false;
/** Build queue priority in schematics. */
public int schematicPriority = 0;
/**
Expand Down Expand Up @@ -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. */
Expand Down
12 changes: 10 additions & 2 deletions core/src/mindustry/world/Build.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ public static void beginPlace(@Nullable Unit unit, Block result, Team team, int
}
});

//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);
Expand Down Expand Up @@ -195,7 +203,7 @@ public static boolean validPlace(Block type, Team team, int x, int y, int rotati
return false;
}

if(!type.requiresWater && !contactsShallows(tile.x, tile.y, type) && !type.placeableLiquid){
if(!type.requiresWater && !type.isFloor() && !contactsShallows(tile.x, tile.y, type) && !type.placeableLiquid){
return false;
}

Expand Down Expand Up @@ -223,7 +231,7 @@ public static boolean validPlace(Block type, Team team, int x, int y, int rotati
(check.floor().isDeep() && !type.floating && !type.requiresWater && !type.placeableLiquid) || //deep water
(type == check.block() && check.build != null && rotation == check.build.rotation && type.rotate && !((type == check.block && check.team() == Team.derelict))) || //same block, same rotation
!check.interactable(team) || //cannot interact
!check.floor().placeableOn || //solid wall
(!check.floor().placeableOn && !type.isFloor()) || //solid floor
(!checkVisible && !check.block().alwaysReplace) || //replacing a block that should be replaced (e.g. payload placement)
!(((type.canReplace(check.block()) || (type == check.block && state.rules.derelictRepair && check.team() == Team.derelict)) || //can replace type OR can replace derelict block of same type
(check.build instanceof ConstructBuild build && build.current == type && check.centerX() == tile.x && check.centerY() == tile.y)) && //same type in construction
Expand Down
10 changes: 5 additions & 5 deletions core/src/mindustry/world/blocks/ConstructBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static void constructFinish(Tile tile, Block block, @Nullable Unit builde
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){
Expand All @@ -100,11 +100,11 @@ public static void constructFinish(Tile tile, Block block, @Nullable Unit builde

//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)){
Expand Down
6 changes: 4 additions & 2 deletions core/src/mindustry/world/blocks/environment/Floor.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,15 @@ public class Floor extends Block{
protected TextureRegion edgeRegion;

public Floor(String name){
super(name);
variants = 3;
this(name, 3);
}

public Floor(String name, int variants){
super(name);
this.variants = variants;
placeableLiquid = true;
allowRectanglePlacement = true;
instantBuild = true;
}

@Override
Expand Down
2 changes: 2 additions & 0 deletions core/src/mindustry/world/blocks/environment/StaticWall.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public StaticWall(String name){
solid = true;
variants = 2;
cacheLayer = CacheLayer.walls;
allowRectanglePlacement = true;
instantBuild = true;
}

@Override
Expand Down

0 comments on commit e942e4b

Please sign in to comment.