From 2dd95a62cab0ff8bf0cfe1f79b046cbcc802274d Mon Sep 17 00:00:00 2001 From: Anuken Date: Tue, 14 Jan 2020 16:18:26 -0500 Subject: [PATCH] Configuration --- core/src/mindustry/io/TypeIO.java | 29 ++++++++++++++++------------- core/src/mindustry/world/Block.java | 6 +++--- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/core/src/mindustry/io/TypeIO.java b/core/src/mindustry/io/TypeIO.java index 24e26d1fc2..4621d257c3 100644 --- a/core/src/mindustry/io/TypeIO.java +++ b/core/src/mindustry/io/TypeIO.java @@ -1,27 +1,25 @@ package mindustry.io; +import arc.graphics.*; +import arc.math.geom.*; import arc.struct.*; -import mindustry.annotations.Annotations.ReadClass; -import mindustry.annotations.Annotations.WriteClass; -import arc.graphics.Color; +import mindustry.annotations.Annotations.*; import mindustry.ctype.*; -import mindustry.entities.Effects; -import mindustry.entities.Effects.Effect; -import mindustry.entities.type.Bullet; -import mindustry.entities.bullet.BulletType; -import mindustry.entities.traits.BuilderTrait.BuildRequest; -import mindustry.entities.traits.ShooterTrait; +import mindustry.entities.*; +import mindustry.entities.Effects.*; +import mindustry.entities.bullet.*; +import mindustry.entities.traits.BuilderTrait.*; +import mindustry.entities.traits.*; import mindustry.entities.type.*; import mindustry.entities.units.*; import mindustry.game.*; -import mindustry.net.Administration.TraceInfo; -import mindustry.net.Packets.AdminAction; -import mindustry.net.Packets.KickReason; +import mindustry.net.Administration.*; +import mindustry.net.Packets.*; import mindustry.type.*; import mindustry.world.*; import java.io.*; -import java.nio.ByteBuffer; +import java.nio.*; import static mindustry.Vars.*; @@ -57,6 +55,10 @@ public class TypeIO{ for(int i = 0; i < arr.size; i++){ buffer.putInt(arr.items[i]); } + }else if(object instanceof Point2){ + buffer.put((byte)7); + buffer.putInt(((Point2)object).x); + buffer.putInt(((Point2)object).y); }else{ throw new IllegalArgumentException("Unknown object type: " + object.getClass()); } @@ -73,6 +75,7 @@ public class TypeIO{ case 4: return readString(buffer); case 5: return content.getByID(ContentType.all[buffer.get()], buffer.getShort()); case 6: short length = buffer.getShort(); IntArray arr = new IntArray(); for(int i = 0; i < length; i ++) arr.add(buffer.getInt()); return arr; + case 7: return new Point2(buffer.getInt(), buffer.getInt()); default: throw new IllegalArgumentException("Unknown object type: " + type); } } diff --git a/core/src/mindustry/world/Block.java b/core/src/mindustry/world/Block.java index 92528625c7..df6a02be69 100644 --- a/core/src/mindustry/world/Block.java +++ b/core/src/mindustry/world/Block.java @@ -95,8 +95,6 @@ public class Block extends BlockStorage{ public boolean consumesTap; /** Whether to draw the glow of the liquid for this block, if it has one. */ public boolean drawLiquidLight = true; - /** Whether the config is positional and needs to be shifted. */ - public boolean posConfig; /** Whether to periodically sync this block across the network.*/ public boolean sync; /** Whether this block uses conveyor-type placement mode.*/ @@ -146,6 +144,7 @@ public class Block extends BlockStorage{ protected TextureRegion[] cacheRegions = {}; protected Array cacheRegionStrings = new Array<>(); protected Prov entityType = TileEntity::new; + protected ObjectMap, Cons2> configurations = new ObjectMap<>(); protected Array tempTiles = new Array<>(); protected TextureRegion[] generatedIcons; @@ -473,12 +472,13 @@ public class Block extends BlockStorage{ } /** Called when arbitrary int configuration is applied to a tile. */ - protected void configured_(Tile tile, @Nullable Player player, int value){ + protected void configuredPos(Tile tile, @Nullable Player player, Point2 point){ } /** Called when arbitrary configuration is applied to a tile. * The default behavior is to treat this as integer configuration. */ + @CallSuper public void configured(Tile tile, @Nullable Player player, @Nullable Object value){ if(value instanceof Integer){ configured_(tile, player, (int)value);