diff --git a/core/assets/sprites/block_colors.png b/core/assets/sprites/block_colors.png index 974e14cda3..24945e26a8 100644 Binary files a/core/assets/sprites/block_colors.png and b/core/assets/sprites/block_colors.png differ diff --git a/core/assets/sprites/sprites2.png b/core/assets/sprites/sprites2.png index a76e7d5a72..3035e7cf83 100644 Binary files a/core/assets/sprites/sprites2.png and b/core/assets/sprites/sprites2.png differ diff --git a/core/src/mindustry/entities/def/TileComp.java b/core/src/mindustry/entities/def/TileComp.java index fd0308b628..7bc7be2483 100644 --- a/core/src/mindustry/entities/def/TileComp.java +++ b/core/src/mindustry/entities/def/TileComp.java @@ -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){ diff --git a/core/src/mindustry/io/SaveVersion.java b/core/src/mindustry/io/SaveVersion.java index 0e18f358f3..9041b5722e 100644 --- a/core/src/mindustry/io/SaveVersion.java +++ b/core/src/mindustry/io/SaveVersion.java @@ -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(); diff --git a/core/src/mindustry/io/legacy/LegacySaveVersion.java b/core/src/mindustry/io/legacy/LegacySaveVersion.java index 06013fc921..fb99262b00 100644 --- a/core/src/mindustry/io/legacy/LegacySaveVersion.java +++ b/core/src/mindustry/io/legacy/LegacySaveVersion.java @@ -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; diff --git a/core/src/mindustry/mod/Mods.java b/core/src/mindustry/mod/Mods.java index aee2c4c2cc..7e5b78dfaf 100644 --- a/core/src/mindustry/mod/Mods.java +++ b/core/src/mindustry/mod/Mods.java @@ -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.*; diff --git a/core/src/mindustry/ui/fragments/BlockInventoryFragment.java b/core/src/mindustry/ui/fragments/BlockInventoryFragment.java index 9fd2f93f7f..b41cca6b66 100644 --- a/core/src/mindustry/ui/fragments/BlockInventoryFragment.java +++ b/core/src/mindustry/ui/fragments/BlockInventoryFragment.java @@ -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();