From 4690aae19781374a2ee6f95a5b5b8f33d0abc1b5 Mon Sep 17 00:00:00 2001 From: Anuken Date: Fri, 5 Mar 2021 14:00:53 -0500 Subject: [PATCH] Fixed cores being replaceable --- core/src/mindustry/entities/comp/BuildingComp.java | 2 +- core/src/mindustry/entities/comp/UnitComp.java | 6 +++++- core/src/mindustry/logic/GlobalConstants.java | 8 +++++--- core/src/mindustry/world/Block.java | 4 +++- core/src/mindustry/world/blocks/storage/CoreBlock.java | 1 + gradle.properties | 2 +- 6 files changed, 16 insertions(+), 7 deletions(-) diff --git a/core/src/mindustry/entities/comp/BuildingComp.java b/core/src/mindustry/entities/comp/BuildingComp.java index dfa7fd75cc..694611fed3 100644 --- a/core/src/mindustry/entities/comp/BuildingComp.java +++ b/core/src/mindustry/entities/comp/BuildingComp.java @@ -1325,7 +1325,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc, case powerNetStored -> power == null ? 0 : power.graph.getLastPowerStored(); case powerNetCapacity -> power == null ? 0 : power.graph.getLastCapacity(); case enabled -> enabled ? 1 : 0; - case controlled -> this instanceof ControlBlock c && c.isControlled() ? 2 : 0; + case controlled -> this instanceof ControlBlock c && c.isControlled() ? GlobalConstants.ctrlPlayer : 0; case payloadCount -> getPayload() != null ? 1 : 0; case size -> block.size; default -> Float.NaN; //gets converted to null in logic diff --git a/core/src/mindustry/entities/comp/UnitComp.java b/core/src/mindustry/entities/comp/UnitComp.java index bd251d4d3b..1db14dcc41 100644 --- a/core/src/mindustry/entities/comp/UnitComp.java +++ b/core/src/mindustry/entities/comp/UnitComp.java @@ -139,7 +139,11 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I case mineX -> mining() ? mineTile.x : -1; case mineY -> mining() ? mineTile.y : -1; case flag -> flag; - case controlled -> !isValid() ? 0 : controller instanceof LogicAI ? 1 : controller instanceof Player ? 2 : controller instanceof FormationAI ? 3 : 0; + case controlled -> !isValid() ? 0 : + controller instanceof LogicAI ? GlobalConstants.ctrlProcessor : + controller instanceof Player ? GlobalConstants.ctrlPlayer : + controller instanceof FormationAI ? GlobalConstants.ctrlFormation : + 0; case commanded -> controller instanceof FormationAI && isValid() ? 1 : 0; case payloadCount -> self() instanceof Payloadc pay ? pay.payloads().size : 0; case size -> hitSize / tilesize; diff --git a/core/src/mindustry/logic/GlobalConstants.java b/core/src/mindustry/logic/GlobalConstants.java index be0500bc77..b13c658611 100644 --- a/core/src/mindustry/logic/GlobalConstants.java +++ b/core/src/mindustry/logic/GlobalConstants.java @@ -9,6 +9,8 @@ import mindustry.world.*; /** Stores global constants for logic processors. */ public class GlobalConstants{ + public static final int ctrlProcessor = 1, ctrlPlayer = 2, ctrlFormation = 3; + private ObjectIntMap namesToIds = new ObjectIntMap<>(); private Seq vars = new Seq<>(Var.class); @@ -21,9 +23,9 @@ public class GlobalConstants{ //special enums - put("@ctrlProcessor", 1); - put("@ctrlPlayer", 2); - put("@ctrlFormation", 3); + put("@ctrlProcessor", ctrlProcessor); + put("@ctrlPlayer", ctrlPlayer); + put("@ctrlFormation", ctrlFormation); //store base content diff --git a/core/src/mindustry/world/Block.java b/core/src/mindustry/world/Block.java index e40fdbca45..613411e6e0 100644 --- a/core/src/mindustry/world/Block.java +++ b/core/src/mindustry/world/Block.java @@ -123,6 +123,8 @@ public class Block extends UnlockableContent{ public boolean fillsTile = true; /** whether this block can be replaced in all cases */ public boolean alwaysReplace = false; + /** if false, this block can never be replaced. */ + public boolean replaceable = true; /** The block group. Unless {@link #canReplace} is overriden, blocks in the same group can replace each other. */ public BlockGroup group = BlockGroup.none; /** List of block flags. Used for AI indexing. */ @@ -410,7 +412,7 @@ public class Block extends UnlockableContent{ public boolean canReplace(Block other){ if(other.alwaysReplace) return true; - return (other != this || rotate) && this.group != BlockGroup.none && other.group == this.group && + return other.replaceable && (other != this || rotate) && this.group != BlockGroup.none && other.group == this.group && (size == other.size || (size >= other.size && ((subclass != null && subclass == other.subclass) || group.anyReplace))); } diff --git a/core/src/mindustry/world/blocks/storage/CoreBlock.java b/core/src/mindustry/world/blocks/storage/CoreBlock.java index 087ba838fd..45b2ce32d1 100644 --- a/core/src/mindustry/world/blocks/storage/CoreBlock.java +++ b/core/src/mindustry/world/blocks/storage/CoreBlock.java @@ -52,6 +52,7 @@ public class CoreBlock extends StorageBlock{ loopSoundVolume = 1f; drawDisabled = false; canOverdrive = false; + replaceable = false; } @Remote(called = Loc.server) diff --git a/gradle.properties b/gradle.properties index 8d7da5a740..75a3570010 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ org.gradle.daemon=true org.gradle.jvmargs=-Xms256m -Xmx1024m -archash=e270ac561e10cbc1dc1f13907d75d614e2d51be0 +archash=1b24d685ea94dd40244be869e70671080e950825