Bugfixes / Fixed #1680

This commit is contained in:
Anuken 2020-03-06 17:06:21 -05:00
parent ae0b84cef0
commit 7655b65363
7 changed files with 52 additions and 23 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 732 B

After

Width:  |  Height:  |  Size: 732 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 128 KiB

After

Width:  |  Height:  |  Size: 128 KiB

View File

@ -182,7 +182,7 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc{
}
public int pos(){
return pos();
return tile.pos();
}
public int rotation(){
@ -194,7 +194,7 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc{
}
public Floor floor(){
return floor();
return tile.floor();
}
public boolean interactable(Team team){

View File

@ -122,11 +122,17 @@ public abstract class SaveVersion extends SaveFileReader{
Tile tile = world.rawTile(i % world.width(), i / world.width());
stream.writeShort(tile.blockID());
//only write the entity for multiblocks once - in the center
if(tile.entity != null){
writeChunk(stream, true, out -> {
out.writeByte(tile.entity.version());
tile.entity.writeAll(Writes.get(out));
});
if(tile.isCenter()){
stream.writeBoolean(true);
writeChunk(stream, true, out -> {
out.writeByte(tile.entity.version());
tile.entity.writeAll(Writes.get(out));
});
}else{
stream.writeBoolean(false);
}
}else{
//write consecutive non-entity blocks
int consecutives = 0;
@ -182,16 +188,27 @@ public abstract class SaveVersion extends SaveFileReader{
Block block = content.block(stream.readShort());
Tile tile = context.tile(x, y);
if(block == null) block = Blocks.air;
tile.setBlock(block);
boolean isCenter = true;
if(tile.entity != null){
try{
readChunk(stream, true, in -> {
byte revision = in.readByte();
tile.entity.readAll(Reads.get(in), revision);
});
}catch(Exception e){
throw new IOException("Failed to read tile entity of block: " + block, e);
if(block.hasEntity()){
isCenter = stream.readBoolean();
}
//set block only if this is the center; otherwise, it's handled elsewhere
if(isCenter){
tile.setBlock(block);
}
if(block.hasEntity()){
if(isCenter){ //only read entity for center blocks
try{
readChunk(stream, true, in -> {
byte revision = in.readByte();
tile.entity.readAll(Reads.get(in), revision);
});
}catch(Throwable e){
throw new IOException("Failed to read tile entity of block: " + block, e);
}
}
}else{
int consecutives = stream.readUnsignedByte();

View File

@ -53,9 +53,16 @@ public abstract class LegacySaveVersion extends SaveVersion{
Block block = content.block(stream.readShort());
Tile tile = context.tile(x, y);
if(block == null) block = Blocks.air;
tile.setBlock(block);
if(tile.entity != null){
//occupied by multiblock part
boolean occupied = tile.entity != null && !tile.isCenter();
//do not override occupied cells
if(!occupied){
tile.setBlock(block);
}
if(block.hasEntity()){
try{
readChunk(stream, true, in -> {
byte version = in.readByte();
@ -76,15 +83,18 @@ public abstract class LegacySaveVersion extends SaveVersion{
//read only from subclasses!
tile.entity.read(Reads.get(in), version);
});
}catch(Exception e){
}catch(Throwable e){
throw new IOException("Failed to read tile entity of block: " + block, e);
}
}else{
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);
//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);
}
}
i += consecutives;

View File

@ -21,7 +21,6 @@ import mindustry.game.EventType.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.graphics.MultiPacker.*;
import mindustry.plugin.*;
import mindustry.type.*;
import mindustry.ui.*;

View File

@ -34,6 +34,10 @@ public class BlockInventoryFragment extends Fragment{
private boolean holding;
private Item lastItem;
{
Events.on(WorldLoadEvent.class, e -> hide());
}
@Remote(called = Loc.server, targets = Loc.both, forward = true)
public static void requestItem(Playerc player, Tilec tile, Item item, int amount){
if(player == null || tile == null || !tile.interactable(player.team())) return;
@ -87,7 +91,6 @@ public class BlockInventoryFragment extends Fragment{
}
private void rebuild(boolean actions){
IntSet container = new IntSet();
table.clearChildren();