From 1bd4c96ee8b2021762c87055fc3e1076b832c84e Mon Sep 17 00:00:00 2001 From: Anuken Date: Wed, 31 Mar 2021 22:36:46 -0400 Subject: [PATCH] Power node placement fixes --- core/src/mindustry/core/UI.java | 10 +++++++--- core/src/mindustry/entities/comp/BuildingComp.java | 4 ++++ core/src/mindustry/world/blocks/power/PowerNode.java | 2 -- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/core/src/mindustry/core/UI.java b/core/src/mindustry/core/UI.java index 7503e1ce3a..7738da6706 100644 --- a/core/src/mindustry/core/UI.java +++ b/core/src/mindustry/core/UI.java @@ -536,15 +536,19 @@ public class UI implements ApplicationListener, Loadable{ } public static String formatAmount(int number){ + //prevent overflow + if(number == Integer.MIN_VALUE) number ++; + int mag = Math.abs(number); + String sign = number < 0 ? "-" : ""; if(mag >= 1_000_000_000){ - return Strings.fixed(number / 1_000_000_000f, 1) + "[gray]" + Core.bundle.get("unit.billions") + "[]"; + return sign + Strings.fixed(mag / 1_000_000_000f, 1) + "[gray]" + Core.bundle.get("unit.billions") + "[]"; }else if(mag >= 1_000_000){ - return Strings.fixed(number / 1_000_000f, 1) + "[gray]" + Core.bundle.get("unit.millions") + "[]"; + return sign + Strings.fixed(mag / 1_000_000f, 1) + "[gray]" + Core.bundle.get("unit.millions") + "[]"; }else if(mag >= 10_000){ return number / 1000 + "[gray]" + Core.bundle.get("unit.thousands") + "[]"; }else if(mag >= 1000){ - return Strings.fixed(number / 1000f, 1) + "[gray]" + Core.bundle.get("unit.thousands") + "[]"; + return sign + Strings.fixed(mag / 1000f, 1) + "[gray]" + Core.bundle.get("unit.thousands") + "[]"; }else{ return number + ""; } diff --git a/core/src/mindustry/entities/comp/BuildingComp.java b/core/src/mindustry/entities/comp/BuildingComp.java index dd5fa7c335..62cd2b9b32 100644 --- a/core/src/mindustry/entities/comp/BuildingComp.java +++ b/core/src/mindustry/entities/comp/BuildingComp.java @@ -84,10 +84,12 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc, create(tile.block(), team); }else{ if(block.hasPower){ + power.init = false; //reinit power graph new PowerGraph().add(self()); } } + proximity.clear(); this.rotation = rotation; this.tile = tile; @@ -757,6 +759,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc, } } + /** in overrides, this does the exact same thing as onProximityUpdate, use that instead */ public void onProximityAdded(){ if(block.hasPower) updatePowerGraph(); } @@ -1216,6 +1219,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc, other.proximity.remove(self(), true); other.onProximityUpdate(); } + proximity.clear(); } public void updateProximity(){ diff --git a/core/src/mindustry/world/blocks/power/PowerNode.java b/core/src/mindustry/world/blocks/power/PowerNode.java index 476511e4a1..58c59861fc 100644 --- a/core/src/mindustry/world/blocks/power/PowerNode.java +++ b/core/src/mindustry/world/blocks/power/PowerNode.java @@ -363,8 +363,6 @@ public class PowerNode extends PowerBlock{ @Override public void dropped(){ power.links.clear(); - //create new power graph to manually unlink (this may be redundant) - new PowerGraph().add(this); } @Override