Skip to content

Commit

Permalink
Allow conveyors/ducts to use duct/conveyor bridges
Browse files Browse the repository at this point in the history
  • Loading branch information
patatayui authored Sep 5, 2024
1 parent 5bff681 commit 3f69c79
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
6 changes: 3 additions & 3 deletions core/src/mindustry/input/Placement.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ public static boolean isSidePlace(Seq<BuildPlan> plans){
}

public static void calculateBridges(Seq<BuildPlan> plans, ItemBridge bridge){
calculateBridges(plans, bridge, t -> false);
calculateBridges(plans, bridge, false, t -> false);
}

public static void calculateBridges(Seq<BuildPlan> plans, ItemBridge bridge, Boolf<Block> avoid){
public static void calculateBridges(Seq<BuildPlan> plans, ItemBridge bridge, boolean hasJunction, Boolf<Block> avoid){
if(isSidePlace(plans) || plans.size == 0) return;

//check for orthogonal placement + unlocked state
Expand Down Expand Up @@ -170,7 +170,7 @@ public static void calculateBridges(Seq<BuildPlan> plans, ItemBridge bridge, Boo
continue outer;
}else if(placeable.get(other)){

if(wereSame){
if(wereSame && hasJunction){
//the gap is fake, it's just conveyors that can be replaced with junctions
i ++;
continue outer;
Expand Down
7 changes: 4 additions & 3 deletions core/src/mindustry/world/blocks/distribution/Conveyor.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void init(){
super.init();

if(junctionReplacement == null) junctionReplacement = Blocks.junction;
if(bridgeReplacement == null || !(bridgeReplacement instanceof ItemBridge)) bridgeReplacement = Blocks.itemBridge;
if(bridgeReplacement == null || !(bridgeReplacement instanceof ItemBridge || bridgeReplacement instanceof DuctBridge)) bridgeReplacement = Blocks.itemBridge;
}

@Override
Expand Down Expand Up @@ -92,8 +92,9 @@ public boolean canReplace(Block other){
@Override
public void handlePlacementLine(Seq<BuildPlan> plans){
if(bridgeReplacement == null) return;

Placement.calculateBridges(plans, (ItemBridge)bridgeReplacement, b -> b instanceof Conveyor);
boolean hasJuntionReplacement = junctionReplacement != null;
if(bridgeReplacement instanceof DuctBridge) Placement.calculateBridges(plans, (DuctBridge)bridgeReplacement, hasJuntionReplacement, b -> b instanceof Duct || b instanceof Conveyor);
if(bridgeReplacement instanceof ItemBridge) Placement.calculateBridges(plans, (ItemBridge)bridgeReplacement, hasJuntionReplacement, b -> b instanceof Conveyor);
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions core/src/mindustry/world/blocks/distribution/Duct.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void setStats(){
public void init(){
super.init();

if(bridgeReplacement == null || !(bridgeReplacement instanceof DuctBridge)) bridgeReplacement = Blocks.ductBridge;
if(bridgeReplacement == null || !(bridgeReplacement instanceof DuctBridge || bridgeReplacement instanceof ItemBridge)) bridgeReplacement = Blocks.ductBridge;
}

@Override
Expand Down Expand Up @@ -106,8 +106,8 @@ public TextureRegion[] icons(){
@Override
public void handlePlacementLine(Seq<BuildPlan> plans){
if(bridgeReplacement == null) return;

Placement.calculateBridges(plans, (DuctBridge)bridgeReplacement, false, b -> b instanceof Duct || b instanceof StackConveyor || b instanceof Conveyor);
if(bridgeReplacement instanceof ItemBridge) Placement.calculateBridges(plans, (ItemBridge)bridgeReplacement, false, b -> b instanceof Duct || b instanceof StackConveyor || b instanceof Conveyor);
if(bridgeReplacement instanceof DuctBridge) Placement.calculateBridges(plans, (DuctBridge)bridgeReplacement, false, b -> b instanceof Duct || b instanceof StackConveyor || b instanceof Conveyor);
}

public class DuctBuild extends Building{
Expand Down
2 changes: 1 addition & 1 deletion core/src/mindustry/world/blocks/liquid/Conduit.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public void handlePlacementLine(Seq<BuildPlan> plans){
if(rotBridgeReplacement instanceof DirectionBridge duct){
Placement.calculateBridges(plans, duct, true, b -> b instanceof Conduit);
}else{
Placement.calculateBridges(plans, (ItemBridge)bridgeReplacement, b -> b instanceof Conduit);
Placement.calculateBridges(plans, (ItemBridge)bridgeReplacement, true, b -> b instanceof Conduit);
}
}

Expand Down

0 comments on commit 3f69c79

Please sign in to comment.