From 3eea0ea0651190942c9c8dfe0d14f0a0d40caeca Mon Sep 17 00:00:00 2001 From: Anuken Date: Wed, 4 Mar 2020 13:48:00 -0500 Subject: [PATCH] Bugfixes, tweaks --- .../mindustry/world/blocks/BuildBlock.java | 2 +- .../world/blocks/distribution/ItemBridge.java | 2 +- .../world/blocks/power/PowerNode.java | 38 +++++++++++++++---- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/core/src/mindustry/world/blocks/BuildBlock.java b/core/src/mindustry/world/blocks/BuildBlock.java index dc1104f4ef..68cbdf567a 100644 --- a/core/src/mindustry/world/blocks/BuildBlock.java +++ b/core/src/mindustry/world/blocks/BuildBlock.java @@ -68,7 +68,7 @@ public class BuildBlock extends Block{ tile.entity.health(block.health * healthf); } //last builder was this local client player, call placed() - if(!headless && builderID == player.id()){ + if(!headless && builderID == player.unit().id()){ if(!skipConfig){ tile.block().playerPlaced(tile); } diff --git a/core/src/mindustry/world/blocks/distribution/ItemBridge.java b/core/src/mindustry/world/blocks/distribution/ItemBridge.java index 9252fbb9a3..6f79e310f9 100644 --- a/core/src/mindustry/world/blocks/distribution/ItemBridge.java +++ b/core/src/mindustry/world/blocks/distribution/ItemBridge.java @@ -86,7 +86,7 @@ public class ItemBridge extends Block{ } public Tile findLink(int x, int y){ - if(world.tile(x, y) != null && linkValid(world.tile(x, y), world.tile(lastPlaced)) && lastPlaced != Point2.pack(x, y)){ + if(world.tiles.in(x, y) && linkValid(world.tile(x, y), world.tile(lastPlaced)) && lastPlaced != Point2.pack(x, y)){ return world.tile(lastPlaced); } return null; diff --git a/core/src/mindustry/world/blocks/power/PowerNode.java b/core/src/mindustry/world/blocks/power/PowerNode.java index 0e2071e50b..7ee1d39944 100644 --- a/core/src/mindustry/world/blocks/power/PowerNode.java +++ b/core/src/mindustry/world/blocks/power/PowerNode.java @@ -1,14 +1,15 @@ package mindustry.world.blocks.power; import arc.*; -import arc.struct.*; import arc.func.*; import arc.graphics.*; import arc.graphics.g2d.*; import arc.math.*; import arc.math.geom.*; -import arc.util.*; +import arc.struct.*; import arc.util.ArcAnnotate.*; +import arc.util.*; +import mindustry.entities.units.*; import mindustry.gen.*; import mindustry.graphics.*; import mindustry.ui.*; @@ -20,6 +21,7 @@ import static mindustry.Vars.*; public class PowerNode extends PowerBlock{ protected static boolean returnValue = false; + protected static BuildRequest otherReq; protected final ObjectSet graphs = new ObjectSet<>(); protected final Vec2 t1 = new Vec2(), t2 = new Vec2(); @@ -287,6 +289,25 @@ public class PowerNode extends PowerBlock{ Draw.reset(); } + @Override + public void drawRequestConfigTop(BuildRequest req, Eachable list){ + if(req.config instanceof Point2[]){ + for(Point2 point : (Point2[])req.config){ + otherReq = null; + list.each(other -> { + if(other.x == point.x && other.y == point.y){ + Log.info("found match " + other); + otherReq = other; + } + }); + + if(otherReq == null || otherReq.block == null) return; + + drawLaser(req.drawx(), req.drawy(), otherReq.drawx(), otherReq.drawy(), 1f, size, otherReq.block.size); + } + } + } + protected boolean linked(Tile tile, Tile other){ return tile.entity.power().links.contains(other.pos()); } @@ -321,24 +342,25 @@ public class PowerNode extends PowerBlock{ } protected void drawLaser(Tile tile, Tile target){ + drawLaser(tile.drawx(), tile.drawy(), target.drawx(), target.drawy(), tile.entity.power().graph.getSatisfaction(), size, target.block().size); + } + + protected void drawLaser(float x1, float y1, float x2, float y2, float satisfaction, int size1, int size2){ int opacityPercentage = Core.settings.getInt("lasersopacity"); if(opacityPercentage == 0) return; float opacity = opacityPercentage / 100f; - float x1 = tile.drawx(), y1 = tile.drawy(), - x2 = target.drawx(), y2 = target.drawy(); - float angle1 = Angles.angle(x1, y1, x2, y2); - t1.trns(angle1, tile.block().size * tilesize / 2f - 1.5f); - t2.trns(angle1 + 180f, target.block().size * tilesize / 2f - 1.5f); + t1.trns(angle1, size1 * tilesize / 2f - 1.5f); + t2.trns(angle1 + 180f, size2 * tilesize / 2f - 1.5f); x1 += t1.x; y1 += t1.y; x2 += t2.x; y2 += t2.y; - float fract = 1f - tile.entity.power().graph.getSatisfaction(); + float fract = 1f - satisfaction; Draw.color(Color.white, Pal.powerLight, fract * 0.86f + Mathf.absin(3f, 0.1f)); Draw.alpha(opacity);