From 718a40d742717c68447d604b7493aa11f27b8773 Mon Sep 17 00:00:00 2001 From: Anuken Date: Fri, 15 Jan 2021 16:04:26 -0500 Subject: [PATCH] More pattern matching --- core/src/mindustry/entities/comp/BuildingComp.java | 2 +- core/src/mindustry/world/blocks/ConstructBlock.java | 2 +- .../mindustry/world/blocks/distribution/StackConveyor.java | 4 ++-- core/src/mindustry/world/blocks/power/PowerNode.java | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/core/src/mindustry/entities/comp/BuildingComp.java b/core/src/mindustry/entities/comp/BuildingComp.java index 2067c328db..1fa2d7c372 100644 --- a/core/src/mindustry/entities/comp/BuildingComp.java +++ b/core/src/mindustry/entities/comp/BuildingComp.java @@ -906,7 +906,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc, tempTiles.clear(); Geometry.circle(tileX(), tileY(), range, (x, y) -> { Building other = world.build(x, y); - if(other != null && other.block instanceof PowerNode && ((PowerNode)other.block).linkValid(other, self()) && !PowerNode.insulated(other, self()) + if(other != null && other.block instanceof PowerNode node && node.linkValid(other, self()) && !PowerNode.insulated(other, self()) && !other.proximity().contains(this.self()) && !(block.outputsPower && proximity.contains(p -> p.power != null && p.power.graph == other.power.graph))){ tempTiles.add(other.tile); diff --git a/core/src/mindustry/world/blocks/ConstructBlock.java b/core/src/mindustry/world/blocks/ConstructBlock.java index f2ebd161dd..85ca209ab6 100644 --- a/core/src/mindustry/world/blocks/ConstructBlock.java +++ b/core/src/mindustry/world/blocks/ConstructBlock.java @@ -63,7 +63,7 @@ public class ConstructBlock extends Block{ if(tile == null) return; float healthf = tile.build == null ? 1f : tile.build.healthf(); - Seq prev = tile.build instanceof ConstructBuild ? ((ConstructBuild)tile.build).prevBuild : null; + Seq prev = tile.build instanceof ConstructBuild co ? co.prevBuild : null; tile.setBlock(block, team, rotation); diff --git a/core/src/mindustry/world/blocks/distribution/StackConveyor.java b/core/src/mindustry/world/blocks/distribution/StackConveyor.java index ceb9339635..b279f09b9d 100644 --- a/core/src/mindustry/world/blocks/distribution/StackConveyor.java +++ b/core/src/mindustry/world/blocks/distribution/StackConveyor.java @@ -92,8 +92,8 @@ public class StackConveyor extends Block implements Autotiler{ @Override public boolean rotatedOutput(int x, int y){ Building tile = world.build(x, y); - if(tile instanceof StackConveyorBuild){ - return ((StackConveyorBuild)tile).state != stateUnload; + if(tile instanceof StackConveyorBuild s){ + return s.state != stateUnload; } return super.rotatedOutput(x, y); } diff --git a/core/src/mindustry/world/blocks/power/PowerNode.java b/core/src/mindustry/world/blocks/power/PowerNode.java index 43c292e5b0..9982c1d324 100644 --- a/core/src/mindustry/world/blocks/power/PowerNode.java +++ b/core/src/mindustry/world/blocks/power/PowerNode.java @@ -246,9 +246,9 @@ public class PowerNode extends PowerBlock{ public boolean linkValid(Building tile, Building link, boolean checkMaxNodes){ if(tile == link || link == null || !link.block.hasPower || tile.team != link.team) return false; - if(overlaps(tile, link, laserRange * tilesize) || (link.block instanceof PowerNode && overlaps(link, tile, ((PowerNode)link.block).laserRange * tilesize))){ - if(checkMaxNodes && link.block instanceof PowerNode){ - return link.power.links.size < ((PowerNode)link.block).maxNodes || link.power.links.contains(tile.pos()); + if(overlaps(tile, link, laserRange * tilesize) || (link.block instanceof PowerNode node && overlaps(link, tile, node.laserRange * tilesize))){ + if(checkMaxNodes && link.block instanceof PowerNode node){ + return link.power.links.size < node.maxNodes || link.power.links.contains(tile.pos()); } return true; }