From ac20b17e0b23bd41038bd2c68235947e1b351493 Mon Sep 17 00:00:00 2001 From: Anuken Date: Thu, 3 Jun 2021 13:58:56 -0400 Subject: [PATCH] Mod bugfixes --- .../entities/comp/WaterMoveComp.java | 1 - core/src/mindustry/graphics/MultiPacker.java | 4 ++++ core/src/mindustry/io/JsonIO.java | 13 ++++++++++++ core/src/mindustry/mod/ContentParser.java | 1 + .../world/blocks/distribution/Duct.java | 21 +++++++++++++++++++ .../world/blocks/distribution/DuctRouter.java | 2 +- core/src/mindustry/world/meta/Attribute.java | 8 +++++++ gradle.properties | 2 +- 8 files changed, 49 insertions(+), 3 deletions(-) diff --git a/core/src/mindustry/entities/comp/WaterMoveComp.java b/core/src/mindustry/entities/comp/WaterMoveComp.java index 69d178f41d..346a2898f8 100644 --- a/core/src/mindustry/entities/comp/WaterMoveComp.java +++ b/core/src/mindustry/entities/comp/WaterMoveComp.java @@ -15,7 +15,6 @@ import mindustry.type.*; import mindustry.world.*; import mindustry.world.blocks.environment.*; -//just a proof of concept @Component abstract class WaterMoveComp implements Posc, Velc, Hitboxc, Flyingc, Unitc{ @Import float x, y, rotation; diff --git a/core/src/mindustry/graphics/MultiPacker.java b/core/src/mindustry/graphics/MultiPacker.java index eb823ea991..f8d9e472e2 100644 --- a/core/src/mindustry/graphics/MultiPacker.java +++ b/core/src/mindustry/graphics/MultiPacker.java @@ -26,6 +26,10 @@ public class MultiPacker implements Disposable{ return null; } + public PixmapPacker getPacker(PageType type){ + return packers[type.ordinal()]; + } + public boolean has(String name){ for(var page : PageType.all){ if(packers[page.ordinal()].getRect(name) != null){ diff --git a/core/src/mindustry/io/JsonIO.java b/core/src/mindustry/io/JsonIO.java index ea15b3969c..c5b7986daa 100644 --- a/core/src/mindustry/io/JsonIO.java +++ b/core/src/mindustry/io/JsonIO.java @@ -8,6 +8,7 @@ import mindustry.ctype.*; import mindustry.game.*; import mindustry.type.*; import mindustry.world.*; +import mindustry.world.meta.*; import java.io.*; @@ -111,6 +112,18 @@ public class JsonIO{ } }); + json.setSerializer(Attribute.class, new Serializer<>(){ + @Override + public void write(Json json, Attribute object, Class knownType){ + json.writeValue(object.name); + } + + @Override + public Attribute read(Json json, JsonValue jsonData, Class type){ + return Attribute.get(jsonData.asString()); + } + }); + json.setSerializer(Item.class, new Serializer<>(){ @Override public void write(Json json, Item object, Class knownType){ diff --git a/core/src/mindustry/mod/ContentParser.java b/core/src/mindustry/mod/ContentParser.java index 720f5c2c02..7c77770cf3 100644 --- a/core/src/mindustry/mod/ContentParser.java +++ b/core/src/mindustry/mod/ContentParser.java @@ -61,6 +61,7 @@ public class ContentParser{ }); put(Interp.class, (type, data) -> field(Interp.class, data)); put(CacheLayer.class, (type, data) -> field(CacheLayer.class, data)); + put(Attribute.class, (type, data) -> Attribute.get(data.asString())); put(Schematic.class, (type, data) -> { Object result = fieldOpt(Loadouts.class, data); if(result != null){ diff --git a/core/src/mindustry/world/blocks/distribution/Duct.java b/core/src/mindustry/world/blocks/distribution/Duct.java index 6e29f879b5..cf09c02f34 100644 --- a/core/src/mindustry/world/blocks/distribution/Duct.java +++ b/core/src/mindustry/world/blocks/distribution/Duct.java @@ -6,6 +6,7 @@ import arc.math.*; import arc.math.geom.*; import arc.struct.*; import arc.util.*; +import arc.util.io.*; import mindustry.annotations.Annotations.*; import mindustry.content.*; import mindustry.entities.units.*; @@ -183,5 +184,25 @@ public class Duct extends Block implements Autotiler{ next = front(); nextc = next instanceof DuctBuild d ? d : null; } + + @Override + public byte version(){ + return 1; + } + + @Override + public void write(Writes write){ + super.write(write); + write.b(recDir); + } + + @Override + public void read(Reads read, byte revision){ + super.read(read, revision); + if(revision >= 1){ + recDir = read.b(); + } + current = items.first(); + } } } diff --git a/core/src/mindustry/world/blocks/distribution/DuctRouter.java b/core/src/mindustry/world/blocks/distribution/DuctRouter.java index b4c78d7ab8..69f90d52d4 100644 --- a/core/src/mindustry/world/blocks/distribution/DuctRouter.java +++ b/core/src/mindustry/world/blocks/distribution/DuctRouter.java @@ -87,7 +87,7 @@ public class DuctRouter extends Block{ if(current == null) return null; for(int i = -1; i <= 1; i++){ - Building other = nearby(Mathf.mod(rotation + i + cdump, 4)); + Building other = nearby(Mathf.mod(rotation + (((i + cdump + 1) % 3) - 1), 4)); if(other != null && other.team == team && other.acceptItem(this, current)){ return other; } diff --git a/core/src/mindustry/world/meta/Attribute.java b/core/src/mindustry/world/meta/Attribute.java index 5114d3c10a..4ade4aa68f 100644 --- a/core/src/mindustry/world/meta/Attribute.java +++ b/core/src/mindustry/world/meta/Attribute.java @@ -1,9 +1,11 @@ package mindustry.world.meta; +import arc.struct.*; import mindustry.*; public class Attribute{ public static Attribute[] all = {}; + public static ObjectMap map = new ObjectMap<>(); public static final Attribute /** Heat content. Used for thermal generator yield. */ @@ -36,6 +38,11 @@ public class Attribute{ return name; } + /** Never returns null, may throw an exception if not found. */ + public static Attribute get(String name){ + return map.getThrow(name, () -> new IllegalArgumentException("Unknown Attribute type: " + name)); + } + /** Automatically registers this attribute for use. Do not call after mod init. */ public static Attribute add(String name){ Attribute a = new Attribute(all.length, name); @@ -43,6 +50,7 @@ public class Attribute{ all = new Attribute[all.length + 1]; System.arraycopy(prev, 0, all, 0, a.id); all[a.id] = a; + map.put(name, a); return a; } } diff --git a/gradle.properties b/gradle.properties index c5c14e018f..13dd3dad98 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,4 +9,4 @@ kapt.use.worker.api=true kapt.include.compile.classpath=false # I don't need to use the kotlin stdlib yet, so remove it to prevent extra bloat & method count issues kotlin.stdlib.default.dependency=false -archash=4afe8d1351e4b8dacd36a53e04fa8d75cda31ffc +archash=ef9b29a8978e8f5e2fcba770bfebd210f4bc8117