diff --git a/src/microbe_stage/components/CellProperties.cs b/src/microbe_stage/components/CellProperties.cs index 67e59786a29..7f0b6b7e256 100644 --- a/src/microbe_stage/components/CellProperties.cs +++ b/src/microbe_stage/components/CellProperties.cs @@ -186,8 +186,13 @@ public static float EjectCompound(this ref CellProperties cellProperties, ref Wo { float amount = compounds.TakeCompound(compound, maxAmount); - cellProperties.SpawnEjectedCompound(ref cellPosition, compoundCloudSystem, compound, amount, direction, - displacement); + if (!cellProperties.SpawnEjectedCompound(ref cellPosition, compoundCloudSystem, compound, amount, direction, + displacement)) + { + // If membrane was not ready, we didn't eject anything + return 0; + } + return amount; } @@ -352,7 +357,7 @@ public static bool SpawnEjectedCompound(this ref CellProperties cellProperties, if (cellProperties.CreatedMembrane == null) { - GD.PrintErr($"{nameof(SpawnEjectedCompound)} called before membrane is created, ignoring eject"); + GD.Print($"{nameof(SpawnEjectedCompound)} called before membrane is created, ignoring eject"); return false; } diff --git a/src/microbe_stage/systems/EngulfedDigestionSystem.cs b/src/microbe_stage/systems/EngulfedDigestionSystem.cs index a0e5b302920..8cfddd7c7df 100644 --- a/src/microbe_stage/systems/EngulfedDigestionSystem.cs +++ b/src/microbe_stage/systems/EngulfedDigestionSystem.cs @@ -291,7 +291,7 @@ private void HandleDigestion(in Entity entity, ref Engulfer engulfer, ref Organe var takenAdjusted = taken * efficiency; var added = compounds.AddCompound(compound, takenAdjusted); - // Eject excess + // Eject excess (we just want to get rid of it, we don't care if the eject failed) cellProperties.SpawnEjectedCompound(ref position, compoundCloudSystem, compound, takenAdjusted - added, Vector3.Back); } diff --git a/src/microbe_stage/systems/MicrobeEmissionSystem.cs b/src/microbe_stage/systems/MicrobeEmissionSystem.cs index 13e1dd9ec0b..683bf1f08f1 100644 --- a/src/microbe_stage/systems/MicrobeEmissionSystem.cs +++ b/src/microbe_stage/systems/MicrobeEmissionSystem.cs @@ -328,9 +328,6 @@ private void HandleSlimeSecretion(in Entity entity, ref MicrobeControl control, // Activate all jets, which will constantly secrete slime until we turn them off foreach (var jet in organelles.SlimeJets) { - // Make sure this is animating - jet.Active = true; - // Secrete the slime float slimeToSecrete = Math.Min(Constants.COMPOUNDS_TO_VENT_PER_SECOND * delta, compounds.GetCompoundAmount(Compound.Mucilage)); @@ -341,6 +338,13 @@ private void HandleSlimeSecretion(in Entity entity, ref MicrobeControl control, slimeToSecrete = cellProperties.EjectCompound(ref worldPosition, compounds, clouds, Compound.Mucilage, slimeToSecrete, -direction, 2); + // If we couldn't emit (due to no membrane yet), then skip for now + if (slimeToSecrete <= 0) + continue; + + // Make sure this is animating + jet.Active = true; + // Queue movement force to be used by the movement system based on the amount of slime ejected jet.AddQueuedForce(entity, slimeToSecrete); }