diff --git a/core/src/mindustry/io/TypeIO.java b/core/src/mindustry/io/TypeIO.java index c0ee5f6d9f29..21ad470fd74b 100644 --- a/core/src/mindustry/io/TypeIO.java +++ b/core/src/mindustry/io/TypeIO.java @@ -128,6 +128,9 @@ public static void writeObject(Writes write, Object object){ for(Object obj : objs){ writeObject(write, obj); } + }else if(object instanceof UnitCommand command){ + write.b(23); + write.s(command.id); }else{ throw new IllegalArgumentException("Unknown object type: " + object.getClass()); } @@ -200,6 +203,7 @@ public static Object readObjectBoxed(Reads read, boolean box){ for(int i = 0; i < objlen; i++) objs[i] = readObjectBoxed(read, box); yield objs; } + case 23 -> UnitCommand.all.get(read.us()); default -> throw new IllegalArgumentException("Unknown object type: " + type); }; } diff --git a/core/src/mindustry/world/Block.java b/core/src/mindustry/world/Block.java index 126a269cc5ad..088a933753bf 100644 --- a/core/src/mindustry/world/Block.java +++ b/core/src/mindustry/world/Block.java @@ -890,6 +890,11 @@ public void placeBegan(Tile tile, Block previous){ } + /** Called when building of this block begins. */ + public void placeBegan(Tile tile, Block previous, @Nullable Unit builder){ + placeBegan(tile, previous); + } + /** Called right before building of this block begins. */ public void beforePlaceBegan(Tile tile, Block previous){ diff --git a/core/src/mindustry/world/Build.java b/core/src/mindustry/world/Build.java index ecec0e1c04a2..e5a9064930f3 100644 --- a/core/src/mindustry/world/Build.java +++ b/core/src/mindustry/world/Build.java @@ -115,9 +115,9 @@ public static void beginPlace(@Nullable Unit unit, Block result, Team team, int build.prevBuild = prevBuild; if(unit != null && unit.getControllerName() != null) build.lastAccessed = unit.getControllerName(); - result.placeBegan(tile, previous); - Events.fire(new BlockBuildBeginEvent(tile, team, unit, false)); + + result.placeBegan(tile, previous, unit); } /** Returns whether a tile can be placed at this location by this team. */ diff --git a/core/src/mindustry/world/blocks/storage/CoreBlock.java b/core/src/mindustry/world/blocks/storage/CoreBlock.java index d33ee51ece16..b09b005bcda4 100644 --- a/core/src/mindustry/world/blocks/storage/CoreBlock.java +++ b/core/src/mindustry/world/blocks/storage/CoreBlock.java @@ -164,7 +164,7 @@ public boolean canPlaceOn(Tile tile, Team team, int rotation){ } @Override - public void placeBegan(Tile tile, Block previous){ + public void placeBegan(Tile tile, Block previous, Unit builder){ //finish placement immediately when a block is replaced. if(previous instanceof CoreBlock){ tile.setBlock(this, tile.team()); @@ -181,6 +181,8 @@ public void placeBegan(Tile tile, Block previous){ nextItems = null; } + + Events.fire(new BlockBuildEndEvent(tile, builder, tile.team(), false, null)); } }