From 129c3f446ada7b294b988953327c9c3a1104c971 Mon Sep 17 00:00:00 2001 From: Anuken Date: Fri, 30 Jun 2023 22:26:43 -0400 Subject: [PATCH] Fixed #8782 --- core/src/mindustry/entities/comp/BuildingComp.java | 3 +++ core/src/mindustry/entities/comp/UnitComp.java | 7 ++++++- core/src/mindustry/service/GameService.java | 2 +- core/src/mindustry/world/blocks/storage/CoreBlock.java | 6 ++++++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/core/src/mindustry/entities/comp/BuildingComp.java b/core/src/mindustry/entities/comp/BuildingComp.java index 3f4157abcf..7fd842cdb1 100644 --- a/core/src/mindustry/entities/comp/BuildingComp.java +++ b/core/src/mindustry/entities/comp/BuildingComp.java @@ -1956,6 +1956,9 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc, case health -> { health = (float)Mathf.clamp(value, 0, maxHealth); healthChanged(); + if(health <= 0f && !dead()){ + Call.buildDestroyed(self()); + } } case team -> { Team team = Team.get((int)value); diff --git a/core/src/mindustry/entities/comp/UnitComp.java b/core/src/mindustry/entities/comp/UnitComp.java index 550a68f45e..b9f5b2dc93 100644 --- a/core/src/mindustry/entities/comp/UnitComp.java +++ b/core/src/mindustry/entities/comp/UnitComp.java @@ -261,7 +261,12 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I @Override public void setProp(LAccess prop, double value){ switch(prop){ - case health -> health = (float)Mathf.clamp(value, 0, maxHealth); + case health -> { + health = (float)Mathf.clamp(value, 0, maxHealth); + if(health <= 0f && !dead){ + kill(); + } + } case x -> x = World.unconv((float)value); case y -> y = World.unconv((float)value); case rotation -> rotation = (float)value; diff --git a/core/src/mindustry/service/GameService.java b/core/src/mindustry/service/GameService.java index 8143cdc0fc..72e7a74740 100644 --- a/core/src/mindustry/service/GameService.java +++ b/core/src/mindustry/service/GameService.java @@ -189,7 +189,7 @@ public class GameService{ } }); - Events.on(BlockBuildBeginEvent.class, e -> { + Events.on(BlockBuildEndEvent.class, e -> { if(campaign() && state.rules.sector == SectorPresets.groundZero.sector && e.tile.block() == Blocks.coreNucleus){ nucleusGroundZero.complete(); } diff --git a/core/src/mindustry/world/blocks/storage/CoreBlock.java b/core/src/mindustry/world/blocks/storage/CoreBlock.java index b09b005bcd..cc60ec4f6c 100644 --- a/core/src/mindustry/world/blocks/storage/CoreBlock.java +++ b/core/src/mindustry/world/blocks/storage/CoreBlock.java @@ -359,8 +359,14 @@ public class CoreBlock extends StorageBlock{ @Override public void changeTeam(Team next){ + if(this.team == next) return; + + state.teams.unregisterCore(this); + super.changeTeam(next); + state.teams.registerCore(this); + Events.fire(new CoreChangeEvent(this)); }