Automatic conveyor/conduit bridging

This commit is contained in:
Anuken
2021-02-22 10:15:40 -05:00
parent 9e8a2b8296
commit e2515fc4bf
8 changed files with 95 additions and 18 deletions

View File

@@ -12,6 +12,7 @@ import mindustry.content.*;
import mindustry.entities.units.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.input.*;
import mindustry.type.*;
import mindustry.ui.*;
import mindustry.world.*;
@@ -71,6 +72,17 @@ public class Conveyor extends Block implements Autotiler{
&& lookingAtEither(tile, rotation, otherx, othery, otherrot, otherblock);
}
//stack conveyors should be bridged over, not replaced
@Override
public boolean canReplace(Block other){
return super.canReplace(other) && !(other instanceof StackConveyor);
}
@Override
public void handlePlacementLine(Seq<BuildPlan> plans){
Placement.calculateBridges(plans, (ItemBridge)Blocks.itemBridge);
}
@Override
public TextureRegion[] icons(){
return new TextureRegion[]{regions[0][0]};

View File

@@ -1,6 +1,5 @@
package mindustry.world.blocks.distribution;
import arc.*;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.math.*;
@@ -32,10 +31,7 @@ public class ItemBridge extends Block{
public @Load("@-arrow") TextureRegion arrowRegion;
//for autolink
@Nullable
public ItemBridgeBuild lastBuild;
@Nullable
public BuildPlan lastPlan;
public @Nullable ItemBridgeBuild lastBuild;
public ItemBridge(String name){
super(name);
@@ -151,12 +147,12 @@ public class ItemBridge extends Block{
}
@Override
public void onNewPlan(BuildPlan plan){
if(lastPlan != null && lastPlan.config == null && positionsValid(lastPlan.x, lastPlan.y, plan.x, plan.y)){
lastPlan.config = new Point2(plan.x - lastPlan.x, plan.y - lastPlan.y);
public void handlePlacementLine(Seq<BuildPlan> plans){
for(int i = 0; i < plans.size - 1; i++){
var cur = plans.get(i);
var next = plans.get(i + 1);
cur.config = new Point2(next.x - cur.x, next.y - cur.y);
}
lastPlan = plan;
}
@Override
@@ -176,12 +172,12 @@ public class ItemBridge extends Block{
public void playerPlaced(Object config){
super.playerPlaced(config);
if(config == null){
//if(config == null){
Tile link = findLink(tile.x, tile.y);
if(linkValid(tile, link) && !proximity.contains(link.build)){
link.build.configure(tile.pos());
}
}
//}
lastBuild = this;
}

View File

@@ -13,6 +13,7 @@ import mindustry.content.*;
import mindustry.entities.units.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.input.*;
import mindustry.type.*;
import mindustry.world.*;
import mindustry.world.blocks.*;
@@ -69,6 +70,11 @@ public class Conduit extends LiquidBlock implements Autotiler{
return otherblock.hasLiquids && (otherblock.outputsLiquid || (lookingAt(tile, rotation, otherx, othery, otherblock))) && lookingAtEither(tile, rotation, otherx, othery, otherrot, otherblock);
}
@Override
public void handlePlacementLine(Seq<BuildPlan> plans){
Placement.calculateBridges(plans, (ItemBridge)Blocks.bridgeConduit);
}
@Override
public TextureRegion[] icons(){
return new TextureRegion[]{Core.atlas.find("conduit-bottom"), topRegions[0]};