From d6d2e88b71bcf51c8344a65ba57918bce66541cc Mon Sep 17 00:00:00 2001 From: Anuken Date: Sat, 25 Jul 2020 14:38:09 -0400 Subject: [PATCH] Saving of rotation of static blocks --- core/src/mindustry/content/Blocks.java | 1 + core/src/mindustry/io/SaveVersion.java | 16 +++++++++++++--- core/src/mindustry/world/Block.java | 2 ++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/core/src/mindustry/content/Blocks.java b/core/src/mindustry/content/Blocks.java index 44424ee3c6..3b58e7ad88 100644 --- a/core/src/mindustry/content/Blocks.java +++ b/core/src/mindustry/content/Blocks.java @@ -121,6 +121,7 @@ public class Blocks implements ContentList{ cliff = new Cliff("cliff"){{ inEditor = false; + saveRotation = true; }}; //Registers build blocks diff --git a/core/src/mindustry/io/SaveVersion.java b/core/src/mindustry/io/SaveVersion.java index e03a22b2a5..fc93121405 100644 --- a/core/src/mindustry/io/SaveVersion.java +++ b/core/src/mindustry/io/SaveVersion.java @@ -168,8 +168,11 @@ public abstract class SaveVersion extends SaveFileReader{ Tile tile = world.rawTile(i % world.width(), i / world.width()); stream.writeShort(tile.blockID()); - //make note of whether there was an entity here - stream.writeBoolean(tile.build != null); + boolean saverot = tile.block().saveRotation; + byte packed = (byte)((tile.build != null ? 1 : 0) | (saverot ? 2 : 0)); + + //make note of whether there was an entity/rotation here + stream.writeByte(packed); //only write the entity for multiblocks once - in the center if(tile.build != null){ @@ -182,6 +185,8 @@ public abstract class SaveVersion extends SaveFileReader{ }else{ stream.writeBoolean(false); } + }else if(saverot){ + stream.writeByte(tile.rotation()); }else{ //write consecutive non-entity blocks int consecutives = 0; @@ -237,7 +242,9 @@ public abstract class SaveVersion extends SaveFileReader{ Tile tile = context.tile(i); if(block == null) block = Blocks.air; boolean isCenter = true; - boolean hadEntity = stream.readBoolean(); + byte packedCheck = stream.readByte(); + boolean hadEntity = (packedCheck & 1) != 0; + boolean hadRotation = (packedCheck & 2) != 0; if(hadEntity){ isCenter = stream.readBoolean(); @@ -264,6 +271,9 @@ public abstract class SaveVersion extends SaveFileReader{ skipChunk(stream, true); } } + }else if(hadRotation){ + tile.setBlock(block); + tile.rotation(stream.readByte()); }else{ int consecutives = stream.readUnsignedByte(); diff --git a/core/src/mindustry/world/Block.java b/core/src/mindustry/world/Block.java index 23d141924e..84b8817d7c 100644 --- a/core/src/mindustry/world/Block.java +++ b/core/src/mindustry/world/Block.java @@ -74,6 +74,8 @@ public class Block extends UnlockableContent{ public boolean solidifes; /** whether this is rotateable */ public boolean rotate; + /** for static blocks only: if true, rotation is saved in world data. */ + public boolean saveRotation; /** whether you can break this with rightclick */ public boolean breakable; /** whether to add this block to brokenblocks */