Saving of rotation of static blocks

This commit is contained in:
Anuken
2020-07-25 14:38:09 -04:00
parent c3881b57de
commit d6d2e88b71
3 changed files with 16 additions and 3 deletions

View File

@ -121,6 +121,7 @@ public class Blocks implements ContentList{
cliff = new Cliff("cliff"){{
inEditor = false;
saveRotation = true;
}};
//Registers build blocks

View File

@ -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();

View File

@ -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 */