This commit is contained in:
Anuken
2020-03-13 22:33:37 -04:00
parent 06e94b1800
commit 808615a77c
19 changed files with 102 additions and 27 deletions

View File

@@ -104,9 +104,9 @@ public class MapIO{
@Override public void end(){}
@Override
public Tile tile(int x, int y){
tile.x = (short)x;
tile.y = (short)y;
public Tile tile(int index){
tile.x = (short)(index % map.width);
tile.y = (short)(index / map.width);
return tile;
}

View File

@@ -13,7 +13,15 @@ public abstract class SaveFileReader{
protected final ReusableByteOutStream byteOutputSmall = new ReusableByteOutStream();
protected final DataOutputStream dataBytesSmall = new DataOutputStream(byteOutputSmall);
protected final ObjectMap<String, String> fallback = ObjectMap.of(
"dart-mech-pad", "dart-ship-pad"
"dart-mech-pad", "legacy-mech-pad",
"dart-ship-pad", "legacy-mech-pad",
"javelin-ship-pad", "legacy-mech-pad",
"trident-ship-pad", "legacy-mech-pad",
"glaive-ship-pad", "legacy-mech-pad",
"alpha-mech-pad", "legacy-mech-pad",
"tau-mech-pad", "legacy-mech-pad",
"omega-mech-pad", "legacy-mech-pad",
"delta-mech-pad", "legacy-mech-pad"
);
protected void region(String name, DataInput stream, CounterInputStream counter, IORunner<DataInput> cons) throws IOException{

View File

@@ -186,7 +186,7 @@ public abstract class SaveVersion extends SaveFileReader{
for(int i = 0; i < width * height; i++){
int x = i % width, y = i / width;
Block block = content.block(stream.readShort());
Tile tile = context.tile(x, y);
Tile tile = context.tile(i);
if(block == null) block = Blocks.air;
boolean isCenter = true;
@@ -214,8 +214,7 @@ public abstract class SaveVersion extends SaveFileReader{
int consecutives = stream.readUnsignedByte();
for(int j = i + 1; j < i + 1 + consecutives; j++){
int newx = j % width, newy = j / width;
context.tile(newx, newy).setBlock(block);
context.tile(j).setBlock(block);
}
i += consecutives;

View File

@@ -49,13 +49,12 @@ public abstract class LegacySaveVersion extends SaveVersion{
//read blocks
for(int i = 0; i < width * height; i++){
int x = i % width, y = i / width;
Block block = content.block(stream.readShort());
Tile tile = context.tile(x, y);
Tile tile = context.tile(i);
if(block == null) block = Blocks.air;
//occupied by multiblock part
boolean occupied = tile.entity != null && !tile.isCenter();
boolean occupied = tile.entity != null && !tile.isCenter() && (tile.entity.block() == block || block == Blocks.air);
//do not override occupied cells
if(!occupied){
@@ -92,8 +91,7 @@ public abstract class LegacySaveVersion extends SaveVersion{
//air is a waste of time and may mess up multiblocks
if(block != Blocks.air){
for(int j = i + 1; j < i + 1 + consecutives; j++){
int newx = j % width, newy = j / width;
context.tile(newx, newy).setBlock(block);
context.tile(j).setBlock(block);
}
}

View File

@@ -8,6 +8,7 @@ import java.io.*;
import static mindustry.Vars.content;
public class Save3 extends LegacySaveVersion{
public Save3(){
super(3);
}