mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-10 15:57:37 +07:00
Saving of rotation of static blocks
This commit is contained in:
@ -121,6 +121,7 @@ public class Blocks implements ContentList{
|
||||
|
||||
cliff = new Cliff("cliff"){{
|
||||
inEditor = false;
|
||||
saveRotation = true;
|
||||
}};
|
||||
|
||||
//Registers build blocks
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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 */
|
||||
|
Reference in New Issue
Block a user