diff --git a/core/src/mindustry/mod/ContentPatcher.java b/core/src/mindustry/mod/ContentPatcher.java index ea4e1c5917..6e84a7870c 100644 --- a/core/src/mindustry/mod/ContentPatcher.java +++ b/core/src/mindustry/mod/ContentPatcher.java @@ -363,7 +363,7 @@ public class ContentPatcher{ try{ if(value instanceof JsonValue jsv){ //setting values from object - if(prevValue == null || !jsv.isObject() || jsv.has("type") || (metadata != null && metadata.type == Attributes.class)){ + if(prevValue == null || !jsv.isObject() || (jsv.has("type") && metadata.type != MappableContent.class) || (metadata != null && metadata.type == Attributes.class)){ if(UnlockableContent.class.isAssignableFrom(metadata.type) && jsv.isObject()){ warn("New content must not be instantiated: @", jsv); return; diff --git a/core/src/mindustry/type/UnitType.java b/core/src/mindustry/type/UnitType.java index ac821e0df2..2e233c59e1 100644 --- a/core/src/mindustry/type/UnitType.java +++ b/core/src/mindustry/type/UnitType.java @@ -829,6 +829,28 @@ public class UnitType extends UnlockableContent implements Senseable{ } } + void initPathType(){ + if(flowfieldPathType == -1){ + flowfieldPathType = + naval ? Pathfinder.costNaval : + allowLegStep ? Pathfinder.costLegs : + flying ? Pathfinder.costNone : + hovering ? Pathfinder.costHover : + Pathfinder.costGround; + } + + if(pathCost == null){ + pathCost = + naval ? ControlPathfinder.costNaval : + allowLegStep ? ControlPathfinder.costLegs : + hovering ? ControlPathfinder.costHover : + ControlPathfinder.costGround; + } + + pathCostId = ControlPathfinder.costTypes.indexOf(pathCost); + if(pathCostId == -1) pathCostId = 0; + } + @CallSuper @Override public void init(){ @@ -852,25 +874,7 @@ public class UnitType extends UnlockableContent implements Senseable{ } } - if(flowfieldPathType == -1){ - flowfieldPathType = - naval ? Pathfinder.costNaval : - allowLegStep ? Pathfinder.costLegs : - flying ? Pathfinder.costNone : - hovering ? Pathfinder.costHover : - Pathfinder.costGround; - } - - if(pathCost == null){ - pathCost = - naval ? ControlPathfinder.costNaval : - allowLegStep ? ControlPathfinder.costLegs : - hovering ? ControlPathfinder.costHover : - ControlPathfinder.costGround; - } - - pathCostId = ControlPathfinder.costTypes.indexOf(pathCost); - if(pathCostId == -1) pathCostId = 0; + initPathType(); if(flying){ envEnabled |= Env.space; @@ -1232,6 +1236,12 @@ public class UnitType extends UnlockableContent implements Senseable{ public void afterPatch(){ super.afterPatch(); totalRequirements = cachedRequirements = firstRequirements = null; + + //this will technically reset any assigned values, but in vanilla, they're not reassigned anyway + flowfieldPathType = -1; + pathCost = null; + pathCostId = -1; + initPathType(); } /** @return the time required to build this unit, as a value that takes into account reconstructors */ diff --git a/core/src/mindustry/world/blocks/production/GenericCrafter.java b/core/src/mindustry/world/blocks/production/GenericCrafter.java index 9fe01d436e..4bdd25d7b4 100644 --- a/core/src/mindustry/world/blocks/production/GenericCrafter.java +++ b/core/src/mindustry/world/blocks/production/GenericCrafter.java @@ -11,6 +11,7 @@ import mindustry.entities.*; import mindustry.entities.units.*; import mindustry.gen.*; import mindustry.logic.*; +import mindustry.mod.*; import mindustry.type.*; import mindustry.world.*; import mindustry.world.blocks.liquid.Conduit.*; @@ -43,6 +44,7 @@ public class GenericCrafter extends Block{ public float updateEffectSpread = 4f; public float warmupSpeed = 0.019f; /** Only used for legacy cultivator blocks. */ + @NoPatch public boolean legacyReadWarmup = false; public DrawBlock drawer = new DrawDefault(); diff --git a/tests/src/test/java/PatcherTests.java b/tests/src/test/java/PatcherTests.java index e23cc9149e..f7ea1bc7fc 100644 --- a/tests/src/test/java/PatcherTests.java +++ b/tests/src/test/java/PatcherTests.java @@ -165,6 +165,20 @@ public class PatcherTests{ assertEquals(0, UnitTypes.dagger.abilities.size); } + @Test + void testUnitTypeObject() throws Exception{ + Vars.state.patcher.apply(Seq.with(""" + { + "name": "object syntax", + "unit.dagger": { + "type": "legs" + } + } + """)); + + assertEquals(new Seq<>(), Vars.state.patcher.patches.first().warnings); + } + @Test void testUnitFlagsArray() throws Exception{ int oldLength = UnitTypes.dagger.targetFlags.length;