public static bool BuildFinally_Prefix(PlanetFactory __instance, Player player, int prebuildId) { if (!SimulatedWorld.Initialized) { return(true); } if (LocalPlayer.IsMasterClient) { if (!FactoryManager.ContainsPrebuildRequest(__instance.planetId, prebuildId)) { // This prevents duplicating the entity when multiple players trigger the BuildFinally for the same entity at the same time. // If it occurs in any other circumstances, it means that we have some desynchronization between clients and host prebuilds buffers. Log.Warn($"BuildFinally was called without having a corresponding PrebuildRequest for the prebuild {prebuildId} on the planet {__instance.planetId}"); return(false); } // Remove the prebuild request from the list since we will now convert it to a real building FactoryManager.RemovePrebuildRequest(__instance.planetId, prebuildId); } if (LocalPlayer.IsMasterClient || !FactoryManager.EventFromServer) { LocalPlayer.SendPacket(new BuildEntityRequest(__instance.planetId, prebuildId, FactoryManager.PacketAuthor == -1 ? LocalPlayer.PlayerId : FactoryManager.PacketAuthor)); } if (!LocalPlayer.IsMasterClient && !FactoryManager.EventFromServer) { DroneManager.AddBuildRequestSent(-prebuildId); } return(LocalPlayer.IsMasterClient || FactoryManager.EventFromServer); }