From 08f63122ba1356e3290f4de88d52c8b49b063ab9 Mon Sep 17 00:00:00 2001 From: BalaM314 <71201189+BalaM314@users.noreply.github.com> Date: Sat, 25 Mar 2023 23:25:26 +0530 Subject: [PATCH] Set controller after setting spawnedByCore (fix UnitChangeEvent) (#8428) * CoreBlock.playerSpawn: Set spawnedByCore first * The call to unit.controller() calls player.unit(unit) * That function fires UnitChangeEvent * The unit in UnitChangeEvent has spawnedByCore incorrectly set to false * This caused me to waste an hour of my life while making a plugin * Might as well improve code readability --- .../world/blocks/storage/CoreBlock.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/core/src/mindustry/world/blocks/storage/CoreBlock.java b/core/src/mindustry/world/blocks/storage/CoreBlock.java index e1a59051ec..203e9daea8 100644 --- a/core/src/mindustry/world/blocks/storage/CoreBlock.java +++ b/core/src/mindustry/world/blocks/storage/CoreBlock.java @@ -66,27 +66,27 @@ public class CoreBlock extends StorageBlock{ @Remote(called = Loc.server) public static void playerSpawn(Tile tile, Player player){ - if(player == null || tile == null || !(tile.build instanceof CoreBuild entity)) return; + if(player == null || tile == null || !(tile.build instanceof CoreBuild core)) return; - CoreBlock block = (CoreBlock)tile.block(); - if(entity.wasVisible){ - Fx.spawn.at(entity); + UnitType spawnType = ((CoreBlock)core.block).unitType; + if(core.wasVisible){ + Fx.spawn.at(core); } - player.set(entity); + player.set(core); if(!net.client()){ - Unit unit = block.unitType.create(tile.team()); - unit.set(entity); + Unit unit = spawnType.create(tile.team()); + unit.set(core); unit.rotation(90f); unit.impulse(0f, 3f); - unit.controller(player); unit.spawnedByCore(true); + unit.controller(player); unit.add(); } if(state.isCampaign() && player == Vars.player){ - block.unitType.unlock(); + spawnType.unlock(); } }