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
This commit is contained in:
BalaM314 2023-03-25 23:25:26 +05:30 committed by GitHub
parent 355f33b0a4
commit 08f63122ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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();
}
}