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"){{ cliff = new Cliff("cliff"){{
inEditor = false; inEditor = false;
saveRotation = true;
}}; }};
//Registers build blocks //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()); Tile tile = world.rawTile(i % world.width(), i / world.width());
stream.writeShort(tile.blockID()); stream.writeShort(tile.blockID());
//make note of whether there was an entity here boolean saverot = tile.block().saveRotation;
stream.writeBoolean(tile.build != null); 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 //only write the entity for multiblocks once - in the center
if(tile.build != null){ if(tile.build != null){
@ -182,6 +185,8 @@ public abstract class SaveVersion extends SaveFileReader{
}else{ }else{
stream.writeBoolean(false); stream.writeBoolean(false);
} }
}else if(saverot){
stream.writeByte(tile.rotation());
}else{ }else{
//write consecutive non-entity blocks //write consecutive non-entity blocks
int consecutives = 0; int consecutives = 0;
@ -237,7 +242,9 @@ public abstract class SaveVersion extends SaveFileReader{
Tile tile = context.tile(i); Tile tile = context.tile(i);
if(block == null) block = Blocks.air; if(block == null) block = Blocks.air;
boolean isCenter = true; boolean isCenter = true;
boolean hadEntity = stream.readBoolean(); byte packedCheck = stream.readByte();
boolean hadEntity = (packedCheck & 1) != 0;
boolean hadRotation = (packedCheck & 2) != 0;
if(hadEntity){ if(hadEntity){
isCenter = stream.readBoolean(); isCenter = stream.readBoolean();
@ -264,6 +271,9 @@ public abstract class SaveVersion extends SaveFileReader{
skipChunk(stream, true); skipChunk(stream, true);
} }
} }
}else if(hadRotation){
tile.setBlock(block);
tile.rotation(stream.readByte());
}else{ }else{
int consecutives = stream.readUnsignedByte(); int consecutives = stream.readUnsignedByte();

View File

@ -74,6 +74,8 @@ public class Block extends UnlockableContent{
public boolean solidifes; public boolean solidifes;
/** whether this is rotateable */ /** whether this is rotateable */
public boolean rotate; 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 */ /** whether you can break this with rightclick */
public boolean breakable; public boolean breakable;
/** whether to add this block to brokenblocks */ /** whether to add this block to brokenblocks */