mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-01-19 08:47:29 +07:00
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:
parent
355f33b0a4
commit
08f63122ba
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user